This commit is contained in:
William Venner 2021-09-20 20:08:42 +01:00
commit 7ed864a789
2 changed files with 11 additions and 0 deletions

View File

@ -75,6 +75,7 @@ lazy_static::lazy_static! {
pub(crate) struct LuaShared {
pub lual_loadfile: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, path: LuaString) -> i32>,
pub lual_loadstring: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, path: LuaString) -> i32>,
pub lual_loadbuffer: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, buff: LuaString, sz: LuaSize, name: LuaString) -> i32>,
pub lua_getfield: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, index: i32, k: LuaString)>,
pub lua_pushvalue: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, index: i32)>,
pub lua_pushboolean: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, bool: i32)>,
@ -134,6 +135,7 @@ impl LuaShared {
Self {
lual_loadfile: find_symbol!("luaL_loadfile"),
lual_loadstring: find_symbol!("luaL_loadstring"),
lual_loadbuffer: find_symbol!("luaL_loadbuffer"),
lua_getfield: find_symbol!("lua_getfield"),
lua_pushvalue: find_symbol!("lua_pushvalue"),
lua_pushboolean: find_symbol!("lua_pushboolean"),

View File

@ -149,6 +149,15 @@ impl LuaState {
}
}
pub unsafe fn load_buffer(&self, buff: &[u8], name: LuaString) -> Result<(), LuaError> {
let lua_error_code = (LUA_SHARED.lual_loadbuffer)(*self, buff.as_ptr() as LuaString, buff.len(), name);
if lua_error_code == 0 {
Ok(())
} else {
Err(LuaError::from_lua_state(*self, lua_error_code))
}
}
pub unsafe fn load_file(&self, path: LuaString) -> Result<(), LuaError> {
let lua_error_code = (LUA_SHARED.lual_loadfile)(*self, path);
if lua_error_code == 0 {