1个不稳定版本
0.1.0 | 2024年4月4日 |
---|
#817 在 游戏开发
1.5MB
434 行
包含 (ELF 库,1MB) lib/x86_64/linux/lua_shared.so,(ELF 库,1MB) lib/i686/linux/lua_shared_srv.so,(静态库,29KB) lib/i686/windows/lua_shared.lib,(静态库,32KB) lib/x86_64/windows/lua_shared.lib
lua-shared
围绕 lua_shared(_srv) 的简单封装,旨在不会破坏你的大脑。
示例用法
use lua_shared as lua;
use lua::cstr;
use std::ffi::c_void;
#[no_mangle]
unsafe extern "C" fn gmod13_open(state: *mut c_void) -> i32 {
lua::createtable(state, 0, 2);
lua::pushfunction(state, |_| {
println!("Hello there!");
Ok(0)
});
lua::setfield(state, -2, lua::cstr!("test_immutable_closure"));
fn test_function(state: lua_State) -> Result {
println!("Hello there, but from functuin, I guess.");
Ok(0)
}
lua::pushfunction(state, test_function);
lua::setfield(state, -2, lua::cstr!("test_immutable_function"));
let mut counter = 0;
lua::pushfunction_mut(state, move |_| {
println!("Here is your counter!: {}", counter);
lua::pushinteger(state, counter);
counter += 1;
Ok(1)
});
lua::setfield(state, -2, lua::cstr!("test_mutable_closure"));
lua::setfield(state, lua::GLOBALSINDEX, lua::cstr!("tests"));
}