#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(clippy::inline_always)]
#![allow(clippy::missing_safety_doc)]
use core::{ffi::{CStr, c_char, c_double, c_int, c_long, c_void}, marker::{PhantomData, PhantomPinned}, mem::MaybeUninit, ptr};
pub type lua_CFunction = unsafe extern "C-unwind" fn(L: *mut lua_State) -> c_int;
pub type lua_Reader = unsafe extern "C-unwind" fn(L: *mut lua_State, ud: *mut c_void, sz: *mut usize) -> *const c_char;
pub type lua_Writer = unsafe extern "C-unwind" fn(L: *mut lua_State, p: *const c_void, sz: usize, ud: *mut c_void) -> c_int;
pub type lua_Alloc = unsafe extern "C" fn(ud: *mut c_void, ptr: *mut c_void, osize: usize, nsize: usize) -> *mut c_void;
pub type lua_Number = c_double;
pub type lua_Integer = isize;
pub type lua_Hook = unsafe extern "C-unwind" fn(L: *mut lua_State, ar: *mut lua_Debug);
pub type luaJIT_profile_callback = unsafe extern "C-unwind" fn(L: *mut lua_State, samples: c_int, vmstate: c_int);
pub const LUA_MULTRET: c_int = -1;
pub const LUA_REGISTRYINDEX: c_int = -10000;
pub const LUA_ENVIRONINDEX: c_int = -10001;
pub const LUA_GLOBALSINDEX: c_int = -10002;
pub const LUA_OK: c_int = 0;
pub const LUA_YIELD: c_int = 1;
pub const LUA_ERRRUN: c_int = 2;
pub const LUA_ERRSYNTAX: c_int = 3;
pub const LUA_ERRMEM: c_int = 4;
pub const LUA_ERRERR: c_int = 5;
pub const LUA_ERRFILE: c_int = LUA_ERRERR + 1;
pub const LUA_TNONE: c_int = -1;
pub const LUA_TNIL: c_int = 0;
pub const LUA_TBOOLEAN: c_int = 1;
pub const LUA_TLIGHTUSERDATA: c_int = 2;
pub const LUA_TNUMBER: c_int = 3;
pub const LUA_TSTRING: c_int = 4;
pub const LUA_TTABLE: c_int = 5;
pub const LUA_TFUNCTION: c_int = 6;
pub const LUA_TUSERDATA: c_int = 7;
pub const LUA_TTHREAD: c_int = 8;
pub const LUA_MINSTACK: c_int = 20;
pub const LUA_GCSTOP: c_int = 0;
pub const LUA_GCRESTART: c_int = 1;
pub const LUA_GCCOLLECT: c_int = 2;
pub const LUA_GCCOUNT: c_int = 3;
pub const LUA_GCCOUNTB: c_int = 4;
pub const LUA_GCSTEP: c_int = 5;
pub const LUA_GCSETPAUSE: c_int = 6;
pub const LUA_GCSETSTEPMUL: c_int = 7;
pub const LUA_GCISRUNNING: c_int = 9;
pub const LUA_IDSIZE: usize = 60;
pub const LUA_HOOKCALL: c_int = 0;
pub const LUA_HOOKRET: c_int = 1;
pub const LUA_HOOKLINE: c_int = 2;
pub const LUA_HOOKCOUNT: c_int = 3;
pub const LUA_HOOKTAILRET: c_int = 4;
pub const LUA_MASKCALL: c_int = 1 << LUA_HOOKCALL;
pub const LUA_MASKRET: c_int = 1 << LUA_HOOKRET;
pub const LUA_MASKLINE: c_int = 1 << LUA_HOOKLINE;
pub const LUA_MASKCOUNT: c_int = 1 << LUA_HOOKCOUNT;
pub const LUA_NOREF: c_int = -2;
pub const LUA_REFNIL: c_int = -1;
pub const LUAL_BUFFERSIZE: usize = if cfg!(windows) {
512
} else if cfg!(unix) {
if cfg!(any(all(target_os = "linux", target_env = "gnu"), target_os = "haiku")) {
8192
} else if cfg!(any(all(target_os = "linux", target_env = "uclibc"), target_os = "aix")) {
4096
} else if cfg!(all(target_os = "l4re", target_env = "uclibc")) {
256
} else {
1024
}
} else {
8192
};
pub const LUAJIT_MODE_MASK: c_int = 0x00FF;
pub const LUAJIT_MODE_ENGINE: c_int = 0;
pub const LUAJIT_MODE_DEBUG: c_int = 1;
pub const LUAJIT_MODE_FUNC: c_int = 2;
pub const LUAJIT_MODE_ALLFUNC: c_int = 3;
pub const LUAJIT_MODE_ALLSUBFUNC: c_int = 4;
pub const LUAJIT_MODE_TRACE: c_int = 5;
pub const LUAJIT_MODE_WRAPCFUNC: c_int = 0x10;
pub const LUAJIT_MODE_MAX: c_int = 0x11;
pub const LUAJIT_MODE_OFF: c_int = 0x0000;
pub const LUAJIT_MODE_ON: c_int = 0x0100;
pub const LUAJIT_MODE_FLUSH: c_int = 0x0200;
#[repr(C)]
pub struct lua_State((), PhantomData<(*mut c_void, PhantomPinned)>);
#[repr(C)]
#[derive(Debug, Clone)]
pub struct lua_Debug {
pub event: c_int,
pub name: MaybeUninit<*const c_char>,
pub namewhat: MaybeUninit<*const c_char>,
pub what: MaybeUninit<*const c_char>,
pub source: MaybeUninit<*const c_char>,
pub currentline: c_int,
pub nups: MaybeUninit<c_int>,
pub linedefined: MaybeUninit<c_int>,
pub lastlinedefined: MaybeUninit<c_int>,
pub short_src: MaybeUninit<[c_char; LUA_IDSIZE]>,
pub(crate) i_ci: c_int,
}
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct luaL_Reg {
pub name: *const c_char,
pub func: Option<lua_CFunction>,
}
#[repr(C)]
#[derive(Debug)]
pub struct luaL_Buffer {
pub(crate) p: *mut c_char,
pub(crate) lvl: c_int,
pub(crate) L: *mut lua_State,
pub(crate) buffer: [MaybeUninit<c_char>; LUAL_BUFFERSIZE],
_marker: PhantomData<PhantomPinned>,
}
#[cfg_attr(windows, link(name = "lua51", kind = "raw-dylib"))]
unsafe extern "C-unwind" {
pub fn lua_newstate(f: lua_Alloc, ud: *mut c_void) -> *mut lua_State; pub fn lua_close(L: *mut lua_State);
pub fn lua_newthread(L: *mut lua_State) -> *mut lua_State;
pub fn lua_atpanic(L: *mut lua_State, panicf: lua_CFunction) -> lua_CFunction;
pub fn lua_gettop(L: *mut lua_State) -> c_int;
pub fn lua_settop(L: *mut lua_State, idx: c_int);
pub fn lua_pushvalue(L: *mut lua_State, idx: c_int);
pub fn lua_remove(L: *mut lua_State, idx: c_int);
pub fn lua_insert(L: *mut lua_State, idx: c_int);
pub fn lua_replace(L: *mut lua_State, idx: c_int);
pub fn lua_checkstack(L: *mut lua_State, sz: c_int) -> c_int;
pub fn lua_xmove(from: *mut lua_State, to: *mut lua_State, n: c_int);
pub fn lua_isnumber(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_isstring(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_iscfunction(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_isuserdata(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_type(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_typename(L: *mut lua_State, tp: c_int) -> *const c_char;
pub fn lua_equal(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int;
pub fn lua_rawequal(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int;
pub fn lua_lessthan(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int;
pub fn lua_tonumber(L: *mut lua_State, idx: c_int) -> lua_Number;
pub fn lua_tointeger(L: *mut lua_State, idx: c_int) -> lua_Integer;
pub fn lua_toboolean(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_tolstring(L: *mut lua_State, idx: c_int, len: *mut usize) -> *const c_char;
pub fn lua_objlen(L: *mut lua_State, idx: c_int) -> usize;
pub fn lua_tocfunction(L: *mut lua_State, idx: c_int) -> Option<lua_CFunction>;
pub fn lua_touserdata(L: *mut lua_State, idx: c_int) -> *mut c_void;
pub fn lua_tothread(L: *mut lua_State, idx: c_int) -> *mut lua_State; pub fn lua_topointer(L: *mut lua_State, idx: c_int) -> *const c_void;
pub fn lua_pushnil(L: *mut lua_State);
pub fn lua_pushnumber(L: *mut lua_State, n: lua_Number);
pub fn lua_pushinteger(L: *mut lua_State, n: lua_Integer);
pub fn lua_pushlstring(L: *mut lua_State, s: *const c_char, l: usize);
pub fn lua_pushstring(L: *mut lua_State, s: *const c_char);
#[cfg(feature = "no_msrv")]
#[clippy::msrv = "1.99.0"]
pub fn lua_pushvfstring(L: *mut lua_State, fmt: *const c_char, argp: core::ffi::VaList) -> *const c_char; pub fn lua_pushfstring(L: *mut lua_State, fmt: *const c_char, ...) -> *const c_char; pub fn lua_pushcclosure(L: *mut lua_State, r#fn: lua_CFunction, n: c_int);
pub fn lua_pushboolean(L: *mut lua_State, b: c_int);
pub fn lua_pushlightuserdata(L: *mut lua_State, p: *mut c_void);
pub fn lua_pushthread(L: *mut lua_State) -> c_int;
pub fn lua_gettable(L: *mut lua_State, idx: c_int);
pub fn lua_getfield(L: *mut lua_State, idx: c_int, k: *const c_char);
pub fn lua_rawget(L: *mut lua_State, idx: c_int);
pub fn lua_rawgeti(L: *mut lua_State, idx: c_int, n: c_int);
pub fn lua_createtable(L: *mut lua_State, narr: c_int, nrec: c_int);
pub fn lua_newuserdata(L: *mut lua_State, sz: usize) -> *mut c_void;
pub fn lua_getmetatable(L: *mut lua_State, objindex: c_int) -> c_int;
pub fn lua_getfenv(L: *mut lua_State, idx: c_int);
pub fn lua_settable(L: *mut lua_State, idx: c_int);
pub fn lua_setfield(L: *mut lua_State, idx: c_int, k: *const c_char);
pub fn lua_rawset(L: *mut lua_State, idx: c_int);
pub fn lua_rawseti(L: *mut lua_State, idx: c_int, n: c_int);
pub fn lua_setmetatable(L: *mut lua_State, objindex: c_int) -> c_int;
pub fn lua_setfenv(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_call(L: *mut lua_State, nargs: c_int, nresults: c_int);
pub fn lua_pcall(L: *mut lua_State, nargs: c_int, nresults: c_int, errfunc: c_int) -> c_int;
pub fn lua_cpcall(L: *mut lua_State, func: lua_CFunction, ud: *mut c_void) -> c_int;
pub fn lua_load(L: *mut lua_State, reader: lua_Reader, dt: *mut c_void, chunkname: *const c_char) -> c_int; pub fn lua_dump(L: *mut lua_State, writer: lua_Writer, dt: *mut c_void) -> c_int;
pub fn lua_yield(L: *mut lua_State, nresults: c_int) -> c_int; pub fn lua_resume(L: *mut lua_State, narg: c_int) -> c_int; pub fn lua_status(L: *mut lua_State) -> c_int;
pub fn lua_gc(L: *mut lua_State, what: c_int, data: c_int) -> c_int;
pub fn lua_error(L: *mut lua_State) -> c_int;
pub fn lua_next(L: *mut lua_State, index: c_int) -> c_int;
pub fn lua_concat(L: *mut lua_State, n: c_int);
pub fn lua_getallocf(L: *mut lua_State, ud: *mut *mut c_void) -> lua_Alloc; pub fn lua_setallocf(L: *mut lua_State, f: lua_Alloc, ud: *mut c_void);
pub fn lua_getstack(L: *mut lua_State, level: c_int, ar: *mut lua_Debug) -> c_int;
pub fn lua_getinfo(L: *mut lua_State, what: *const c_char, ar: *mut lua_Debug) -> c_int;
pub fn lua_getlocal(L: *mut lua_State, ar: *const lua_Debug, n: c_int) -> *const c_char;
pub fn lua_setlocal(L: *mut lua_State, ar: *const lua_Debug, n: c_int) -> *const c_char;
pub fn lua_getupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char;
pub fn lua_setupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char;
pub fn lua_sethook(L: *mut lua_State, func: Option<lua_Hook>, mask: c_int, count: c_int) -> c_int;
pub fn lua_gethook(L: *mut lua_State) -> Option<lua_Hook>;
pub fn lua_gethookmask(L: *mut lua_State) -> c_int;
pub fn lua_gethookcount(L: *mut lua_State) -> c_int;
pub fn lua_upvalueid(L: *mut lua_State, idx: c_int, n: c_int) -> *mut c_void;
pub fn lua_upvaluejoin(L: *mut lua_State, idx1: c_int, n1: c_int, idx2: c_int, n2: c_int); pub fn lua_loadx(L: *mut lua_State, reader: lua_Reader, dt: *mut c_void, chunkname: *const c_char, mode: *const c_char) -> c_int; pub safe fn lua_version(L: *mut lua_State) -> *const lua_Number;
pub fn lua_copy(L: *mut lua_State, fromidx: c_int, toidx: c_int);
pub fn lua_tonumberx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Number;
pub fn lua_tointegerx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Integer;
pub fn lua_isyieldable(L: *mut lua_State) -> c_int;
pub fn luaL_openlib(L: *mut lua_State, libname: *const c_char, l: *const luaL_Reg, nup: c_int); pub fn luaL_register(L: *mut lua_State, libname: *const c_char, l: *const luaL_Reg);
pub fn luaL_getmetafield(L: *mut lua_State, obj: c_int, e: *const c_char) -> c_int; pub fn luaL_callmeta(L: *mut lua_State, obj: c_int, e: *const c_char) -> c_int;
pub fn luaL_typerror(L: *mut lua_State, narg: c_int, tname: *const c_char) -> c_int;
pub fn luaL_argerror(L: *mut lua_State, numarg: c_int, extramsg: *const c_char) -> c_int;
pub fn luaL_checklstring(L: *mut lua_State, numArg: c_int, l: *mut usize) -> *const c_char;
pub fn luaL_optlstring(L: *mut lua_State, numArg: c_int, def: *const c_char, l: *mut usize) -> *const c_char;
pub fn luaL_checknumber(L: *mut lua_State, numArg: c_int) -> lua_Number;
pub fn luaL_optnumber(L: *mut lua_State, nArg: c_int, def: lua_Number) -> lua_Number;
pub fn luaL_checkinteger(L: *mut lua_State, numArg: c_int) -> lua_Integer;
pub fn luaL_optinteger(L: *mut lua_State, nArg: c_int, def: lua_Integer) -> lua_Integer;
pub fn luaL_checkstack(L: *mut lua_State, sz: c_int, msg: *const c_char);
pub fn luaL_checktype(L:*mut lua_State, narg: c_int, t: c_int);
pub fn luaL_checkany(L: *mut lua_State, narg: c_int);
pub fn luaL_newmetatable(L: *mut lua_State, tname: *const c_char) -> c_int;
pub fn luaL_checkudata(L: *mut lua_State, ud: c_int, tname: *const c_char) -> *mut c_void;
pub fn luaL_where(L: *mut lua_State, lvl: c_int);
pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> c_int;
pub fn luaL_checkoption(L: *mut lua_State, narg: c_int, def: *const c_char, lst: *const *const c_char) -> c_int;
pub fn luaL_ref(L: *mut lua_State, t: c_int) -> c_int; pub fn luaL_unref(L: *mut lua_State, t: c_int, r#ref: c_int);
pub fn luaL_loadfile(L: *mut lua_State, filename: *const c_char) -> c_int;
pub fn luaL_loadbuffer(L: *mut lua_State, buff: *const c_char, sz: usize, name: *const c_char) -> c_int;
pub fn luaL_loadstring(L: *mut lua_State, s: *const c_char) -> c_int;
pub safe fn luaL_newstate() -> *mut lua_State;
pub fn luaL_gsub(L: *mut lua_State, s: *const c_char, p: *const c_char, r: *const c_char) -> *const c_char;
pub fn luaL_findtable(L: *mut lua_State, idx: c_int, fname: *const c_char, szhint: c_int) -> *const c_char;
pub fn luaL_fileresult(L: *mut lua_State, stat: c_int, fname: *const c_char) -> c_int; pub fn luaL_execresult(L: *mut lua_State, stat: c_int) -> c_int; pub fn luaL_loadfilex(L: *mut lua_State, filename: *const c_char, mode: *const c_char) -> c_int; pub fn luaL_loadbufferx(L: *mut lua_State, buff: *const c_char, sz: usize, name: *const c_char, mode: *const c_char) -> c_int; pub fn luaL_traceback(L: *mut lua_State, L1: *mut lua_State, msg: *const c_char, level: c_int); pub fn luaL_setfuncs(L: *mut lua_State, l: *const luaL_Reg, nup: c_int); pub fn luaL_pushmodule(L: *mut lua_State, modname: *const c_char, sizehint: c_int); pub fn luaL_testudata(L: *mut lua_State, ud: c_int, tname: *const c_char) -> *mut c_void;
pub fn luaL_setmetatable(L: *mut lua_State, tname: *const c_char);
pub fn luaL_buffinit(L: *mut lua_State, B: *mut luaL_Buffer);
pub fn luaL_prepbuffer(B: *mut luaL_Buffer) -> *mut c_char;
pub fn luaL_addlstring(B: *mut luaL_Buffer, s: *const c_char, l: usize);
pub fn luaL_addstring(B: *mut luaL_Buffer, s: *const c_char);
pub fn luaL_addvalue(B: *mut luaL_Buffer);
pub fn luaL_pushresult(B: *mut luaL_Buffer);
pub fn luaL_openlibs(L: *mut lua_State);
pub fn luaopen_base(L: *mut lua_State) -> c_int; pub fn luaopen_math(L: *mut lua_State) -> c_int; pub fn luaopen_string(L: *mut lua_State) -> c_int; pub fn luaopen_table(L: *mut lua_State) -> c_int; pub fn luaopen_io(L: *mut lua_State) -> c_int; pub fn luaopen_os(L: *mut lua_State) -> c_int; pub fn luaopen_package(L: *mut lua_State) -> c_int; pub fn luaopen_debug(L: *mut lua_State) -> c_int; pub fn luaopen_bit(L: *mut lua_State) -> c_int; pub fn luaopen_jit(L: *mut lua_State) -> c_int; pub fn luaopen_ffi(L: *mut lua_State) -> c_int; pub fn luaopen_string_buffer(L: *mut lua_State) -> c_int;
pub fn luaJIT_setmode(L: *mut lua_State, idx: c_int, mode: c_int) -> c_int; pub fn luaJIT_profile_start(L: *mut lua_State, mode: *const c_char, cb: luaJIT_profile_callback, data: *mut c_void); pub fn luaJIT_profile_stop(L: *mut lua_State); pub fn luaJIT_profile_dumpstack(L: *mut lua_State, fmt: *const c_char, depth: c_int, len: *mut usize) -> *const c_char; }
#[inline(always)]
pub const fn lua_upvalueindex(i: c_int) -> c_int {
LUA_GLOBALSINDEX - i as c_int
}
#[inline(always)]
pub unsafe fn lua_pop(L: *mut lua_State, n: c_int) {
unsafe { lua_settop(L, -(n)-1); }
}
#[inline(always)]
pub unsafe fn lua_newtable(L: *mut lua_State) {
unsafe { lua_createtable(L, 0, 0); }
}
#[inline(always)]
pub unsafe fn lua_register(L: *mut lua_State, n: *const c_char, f: lua_CFunction) {
unsafe { lua_pushcfunction(L, f); lua_setglobal(L, n); }
}
#[inline(always)]
pub unsafe fn lua_pushcfunction(L: *mut lua_State, f: lua_CFunction) {
unsafe { lua_pushcclosure(L, f, 0); }
}
#[inline(always)]
pub unsafe fn lua_strlen(L: *mut lua_State, i: c_int) -> usize {
unsafe { lua_objlen(L, i) }
}
#[inline(always)]
pub unsafe fn lua_isfunction(L: *mut lua_State, n: c_int) -> c_int {
unsafe { c_int::from(lua_type(L, n) == LUA_TFUNCTION) }
}
#[inline(always)]
pub unsafe fn lua_istable(L: *mut lua_State, n: c_int) -> c_int {
unsafe { c_int::from(lua_type(L, n) == LUA_TTABLE) }
}
#[inline(always)]
pub unsafe fn lua_islightuserdata(L: *mut lua_State, n: c_int) -> c_int {
unsafe { c_int::from(lua_type(L, n) == LUA_TLIGHTUSERDATA) }
}
#[inline(always)]
pub unsafe fn lua_isnil(L: *mut lua_State, n: c_int) -> c_int {
unsafe { c_int::from(lua_type(L, n) == LUA_TNIL) }
}
#[inline(always)]
pub unsafe fn lua_isboolean(L: *mut lua_State, n: c_int) -> c_int {
unsafe { c_int::from(lua_type(L, n) == LUA_TBOOLEAN) }
}
#[inline(always)]
pub unsafe fn lua_isthread(L: *mut lua_State, n: c_int) -> c_int {
unsafe { c_int::from(lua_type(L, n) == LUA_TTHREAD) }
}
#[inline(always)]
pub unsafe fn lua_isnone(L: *mut lua_State, n: c_int) -> c_int {
unsafe { c_int::from(lua_type(L, n) == LUA_TNONE) }
}
#[inline(always)]
pub unsafe fn lua_isnoneornil(L: *mut lua_State, n: c_int) -> c_int {
unsafe { c_int::from(lua_type(L, n) <= 0) }
}
#[inline(always)]
pub unsafe fn lua_pushliteral(L: *mut lua_State, s: *const c_char) {
unsafe { lua_pushlstring(L, s, CStr::from_ptr(s).count_bytes()); }
}
#[inline(always)]
pub unsafe fn lua_setglobal(L: *mut lua_State, s: *const c_char) {
unsafe { lua_setfield(L, LUA_GLOBALSINDEX, s); }
}
#[inline(always)]
pub unsafe fn lua_getglobal(L: *mut lua_State, s: *const c_char) {
unsafe { lua_getfield(L, LUA_GLOBALSINDEX, s); }
}
#[inline(always)]
pub unsafe fn lua_tostring(L: *mut lua_State, i: c_int) -> *const c_char {
unsafe { lua_tolstring(L, i, ptr::null_mut()) }
}
#[inline(always)]
pub unsafe fn luaL_argcheck(L: *mut lua_State, cond: c_int, numarg: c_int, extramsg: *const c_char) {
if cond != 0 { unsafe { luaL_argerror(L, numarg, extramsg); } }
}
#[inline(always)]
pub unsafe fn luaL_checkstring(L: *mut lua_State, n: c_int) -> *const c_char {
unsafe { luaL_checklstring(L, n, ptr::null_mut()) }
}
#[inline(always)]
pub unsafe fn luaL_optstring(L: *mut lua_State, n: c_int, d: *const c_char) -> *const c_char {
unsafe { luaL_optlstring(L, n, d, ptr::null_mut()) }
}
#[inline(always)]
#[allow(clippy::cast_possible_truncation)]
pub unsafe fn luaL_checkint(L: *mut lua_State, n: c_int) -> c_int {
unsafe { luaL_checkinteger(L, n) as c_int }
}
#[inline(always)]
#[allow(clippy::cast_possible_truncation)]
pub unsafe fn luaL_optint(L: *mut lua_State, n: c_int, d: lua_Integer) -> c_int {
unsafe { luaL_optinteger(L, n, d) as c_int }
}
#[inline(always)]
pub unsafe fn luaL_checklong(L: *mut lua_State, n: c_int) -> c_long {
unsafe { luaL_checkinteger(L, n) as c_long }
}
#[inline(always)]
pub unsafe fn luaL_optlong(L: *mut lua_State, n: c_int, d: lua_Integer) -> c_long {
unsafe { luaL_optinteger(L, n, d) as c_long }
}
#[inline(always)]
pub unsafe fn luaL_typename(L: *mut lua_State, i: i32) -> *const c_char {
unsafe { lua_typename(L, lua_type(L, i)) }
}
#[inline(always)]
pub unsafe fn luaL_dofile(L: *mut lua_State, r#fn: *const c_char) -> c_int {
unsafe {
let ok = luaL_loadfile(L, r#fn);
if ok != 0 { return ok; }
lua_pcall(L, 0, LUA_MULTRET, 0)
}
}
#[inline(always)]
pub unsafe fn luaL_dostring(L: *mut lua_State, s: *const c_char) -> c_int {
unsafe {
let ok = luaL_loadstring(L, s);
if ok != 0 { return ok; }
lua_pcall(L, 0, LUA_MULTRET, 0)
}
}
#[inline(always)]
pub unsafe fn luaL_getmetatable(L: *mut lua_State, n: *const c_char) {
unsafe { lua_getfield(L, LUA_REGISTRYINDEX, n); }
}
#[inline(always)]
pub unsafe fn luaL_opt<T>(L: *mut lua_State, f: impl FnOnce(*mut lua_State, c_int) -> T, n: c_int, d: T) -> T {
if unsafe { lua_isnoneornil(L, n) != 0 } { d } else { f(L, n) }
}
#[inline(always)]
pub unsafe fn luaL_newlibtable(L: *mut lua_State, l: *const luaL_Reg) {
const unsafe fn sizeof(mut l: *const luaL_Reg) -> c_int {
let mut size = 0;
while unsafe { !l.read().name.is_null() } {
size += 1;
l = unsafe { l.add(1) };
}
size
}
unsafe { lua_createtable(L, 0, sizeof(l)); }
}
#[inline(always)]
pub unsafe fn luaL_newlib(L: *mut lua_State, l: *const luaL_Reg) {
unsafe { luaL_newlibtable(L, l); luaL_setfuncs(L, l, 0); }
}
#[inline(always)]
pub unsafe fn luaL_addchar(B: *mut luaL_Buffer, c: c_char) {
unsafe {
if (*B).p >= (*B).buffer.as_mut_ptr().add(LUAL_BUFFERSIZE).cast() { luaL_prepbuffer(B); }
(*B).p.write(c);
(*B).p = (*B).p.add(1);
}
}
#[inline(always)]
pub const unsafe fn luaL_addsize(B: *mut luaL_Buffer, n: usize) {
unsafe { (*B).p = (*B).p.add(n); }
}