-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathlua.rs
More file actions
101 lines (87 loc) · 3.63 KB
/
lua.rs
File metadata and controls
101 lines (87 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use crate::lua::lua::{lua_state, luaL_Reg_container, luaL_Reg_from_api};
use std::ffi::CString;
#[no_mangle]
pub extern "C" fn arcorp_add_lua_menu_manager(name: *mut i8, reg_vec_ptr: *mut luaL_Reg_from_api, reg_vec_size: usize, reg_vec_cap: usize) -> bool {
debug!("arcorp_add_lua_menu_manager -> Function called");
unsafe {
match CString::from_raw(name as _).to_str() {
Ok(s) => {
let name = s.to_string();
let registry = Vec::from_raw_parts(reg_vec_ptr, reg_vec_size, reg_vec_cap);
let functions = registry.iter().map(|x| {
luaL_Reg_container {
name: CString::from_raw(x.name as _).to_str().unwrap().to_string(),
func: x.func
}
}).collect::<Vec<luaL_Reg_container>>();
crate::lua::add_lua_menu_manager(name, functions)
},
Err(err) => {
error!("arcorp_add_lua_menu_manager -> Error when adding manager! Reason: {:?}", err);
false
}
}
}
}
#[no_mangle]
pub extern "C" fn arcorp_add_lua_ingame_manager(name: *mut i8, reg_vec_ptr: *mut luaL_Reg_from_api, reg_vec_size: usize, reg_vec_cap: usize) -> bool {
debug!("arcorp_add_lua_ingame_manager -> Function called");
unsafe {
match CString::from_raw(name as _).to_str() {
Ok(s) => {
let name = s.to_string();
let registry = Vec::from_raw_parts(reg_vec_ptr, reg_vec_size, reg_vec_cap);
let functions = registry.iter().map(|x| {
luaL_Reg_container {
name: CString::from_raw(x.name as _).to_str().unwrap().to_string(),
func: x.func
}
}).collect::<Vec<luaL_Reg_container>>();
crate::lua::add_lua_ingame_manager(name, functions)
},
Err(err) => {
false
}
}
}
}
#[no_mangle]
pub extern "C" fn arcrop_lua_state_get_string(lua_state: &mut lua_state) -> *const u8 {
debug!("arcrop_lua_state_get_string -> Function called");
lua_state.get_string_arg_ptr()
}
#[no_mangle]
pub extern "C" fn arcrop_lua_state_get_number(lua_state: &mut lua_state) -> f32 {
debug!("arcrop_lua_state_get_number -> Function called");
lua_state.get_number_arg()
}
#[no_mangle]
pub extern "C" fn arcrop_lua_state_get_integer(lua_state: &mut lua_state) -> u64 {
debug!("arcrop_lua_state_get_integer -> Function called");
lua_state.get_integer_arg()
}
#[no_mangle]
pub extern "C" fn arcrop_lua_state_push_bool(lua_state: &mut lua_state, val: bool) {
debug!("arcrop_lua_state_push_bool -> Function called");
lua_state.push_bool(val)
}
#[no_mangle]
pub extern "C" fn arcrop_lua_state_push_integer(lua_state: &mut lua_state, val: u64) {
debug!("arcrop_lua_state_push_integer -> Function called");
lua_state.push_integer(val)
}
#[no_mangle]
pub extern "C" fn arcrop_lua_state_push_number(lua_state: &mut lua_state, val: f32) {
debug!("arcrop_lua_state_push_number -> Function called");
lua_state.push_number(val)
}
#[no_mangle]
pub extern "C" fn arcrop_lua_state_push_nil(lua_state: &mut lua_state) {
debug!("arcrop_lua_state_push_nil -> Function called");
lua_state.push_nil()
}
#[no_mangle]
pub extern "C" fn arcrop_lua_state_push_string(lua_state: &mut lua_state, str: *mut i8) {
debug!("arcrop_lua_state_push_string -> Function called");
unsafe { lua_state.push_string(CString::from_raw(str as _).to_str().expect("Failed to get string from str pointer!")); }
}