Struct gmod::lua::State

source ·
#[repr(transparent)]
pub struct State(pub *mut c_void);

Tuple Fields§

§0: *mut c_void

Implementations§

source§

impl LuaState

source

pub unsafe fn new() -> Result<Self, LuaError>

source

pub unsafe fn is_client(&self) -> bool

Returns whether this is the clientside Lua state or not.

source

pub unsafe fn is_server(&self) -> bool

Returns whether this is the serverside Lua state or not.

source

pub unsafe fn is_menu(&self) -> bool

Returns whether this is the menu Lua state or not.

source

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.

source

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.

source

pub unsafe fn get_type(&self, index: i32) -> &str

Returns the name of the type of the value at the given index.

source

pub unsafe fn get_top(&self) -> i32

source

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.

source

pub unsafe fn dereference(&self, ref: LuaReference)

source

pub unsafe fn from_reference(&self, ref: LuaReference)

source

pub unsafe fn is_nil(&self, index: i32) -> bool

You may be looking for is_none_or_nil

source

pub unsafe fn is_none(&self, index: i32) -> bool

source

pub unsafe fn is_none_or_nil(&self, index: i32) -> bool

source

pub unsafe fn is_function(&self, index: i32) -> bool

source

pub unsafe fn is_table(&self, index: i32) -> bool

source

pub unsafe fn is_boolean(&self, index: i32) -> bool

source

pub unsafe fn remove(&self, index: i32)

source

pub unsafe fn push_value(&self, index: i32)

source

pub unsafe fn push_lightuserdata(&self, data: *mut c_void)

source

pub unsafe fn get_field(&self, index: i32, k: LuaString)

source

pub unsafe fn push_boolean(&self, boolean: bool)

source

pub unsafe fn push_integer(&self, int: LuaInt)

source

pub unsafe fn push_number(&self, num: LuaNumber)

source

pub unsafe fn push_nil(&self)

source

pub unsafe fn push_thread(&self) -> i32

source

pub unsafe fn to_thread(&self, index: i32) -> State

source

pub unsafe fn pcall(&self, nargs: i32, nresults: i32, errfunc: i32) -> i32

source

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.

source

pub unsafe fn load_string(&self, src: LuaString) -> Result<(), LuaError>

source

pub unsafe fn load_buffer( &self, buff: &[u8], name: LuaString ) -> Result<(), LuaError>

source

pub unsafe fn load_file(&self, path: LuaString) -> Result<(), LuaError>

source

pub unsafe fn pop(&self)

source

pub unsafe fn pop_n(&self, count: i32)

source

pub unsafe fn set_top(&self, index: i32)

source

pub unsafe fn lua_type(&self, index: i32) -> i32

source

pub unsafe fn lua_type_name(&self, lua_type_id: i32) -> Cow<'_, str>

source

pub unsafe fn replace(&self, index: i32)

source

pub unsafe fn push_globals(&self)

source

pub unsafe fn push_registry(&self)

source

pub unsafe fn push_string(&self, data: &str)

source

pub unsafe fn push_binary_string(&self, data: &[u8])

source

pub unsafe fn push_function(&self, func: LuaFunction)

source

pub unsafe fn push_closure(&self, func: LuaFunction, n: i32)

Creates a closure, which can be used as a function with stored data (upvalues)

Example
#[lua_function]
unsafe fn foo(lua: gmod::lua::State) {
    lua.get_closure_arg(1);
    let hello = lua.get_string(-1);
    println!("{}", hello);
}

lua.push_string("Hello, world!");
lua.push_closure(foo, 1);
source

pub unsafe fn push_closure_arg(&self, n: i32)

Pushes the nth closure argument onto the stack

Example
#[lua_function]
unsafe fn foo(lua: gmod::lua::State) {
    lua.push_closure_arg(1);
    let hello = lua.get_string(-1);
    println!("{}", hello);
}

