Add new_metatable check_function check_table push_registry
This commit is contained in:
parent
10efbfdd16
commit
00cb274bf3
|
@ -109,7 +109,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gmod"
|
name = "gmod"
|
||||||
version = "6.0.1"
|
version = "7.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg_table",
|
"cfg_table",
|
||||||
"cstr",
|
"cstr",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "gmod"
|
name = "gmod"
|
||||||
version = "6.0.1"
|
version = "7.0.0"
|
||||||
authors = ["William Venner <william@venner.io>"]
|
authors = ["William Venner <william@venner.io>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
@ -169,6 +169,7 @@ pub struct LuaShared {
|
||||||
pub lua_next: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, index: i32) -> i32>,
|
pub lua_next: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, index: i32) -> i32>,
|
||||||
pub lua_topointer: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, index: i32) -> *const c_void>,
|
pub lua_topointer: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, index: i32) -> *const c_void>,
|
||||||
pub lua_newuserdata: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, size: usize) -> *mut c_void>,
|
pub lua_newuserdata: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, size: usize) -> *mut c_void>,
|
||||||
|
pub lual_newmetatable: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, name: LuaString) -> i32>,
|
||||||
}
|
}
|
||||||
unsafe impl Sync for LuaShared {}
|
unsafe impl Sync for LuaShared {}
|
||||||
impl LuaShared {
|
impl LuaShared {
|
||||||
|
@ -235,6 +236,7 @@ impl LuaShared {
|
||||||
lua_next: find_symbol!("lua_next"),
|
lua_next: find_symbol!("lua_next"),
|
||||||
lua_topointer: find_symbol!("lua_topointer"),
|
lua_topointer: find_symbol!("lua_topointer"),
|
||||||
lua_newuserdata: find_symbol!("lua_newuserdata"),
|
lua_newuserdata: find_symbol!("lua_newuserdata"),
|
||||||
|
lual_newmetatable: find_symbol!("lual_newmetatable"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,6 +218,11 @@ impl LuaState {
|
||||||
(LUA_SHARED.lua_pushvalue)(*self, LUA_GLOBALSINDEX)
|
(LUA_SHARED.lua_pushvalue)(*self, LUA_GLOBALSINDEX)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn push_registry(&self) {
|
||||||
|
(LUA_SHARED.lua_pushvalue)(*self, LUA_REGISTRYINDEX)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn push_string(&self, data: &str) {
|
pub unsafe fn push_string(&self, data: &str) {
|
||||||
(LUA_SHARED.lua_pushlstring)(*self, data.as_ptr() as LuaString, data.len())
|
(LUA_SHARED.lua_pushlstring)(*self, data.as_ptr() as LuaString, data.len())
|
||||||
|
@ -325,6 +330,16 @@ impl LuaState {
|
||||||
(LUA_SHARED.lua_getmetatable)(*self, index)
|
(LUA_SHARED.lua_getmetatable)(*self, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn check_table(&self, arg: i32) {
|
||||||
|
(LUA_SHARED.lual_checktype)(*self, arg, LUA_TTABLE)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn check_function(&self, arg: i32) {
|
||||||
|
(LUA_SHARED.lual_checktype)(*self, arg, LUA_TFUNCTION)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn check_integer(&self, arg: i32) -> LuaInt {
|
pub unsafe fn check_integer(&self, arg: i32) -> LuaInt {
|
||||||
(LUA_SHARED.lual_checkinteger)(*self, arg)
|
(LUA_SHARED.lual_checkinteger)(*self, arg)
|
||||||
|
@ -391,6 +406,13 @@ impl LuaState {
|
||||||
(LUA_SHARED.lua_touserdata)(*self, index)
|
(LUA_SHARED.lua_touserdata)(*self, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a new table in the registry with the given `name` as the key if it doesn't already exist, and pushes it onto the stack.
|
||||||
|
///
|
||||||
|
/// Returns if the metatable was already present in the registry.
|
||||||
|
pub unsafe fn new_metatable(&self, name: LuaString) -> bool {
|
||||||
|
(LUA_SHARED.lual_newmetatable)(*self, name) == 0
|
||||||
|
}
|
||||||
|
|
||||||
pub unsafe fn new_userdata<T: Sized>(&self, data: T, metatable: Option<i32>) -> *mut T {
|
pub unsafe fn new_userdata<T: Sized>(&self, data: T, metatable: Option<i32>) -> *mut T {
|
||||||
let has_metatable = if std::mem::needs_drop::<T>() {
|
let has_metatable = if std::mem::needs_drop::<T>() {
|
||||||
if let Some(metatable) = metatable {
|
if let Some(metatable) = metatable {
|
||||||
|
|
Loading…
Reference in New Issue