luaL_register

Function luaL_register 

Source
pub fn luaL_register(l: LuaState, libname: LuaString, lib: *const LuaReg)
Expand description

Registers a reg of functions onto the LuaState’s _G[libname]. For example you could set libname to cstr!(“math”) to add functions onto the math table or create it if it does not exist.

When called with libname as std::ptr::null(), it simply registers all functions in the list lib into the table on the top of the stack.

§Example

use rglua::prelude::*;

#[lua_function] fn add(l: LuaState) -> i32 {0}
#[lua_function] fn sub(l: LuaState) -> i32 {0}

#[gmod_open]
fn entry(l: LuaState) -> i32 {
	let lib = reg! [
		"add" => add,
		"subtract" => sub
	];
	luaL_register(l, cstr!("math"), lib.as_ptr());
	0
}