lua.push_string("Hello, world!");
lua.push_closure(foo, 1);
source

pub const fn upvalue_index(&self, idx: i32) -> i32

Equivalent to C lua_upvalueindex macro

source

pub unsafe fn set_table(&self, index: i32)

source

pub unsafe fn set_field(&self, index: i32, k: LuaString)

source

pub unsafe fn get_global(&self, name: LuaString)

source

pub unsafe fn set_global(&self, name: LuaString)

source

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.

source

pub unsafe fn insert(&self, index: i32)

source

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.

source

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)

source

pub unsafe fn get_table(&self, index: i32)

source

pub unsafe fn check_binary_string(&self, arg: i32) -> &[u8]

source

pub unsafe fn check_string(&self, arg: i32) -> Cow<'_, str>

source

pub unsafe fn check_userdata( &self, arg: i32, name: LuaString ) -> *mut TaggedUserData

source

pub unsafe fn test_userdata(&self, index: i32, name: LuaString) -> bool

source

pub unsafe fn raw_equal(&self, a: i32, b: i32) -> bool

source

pub unsafe fn get_metatable(&self, index: i32) -> i32

source

pub unsafe fn check_table(&self, arg: i32)

source

pub unsafe fn check_function(&self, arg: i32)

source

pub unsafe fn check_integer(&self, arg: i32) -> LuaInt

source

pub unsafe fn check_number(&self, arg: i32) -> f64

source

pub unsafe fn check_boolean(&self, arg: i32) -> bool

source

pub unsafe fn to_integer(&self, index: i32) -> LuaInt

source

pub unsafe fn to_number(&self, index: i32) -> f64

source

pub unsafe fn get_boolean(&self, index: i32) -> bool

source

pub unsafe fn set_metatable(&self, index: i32) -> i32

source

pub unsafe fn len(&self, index: i32) -> i32

source

pub unsafe fn raw_geti(&self, t: i32, index: i32)

source

pub unsafe fn raw_seti(&self, t: i32, index: i32)

source

pub unsafe fn next(&self, index: i32) -> i32

source

pub unsafe fn to_pointer(&self, index: i32) -> *const c_void

source

pub unsafe fn to_userdata(&self, index: i32) -> *mut c_void

source

pub unsafe fn coroutine_new(&self) -> State

source

pub unsafe fn coroutine_yield(&self, nresults: i32) -> i32

source

pub unsafe fn coroutine_resume(&self, narg: i32) -> i32

source

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.

source

pub unsafe fn equal(&self, index1: i32, index2: i32) -> bool

source

pub unsafe fn coroutine_resume_call(&self, narg: i32)

See call

source

pub unsafe fn coroutine_resume_pcall_ignore(&self, narg: i32) -> Result<i32, ()>

See pcall_ignore

source

pub unsafe fn coroutine_status(&self) -> i32

source

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.

source

pub unsafe fn new_userdata<T: Sized>( &self, data: T, metatable: Option<i32> ) -> *mut T

source

pub unsafe fn error<S: AsRef<str>>(&self, msg: S) -> !

source

pub unsafe fn debug_getinfo_from_ar( &self, ar: &mut LuaDebug, what: LuaString ) -> Result<(), ()>

source

pub unsafe fn debug_getinfo_from_stack( &self, what: LuaString ) -> Option<LuaDebug>

what should start with > and pop a function off the stack

source

pub unsafe fn get_stack_at(&self, level: i32) -> Option<LuaDebug>

source

pub unsafe fn debug_getinfo_at( &self, level: i32, what: LuaString ) -> Option<LuaDebug>

source

pub unsafe fn dump_stack(&self)

source

pub unsafe fn dump_val(&self, index: i32) -> String

source§

impl State

source

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.

Trait Implementations§

source§

impl Clone for LuaState

source§

fn clone(&self) -> LuaState

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for LuaState

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for LuaState

§

type Target = *mut c_void

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl Copy for LuaState

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.