#![allow(clippy::missing_safety_doc)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
use std::marker::{PhantomData, PhantomPinned};
use std::{
ffi::{c_char, c_double, c_float, c_int, c_uchar, c_uint, c_void},
ptr::null_mut,
};
use super::*;
pub const LUA_MULTRET: c_int = -1;
pub const LUA_REGISTRYINDEX: c_int = -LUAI_MAXCSTACK - 2000;
pub const LUA_ENVIRONINDEX: c_int = -LUAI_MAXCSTACK - 2001;
pub const LUA_GLOBALSINDEX: c_int = -LUAI_MAXCSTACK - 2002;
pub fn lua_upvalueindex(i: c_int) -> c_int {
LUA_GLOBALSINDEX - i
}
pub fn lua_ispseudo(i: c_int) -> bool {
i <= LUA_REGISTRYINDEX
}
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum lua_Status {
LUA_OK = 0,
LUA_YIELD,
LUA_ERRRUN,
LUA_ERRSYNTAX,
LUA_ERRMEM,
LUA_ERRERR,
LUA_BREAK,
}
pub use lua_Status::*;
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum lua_CoStatus {
LUA_CORUN = 0,
LUA_COSUS,
LUA_CONOR,
LUA_COFIN,
LUA_COERR,
}
pub use lua_CoStatus::*;
#[repr(C)]
pub struct lua_State {
_data: (),
_marker: PhantomData<(*mut u8, PhantomPinned)>,
}
pub type lua_CFunction = extern "C-unwind" fn(L: *mut lua_State) -> c_int;
pub type lua_Continuation = extern "C-unwind" fn(L: *mut lua_State, status: lua_Status) -> c_int;
pub type lua_Alloc = extern "C-unwind" fn(
ud: *mut c_void,
ptr: *mut c_void,
osize: usize,
nsize: usize,
) -> *mut c_void;
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum lua_Type {
LUA_TNONE = -1,
LUA_TNIL = 0,
LUA_TBOOLEAN = 1,
LUA_TLIGHTUSERDATA,
LUA_TNUMBER,
LUA_TVECTOR,
LUA_TSTRING,
LUA_TTABLE,
LUA_TFUNCTION,
LUA_TUSERDATA,
LUA_TTHREAD,
LUA_TBUFFER,
}
pub use lua_Type::*;
pub type lua_Number = c_double;
pub type lua_Integer = c_int;
pub type lua_Unsigned = c_uint;
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_mainthread(L: *mut lua_State) -> *mut lua_State;
pub fn lua_resetthread(L: *mut lua_State);
pub fn lua_isthreadreset(L: *mut lua_State) -> c_int;
pub fn lua_absindex(L: *mut lua_State, idx: c_int) -> c_int;
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_rawcheckstack(L: *mut lua_State, sz: c_int);
pub fn lua_xmove(from: *mut lua_State, to: *mut lua_State, n: c_int);
pub fn lua_xpush(from: *mut lua_State, to: *mut lua_State, idx: 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_isLfunction(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) -> lua_Type;
pub fn lua_typename(L: *mut lua_State, tp: lua_Type) -> *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_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_tounsignedx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Unsigned;
pub fn lua_tovector(L: *mut lua_State, idx: c_int) -> *const c_float;
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_tostringatom(L: *mut lua_State, idx: c_int, atom: *mut c_int) -> *const c_char;
pub fn lua_tolstringatom(
L: *mut lua_State,
idx: c_int,
len: *mut usize,
atom: *mut c_int,
) -> *const c_char;
pub fn lua_namecallatom(L: *mut lua_State, atom: *mut c_int) -> *const c_char;
pub fn lua_objlen(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_tocfunction(L: *mut lua_State, idx: c_int) -> Option<lua_CFunction>;
pub fn lua_tolightuserdata(L: *mut lua_State, idx: c_int) -> *mut c_void;
pub fn lua_tolightuserdatatagged(L: *mut lua_State, idx: c_int, tag: c_int) -> *mut c_void;
pub fn lua_touserdata(L: *mut lua_State, idx: c_int) -> *mut c_void;
pub fn lua_touserdatatagged(L: *mut lua_State, idx: c_int, tag: c_int) -> *mut c_void;
pub fn lua_userdatatag(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_lightuserdatatag(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_tothread(L: *mut lua_State, idx: c_int) -> *mut lua_State;
pub fn lua_tobuffer(L: *mut lua_State, idx: c_int, len: *mut usize) -> *mut c_void;
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_pushunsigned(L: *mut lua_State, n: lua_Unsigned);
pub fn lua_pushvector(L: *mut lua_State, x: c_float, y: c_float, z: c_float);
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);
pub fn lua_pushcclosurek(
L: *mut lua_State,
r#fn: lua_CFunction,
debugname: *const c_char,
nup: c_int,
cont: Option<lua_Continuation>,
);
pub fn lua_pushboolean(L: *mut lua_State, b: c_int);
pub fn lua_pushthread(L: *mut lua_State) -> c_int;
pub fn lua_pushlightuserdatatagged(L: *mut lua_State, p: *mut c_void, tag: c_int);
pub fn lua_newuserdatatagged(L: *mut lua_State, size: usize, tag: c_int) -> *mut c_void;
pub fn lua_newuserdatataggedwithmetatable(
L: *mut lua_State,
size: usize,
tag: c_int,
) -> *mut c_void;
pub fn lua_newuserdatadtor(
L: *mut lua_State,
size: usize,
dtor: Option<extern "C-unwind" fn(*mut c_void)>,
) -> *mut c_void;
pub fn lua_newbuffer(L: *mut lua_State, size: usize) -> *mut c_void;
pub fn lua_gettable(L: *mut lua_State, idx: c_int) -> lua_Type;
pub fn lua_getfield(L: *mut lua_State, idx: c_int, k: *const c_char) -> lua_Type;
pub fn lua_rawgetfield(L: *mut lua_State, idx: c_int, k: *const c_char) -> lua_Type;
pub fn lua_rawget(L: *mut lua_State, idx: c_int) -> lua_Type;
pub fn lua_rawgeti(L: *mut lua_State, idx: c_int, k: c_int) -> lua_Type;
pub fn lua_createtable(L: *mut lua_State, narr: c_int, nrec: c_int);
pub fn lua_setreadonly(L: *mut lua_State, idx: c_int, enabled: c_int);
pub fn lua_getreadonly(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_setsafeenv(L: *mut lua_State, idx: c_int, enabled: c_int);
pub fn lua_getmetatable(L: *mut lua_State, idx: 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_rawsetfield(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, k: c_int) -> c_int;
pub fn lua_setmetatable(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_setfenv(L: *mut lua_State, idx: c_int) -> c_int;
pub fn luau_load(
L: *mut lua_State,
chunkname: *const c_char,
data: *const c_char,
size: usize,
env: 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,
) -> lua_Status;
pub fn lua_cpcall(L: *mut lua_State, func: lua_CFunction, ud: *mut c_void) -> lua_Status;
pub fn lua_yield(L: *mut lua_State, nresults: c_int) -> c_int;
pub fn lua_break(L: *mut lua_State) -> c_int;
pub fn lua_resume(L: *mut lua_State, from: *mut lua_State, nargs: c_int) -> lua_Status;
pub fn lua_resumeerror(L: *mut lua_State, from: *mut lua_State) -> lua_Status;
pub fn lua_status(L: *mut lua_State) -> lua_Status;
pub fn lua_isyieldable(L: *mut lua_State) -> c_int;
pub fn lua_getthreaddata(L: *mut lua_State) -> *mut c_void;
pub fn lua_setthreaddata(L: *mut lua_State, data: *mut c_void);
pub fn lua_costatus(L: *mut lua_State) -> lua_CoStatus;
}
#[repr(C)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum lua_GCOp {
LUA_GCSTOP,
LUA_GCRESTART,
LUA_GCCOLLECT,
LUA_GCCOUNT,
LUA_GCCOUNTB,
LUA_GCISRUNNING,
LUA_GCSTEP,
LUA_GCSETGOAL,
LUA_GCSETSTEPMUL,
LUA_GCSETSTEPSIZE,
}
unsafe extern "C-unwind" {
pub fn lua_gc(L: *mut lua_State, what: lua_GCOp, data: c_int) -> c_int;
pub fn lua_setmemcat(L: *mut lua_State, category: c_int);
pub fn lua_totalbytes(L: *mut lua_State, category: c_int) -> usize;
pub fn lua_error(L: *mut lua_State) -> !;
pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_rawiter(L: *mut lua_State, idx: c_int, iteration_index: c_int) -> c_int;
pub fn lua_concat(L: *mut lua_State, n: c_int);
pub fn lua_encodepointer(L: *mut lua_State, p: usize) -> usize;
pub fn lua_clock() -> c_double;
pub fn lua_setuserdatatag(L: *mut lua_State, idx: c_int, tag: c_int) -> c_int;
}
pub type lua_Destructor = extern "C-unwind" fn(L: *mut lua_State, userdata: *mut c_void);
unsafe extern "C-unwind" {
pub fn lua_setuserdatadtor(L: *mut lua_State, tag: c_int, dtor: Option<lua_Destructor>);
pub fn lua_getuserdatadtor(L: *mut lua_State, tag: c_int) -> Option<lua_Destructor>;
pub fn lua_setuserdatametatable(L: *mut lua_State, tag: c_int);
pub fn lua_getuserdatametatable(L: *mut lua_State, tag: c_int) -> c_int;
pub fn lua_setlightuserdataname(L: *mut lua_State, tag: c_int, name: *const c_char);
pub fn lua_getlightuserdataname(L: *mut lua_State, tag: c_int) -> *const c_char;
pub fn lua_clonefunction(L: *mut lua_State, idx: c_int);
pub fn lua_cleartable(L: *mut lua_State, idx: c_int);
pub fn lua_clonetable(L: *mut lua_State, idx: c_int);
pub fn lua_getallocf(L: *mut lua_State) -> Option<lua_Alloc>;
}
pub const LUA_NOREF: c_int = -1;
pub const LUA_REFNIL: c_int = 0;
unsafe extern "C-unwind" {
pub fn lua_ref(L: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_unref(L: *mut lua_State, ref_: c_int);
}
pub unsafe fn lua_getref(L: *mut lua_State, r#ref: c_int) -> lua_Type {
unsafe { lua_rawgeti(L, LUA_REGISTRYINDEX, r#ref) }
}
pub unsafe fn lua_tonumber(L: *mut lua_State, idx: c_int) -> lua_Number {
unsafe { lua_tonumberx(L, idx, null_mut()) }
}
pub unsafe fn lua_tointeger(L: *mut lua_State, idx: c_int) -> lua_Integer {
unsafe { lua_tointegerx(L, idx, null_mut()) }
}
pub unsafe fn lua_tounsigned(L: *mut lua_State, idx: c_int) -> lua_Unsigned {
unsafe { lua_tounsignedx(L, idx, null_mut()) }
}
pub unsafe fn lua_pop(L: *mut lua_State, n: c_int) {
unsafe { lua_settop(L, -(n) - 1) }
}
pub unsafe fn lua_newtable(L: *mut lua_State) {
unsafe { lua_createtable(L, 0, 0) }
}
pub unsafe fn lua_newuserdata(L: *mut lua_State, size: usize) -> *mut c_void {
unsafe { lua_newuserdatatagged(L, size, 0) }
}
pub unsafe fn lua_strlen(L: *mut lua_State, idx: c_int) -> c_int {
unsafe { lua_objlen(L, idx) }
}
pub unsafe fn lua_isfunction(L: *mut lua_State, idx: c_int) -> bool {
unsafe { lua_type(L, idx) == LUA_TFUNCTION }
}
pub unsafe fn lua_istable(L: *mut lua_State, idx: c_int) -> bool {
unsafe { lua_type(L, idx) == LUA_TTABLE }
}
pub unsafe fn lua_islightuserdata(L: *mut lua_State, idx: c_int) -> bool {
unsafe { lua_type(L, idx) == LUA_TLIGHTUSERDATA }
}
pub unsafe fn lua_isnil(L: *mut lua_State, idx: c_int) -> bool {
unsafe { lua_type(L, idx) == LUA_TNIL }
}
pub unsafe fn lua_isboolean(L: *mut lua_State, idx: c_int) -> bool {
unsafe { lua_type(L, idx) == LUA_TBOOLEAN }
}
pub unsafe fn lua_isvector(L: *mut lua_State, idx: c_int) -> bool {
unsafe { lua_type(L, idx) == LUA_TVECTOR }
}
pub unsafe fn lua_isthread(L: *mut lua_State, idx: c_int) -> bool {
unsafe { lua_type(L, idx) == LUA_TTHREAD }
}
pub unsafe fn lua_isbuffer(L: *mut lua_State, idx: c_int) -> bool {
unsafe { lua_type(L, idx) == LUA_TBUFFER }
}
pub unsafe fn lua_isnone(L: *mut lua_State, idx: c_int) -> bool {
unsafe { lua_type(L, idx) == LUA_TNONE }
}
pub unsafe fn lua_isnoneornil(L: *mut lua_State, idx: c_int) -> bool {
unsafe { lua_type(L, idx) as c_int <= LUA_TNIL as c_int }
}
pub unsafe fn lua_pushliteral(L: *mut lua_State, s: &'static [u8]) {
unsafe { lua_pushlstring(L, s.as_ptr() as _, s.len()) }
}
pub unsafe fn lua_pushcfunction(L: *mut lua_State, r#fn: lua_CFunction, debugname: *const c_char) {
unsafe { lua_pushcclosurek(L, r#fn, debugname, 0, None) }
}
pub unsafe fn lua_pushcclosure(
L: *mut lua_State,
r#fn: lua_CFunction,
debugname: *const c_char,
nup: c_int,
) {
unsafe { lua_pushcclosurek(L, r#fn, debugname, nup, None) }
}
pub unsafe fn lua_pushlightuserdata(L: *mut lua_State, p: *mut c_void) {
unsafe { lua_pushlightuserdatatagged(L, p, 0) }
}
pub unsafe fn lua_setglobal(L: *mut lua_State, name: *const c_char) {
unsafe { lua_setfield(L, LUA_GLOBALSINDEX, name) }
}
pub unsafe fn lua_getglobal(L: *mut lua_State, name: *const c_char) -> lua_Type {
unsafe { lua_getfield(L, LUA_GLOBALSINDEX, name) }
}
pub unsafe fn lua_tostring(L: *mut lua_State, idx: c_int) -> *const c_char {
unsafe { lua_tolstring(L, idx, null_mut()) }
}
#[repr(C)]
pub struct lua_Debug {
pub name: *const c_char,
pub what: *const c_char,
pub source: *const c_char,
pub short_src: *const c_char,
pub linedefined: c_int,
pub currentline: c_int,
pub nupvals: c_uchar,
pub nparams: c_uchar,
pub isvararg: c_char,
pub userdata: *mut c_void,
pub ssbuf: [c_char; LUA_IDSIZE as usize],
}
pub type lua_Hook = extern "C-unwind" fn(L: *mut lua_State, ar: *mut lua_Debug);
unsafe extern "C-unwind" {
pub fn lua_stackdepth(L: *mut lua_State) -> c_int;
pub fn lua_getinfo(
L: *mut lua_State,
level: c_int,
what: *const c_char,
ar: *mut lua_Debug,
) -> c_int;
pub fn lua_getargument(L: *mut lua_State, level: c_int, n: c_int) -> c_int;
pub fn lua_getlocal(L: *mut lua_State, level: c_int, n: c_int) -> *const c_char;
pub fn lua_setlocal(L: *mut lua_State, level: c_int, 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_singlestep(L: *mut lua_State, enabled: c_int);
pub fn lua_breakpoint(
L: *mut lua_State,
funcindex: c_int,
line: c_int,
enabled: c_int,
) -> c_int;
}
pub type lua_Coverage = extern "C-unwind" fn(
context: *mut c_void,
function: *const c_char,
linedefined: c_int,
depth: c_int,
hits: *const c_int,
size: usize,
);
unsafe extern "C-unwind" {
pub fn lua_getcoverage(
L: *mut lua_State,
funcindex: c_int,
context: *mut c_void,
callback: lua_Coverage,
);
pub fn lua_debugtrace(L: *mut lua_State) -> *const c_char;
}
#[repr(C)]
pub struct lua_Callbacks {
pub userdata: *mut c_void,
pub interrupt: Option<extern "C-unwind" fn(L: *mut lua_State, gc: c_int)>,
pub panic: Option<extern "C-unwind" fn(L: *mut lua_State, errcode: c_int)>,
pub userthread: Option<extern "C-unwind" fn(LP: *mut lua_State, L: *mut lua_State)>,
pub useratom: Option<extern "C-unwind" fn(s: *const c_char, l: usize) -> i16>,
pub debugbreak: Option<lua_Hook>,
pub debugstep: Option<lua_Hook>,
pub debuginterrupt: Option<lua_Hook>,
pub debugprotectederror: Option<lua_Hook>,
pub onallocate: Option<extern "C-unwind" fn(L: *mut lua_State, osize: usize, nsize: usize)>,
}
unsafe extern "C-unwind" {
pub fn lua_callbacks(L: *mut lua_State) -> *mut lua_Callbacks;
}