diff --git a/gmod/src/lua/import.rs b/gmod/src/lua/import.rs index 447c3ee..eed1a6c 100644 --- a/gmod/src/lua/import.rs +++ b/gmod/src/lua/import.rs @@ -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"), diff --git a/gmod/src/lua/lua_state.rs b/gmod/src/lua/lua_state.rs index e92508b..2c2f61f 100644 --- a/gmod/src/lua/lua_state.rs +++ b/gmod/src/lua/lua_state.rs @@ -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 {