#[repr(transparent)]pub struct State(pub *mut c_void);
Tuple Fields§
§0: *mut c_void
Implementations§
source§impl LuaState
impl LuaState
pub unsafe fn new() -> Result<Self, LuaError>
sourcepub unsafe fn is_client(&self) -> bool
pub unsafe fn is_client(&self) -> bool
Returns whether this is the clientside Lua state or not.
sourcepub unsafe fn is_server(&self) -> bool
pub unsafe fn is_server(&self) -> bool
Returns whether this is the serverside Lua state or not.
Returns whether this is the menu Lua state or not.
sourcepub unsafe fn get_binary_string(&self, index: i32) -> Option<&[u8]>
pub unsafe fn get_binary_string(&self, index: i32) -> Option<&[u8]>
Returns the Lua string as a slice of bytes.
WARNING: This will CHANGE the type of the value at the given index to a string.
Returns None if the value at the given index is not convertible to a string.
sourcepub unsafe fn get_string(&self, index: i32) -> Option<Cow<'_, str>>
pub unsafe fn get_string(&self, index: i32) -> Option<Cow<'_, str>>
Returns the Lua string as a Rust UTF-8 String.
WARNING: This will CHANGE the type of the value at the given index to a string.
Returns None if the value at the given index is not convertible to a string.
This is a lossy operation, and will replace any invalid UTF-8 sequences with the Unicode replacement character. See the documentation for String::from_utf8_lossy
for more information.
If you need raw data, use get_binary_string
.
sourcepub unsafe fn get_type(&self, index: i32) -> &str
pub unsafe fn get_type(&self, index: i32) -> &str
Returns the name of the type of the value at the given index.
pub unsafe fn get_top(&self) -> i32
sourcepub unsafe fn reference(&self) -> LuaReference
pub unsafe fn reference(&self) -> LuaReference
Pops the stack, inserts the value into the registry table, and returns the registry index of the value.
Use from_reference
with the reference index to push the value back onto the stack.
Use dereference
to free the reference from the registry table.
pub unsafe fn dereference(&self, ref: LuaReference)
pub unsafe fn from_reference(&self, ref: LuaReference)
pub unsafe fn is_none(&self, index: i32) -> bool
pub unsafe fn is_none_or_nil(&self, index: i32) -> bool
pub unsafe fn is_function(&self, index: i32) -> bool
pub unsafe fn is_table(&self, index: i32) -> bool
pub unsafe fn is_boolean(&self, index: i32) -> bool
pub unsafe fn remove(&self, index: i32)
pub unsafe fn push_value(&self, index: i32)
pub unsafe fn push_lightuserdata(&self, data: *mut c_void)
pub unsafe fn get_field(&self, index: i32, k: LuaString)
pub unsafe fn push_boolean(&self, boolean: bool)
pub unsafe fn push_integer(&self, int: LuaInt)
pub unsafe fn push_number(&self, num: LuaNumber)
pub unsafe fn push_nil(&self)
pub unsafe fn push_thread(&self) -> i32
pub unsafe fn to_thread(&self, index: i32) -> State
pub unsafe fn pcall(&self, nargs: i32, nresults: i32, errfunc: i32) -> i32
sourcepub unsafe fn pcall_ignore(&self, nargs: i32, nresults: i32) -> bool
pub unsafe fn pcall_ignore(&self, nargs: i32, nresults: i32) -> bool
Same as pcall, but ignores any runtime error and calls ErrorNoHaltWithStack
instead with the error message.
Returns whether the execution was successful.
pub unsafe fn load_string(&self, src: LuaString) -> Result<(), LuaError>
pub unsafe fn load_buffer( &self, buff: &[u8], name: LuaString ) -> Result<(), LuaError>
pub unsafe fn load_file(&self, path: LuaString) -> Result<(), LuaError>
pub unsafe fn pop(&self)
pub unsafe fn pop_n(&self, count: i32)
pub unsafe fn set_top(&self, index: i32)
pub unsafe fn lua_type(&self, index: i32) -> i32
pub unsafe fn lua_type_name(&self, lua_type_id: i32) -> Cow<'_, str>
pub unsafe fn replace(&self, index: i32)
pub unsafe fn push_globals(&self)
pub unsafe fn push_registry(&self)
pub unsafe fn push_string(&self, data: &str)
pub unsafe fn push_binary_string(&self, data: &[u8])
pub unsafe fn push_function(&self, func: LuaFunction)
sourcepub unsafe fn push_closure(&self, func: LuaFunction, n: i32)
pub unsafe fn push_closure(&self, func: LuaFunction, n: i32)
sourcepub unsafe fn push_closure_arg(&self, n: i32)
pub unsafe fn push_closure_arg(&self, n: i32)
sourcepub const fn upvalue_index(&self, idx: i32) -> i32
pub const fn upvalue_index(&self, idx: i32) -> i32
Equivalent to C lua_upvalueindex
macro
pub unsafe fn set_table(&self, index: i32)
pub unsafe fn set_field(&self, index: i32, k: LuaString)
pub unsafe fn get_global(&self, name: LuaString)
pub unsafe fn set_global(&self, name: LuaString)
sourcepub unsafe fn call(&self, nargs: i32, nresults: i32)
pub unsafe fn call(&self, nargs: i32, nresults: i32)
WARNING: Any Lua errors caused by calling the function will longjmp and prevent any further execution of your code.
To workaround this, use pcall_ignore
, which will call ErrorNoHaltWithStack
instead and allow your code to continue executing.
pub unsafe fn insert(&self, index: i32)
sourcepub unsafe fn create_table(&self, seq_n: i32, hash_n: i32)
pub unsafe fn create_table(&self, seq_n: i32, hash_n: i32)
Creates a new table and pushes it to the stack. seq_n is a hint as to how many sequential elements the table may have. hash_n is a hint as to how many non-sequential/hashed elements the table may have. Lua may use these hints to preallocate memory.
sourcepub unsafe fn new_table(&self)
pub unsafe fn new_table(&self)
Creates a new table and pushes it to the stack without memory preallocation hints.
Equivalent to create_table(0, 0)
pub unsafe fn get_table(&self, index: i32)
pub unsafe fn check_binary_string(&self, arg: i32) -> &[u8] ⓘ
pub unsafe fn check_string(&self, arg: i32) -> Cow<'_, str>
pub unsafe fn check_userdata( &self, arg: i32, name: LuaString ) -> *mut TaggedUserData
pub unsafe fn test_userdata(&self, index: i32, name: LuaString) -> bool
pub unsafe fn raw_equal(&self, a: i32, b: i32) -> bool
pub unsafe fn get_metatable(&self, index: i32) -> i32
pub unsafe fn check_table(&self, arg: i32)
pub unsafe fn check_function(&self, arg: i32)
pub unsafe fn check_integer(&self, arg: i32) -> LuaInt
pub unsafe fn check_number(&self, arg: i32) -> f64
pub unsafe fn check_boolean(&self, arg: i32) -> bool
pub unsafe fn to_integer(&self, index: i32) -> LuaInt
pub unsafe fn to_number(&self, index: i32) -> f64
pub unsafe fn get_boolean(&self, index: i32) -> bool
pub unsafe fn set_metatable(&self, index: i32) -> i32
pub unsafe fn len(&self, index: i32) -> i32
pub unsafe fn raw_geti(&self, t: i32, index: i32)
pub unsafe fn raw_seti(&self, t: i32, index: i32)
pub unsafe fn next(&self, index: i32) -> i32
pub unsafe fn to_pointer(&self, index: i32) -> *const c_void
pub unsafe fn to_userdata(&self, index: i32) -> *mut c_void
pub unsafe fn coroutine_new(&self) -> State
pub unsafe fn coroutine_yield(&self, nresults: i32) -> i32
pub unsafe fn coroutine_resume(&self, narg: i32) -> i32
sourcepub unsafe fn coroutine_exchange(&self, target_thread: State, n: i32)
pub unsafe fn coroutine_exchange(&self, target_thread: State, n: i32)
Exchange values between different threads of the same global state.
This function pops n
values from the stack self
, and pushes them onto the stack target_thread
.
pub unsafe fn equal(&self, index1: i32, index2: i32) -> bool
sourcepub unsafe fn coroutine_resume_call(&self, narg: i32)
pub unsafe fn coroutine_resume_call(&self, narg: i32)
See call
sourcepub unsafe fn coroutine_resume_pcall_ignore(&self, narg: i32) -> Result<i32, ()>
pub unsafe fn coroutine_resume_pcall_ignore(&self, narg: i32) -> Result<i32, ()>
See pcall_ignore
pub unsafe fn coroutine_status(&self) -> i32
sourcepub unsafe fn new_metatable(&self, name: LuaString) -> bool
pub unsafe fn new_metatable(&self, name: LuaString) -> bool
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_userdata<T: Sized>( &self, data: T, metatable: Option<i32> ) -> *mut T
pub unsafe fn error<S: AsRef<str>>(&self, msg: S) -> !
pub unsafe fn debug_getinfo_from_ar( &self, ar: &mut LuaDebug, what: LuaString ) -> Result<(), ()>
sourcepub unsafe fn debug_getinfo_from_stack(
&self,
what: LuaString
) -> Option<LuaDebug>
pub unsafe fn debug_getinfo_from_stack( &self, what: LuaString ) -> Option<LuaDebug>
what
should start with >
and pop a function off the stack
pub unsafe fn get_stack_at(&self, level: i32) -> Option<LuaDebug>
pub unsafe fn debug_getinfo_at( &self, level: i32, what: LuaString ) -> Option<LuaDebug>
pub unsafe fn dump_stack(&self)
pub unsafe fn dump_val(&self, index: i32) -> String
source§impl State
impl State
sourcepub unsafe fn raw_bind<F: CLuaFunction>(
&self,
symbol: &[u8]
) -> Result<F, Error>
pub unsafe fn raw_bind<F: CLuaFunction>( &self, symbol: &[u8] ) -> Result<F, Error>
Binds to a raw Lua C function.
If anything is missing from this library, you can use this function to bind it yourself.
Note, this may be a somewhat expensive operation, so storing its result in some way is recommended.