#![allow(missing_docs, non_camel_case_types)]
use crate::std::ptr;
use libc::{c_char, c_double, c_int, c_uchar, c_void, int64_t, intptr_t, size_t, uint64_t};
pub const LUA_VERSION_MAJOR: &str = "5";
pub const LUA_VERSION_MINOR: &str = "3";
pub const LUA_VERSION_NUM: c_int = 503;
pub const LUA_VERSION_RELEASE: &str = "4";
pub const LUA_VERSION: &str = "Lua 5.3";
pub const LUA_RELEASE: &str = "Lua 5.3.4";
pub const LUA_COPYRIGHT: &str = "Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio";
pub const LUA_AUTHORS: &str = "R. Ierusalimschy, L. H. de Figueiredo, W. Celes";
pub const LUA_SIGNATURE: &[u8] = b"\x1bLua";
pub const LUA_MULTRET: c_int = -1;
#[cfg(debug_assertions)]
const LUAI_MAXSTACK: c_int = 50000;
#[cfg(not(debug_assertions))]
const LUAI_MAXSTACK: c_int = 1000000;
pub const LUA_REGISTRYINDEX: c_int = -LUAI_MAXSTACK - 1000;
#[inline(always)]
pub fn lua_upvalueindex(i: c_int) -> c_int {
LUA_REGISTRYINDEX - i
}
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_ERRGCMM: c_int = 5;
pub const LUA_ERRERR: c_int = 6;
pub type lua_State = c_void;
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_NUMTAGS: c_int = 9;
pub const LUA_MINSTACK: c_int = 20;
pub const LUA_RIDX_MAINTHREAD: lua_Integer = 1;
pub const LUA_RIDX_GLOBALS: lua_Integer = 2;
pub const LUA_RIDX_LAST: lua_Integer = LUA_RIDX_GLOBALS;
pub type lua_Number = c_double;
pub type lua_Integer = int64_t;
pub const LUA_MAXINTEGER: lua_Integer = 9223372036854775807;
pub const LUA_MININTEGER: lua_Integer = -9223372036854775808;
pub type lua_Unsigned = uint64_t;
pub type lua_KContext = intptr_t;
pub type lua_CFunction = Option<unsafe extern "C" fn(l: *mut lua_State) -> c_int>;
pub type lua_KFunction =
Option<unsafe extern "C" fn(l: *mut lua_State, status: c_int, ctx: lua_KContext) -> c_int>;
pub type lua_Reader = Option<
unsafe extern "C" fn(l: *mut lua_State, ud: *mut c_void, sz: *mut size_t) -> *const c_char,
>;
pub type lua_Writer = Option<
unsafe extern "C" fn(l: *mut lua_State, p: *const c_void, sz: size_t, ud: *mut c_void) -> c_int,
>;
pub type lua_Alloc = Option<
unsafe extern "C" fn(
ud: *mut c_void,
ptr: *mut c_void,
osize: size_t,
nsize: size_t,
) -> *mut c_void,
>;
extern "C" {
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_version(l: *mut lua_State) -> *const lua_Number;
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_rotate(l: *mut lua_State, idx: c_int, n: c_int);
pub fn lua_copy(l: *mut lua_State, fromidx: c_int, toidx: 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_isinteger(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_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_toboolean(l: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_tolstring(l: *mut lua_State, idx: c_int, len: *mut size_t) -> *const c_char;
pub fn lua_rawlen(l: *mut lua_State, idx: c_int) -> size_t;
pub fn lua_tocfunction(l: *mut lua_State, idx: c_int) -> 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 const LUA_OPADD: c_int = 0;
pub const LUA_OPSUB: c_int = 1;
pub const LUA_OPMUL: c_int = 2;
pub const LUA_OPMOD: c_int = 3;
pub const LUA_OPPOW: c_int = 4;
pub const LUA_OPDIV: c_int = 5;
pub const LUA_OPIDIV: c_int = 6;
pub const LUA_OPBAND: c_int = 7;
pub const LUA_OPBOR: c_int = 8;
pub const LUA_OPBXOR: c_int = 9;
pub const LUA_OPSHL: c_int = 10;
pub const LUA_OPSHR: c_int = 11;
pub const LUA_OPUNM: c_int = 12;
pub const LUA_OPBNOT: c_int = 13;
extern "C" {
pub fn lua_arith(l: *mut lua_State, op: c_int);
}
pub const LUA_OPEQ: c_int = 0;
pub const LUA_OPLT: c_int = 1;
pub const LUA_OPLE: c_int = 2;
extern "C" {
pub fn lua_rawequal(l: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int;
pub fn lua_compare(l: *mut lua_State, idx1: c_int, idx2: c_int, op: c_int) -> c_int;
}
extern "C" {
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: size_t) -> *const c_char;
pub fn lua_pushstring(l: *mut lua_State, s: *const c_char) -> *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, f: 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;
}
extern "C" {
pub fn lua_getglobal(l: *mut lua_State, var: *const c_char) -> c_int;
pub fn lua_gettable(l: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_getfield(l: *mut lua_State, idx: c_int, k: *const c_char) -> c_int;
pub fn lua_geti(l: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int;
pub fn lua_rawget(l: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_rawgeti(l: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int;
pub fn lua_rawgetp(l: *mut lua_State, idx: c_int, p: *const c_void) -> 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: size_t) -> *mut c_void;
pub fn lua_getmetatable(l: *mut lua_State, objindex: c_int) -> c_int;
pub fn lua_getuservalue(l: *mut lua_State, idx: c_int) -> c_int;
}
extern "C" {
pub fn lua_setglobal(l: *mut lua_State, var: *const c_char);
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_seti(l: *mut lua_State, idx: c_int, n: lua_Integer);
pub fn lua_rawset(l: *mut lua_State, idx: c_int);
pub fn lua_rawseti(l: *mut lua_State, idx: c_int, n: lua_Integer);
pub fn lua_rawsetp(l: *mut lua_State, idx: c_int, p: *const c_void);
pub fn lua_setmetatable(l: *mut lua_State, objindex: c_int) -> c_int;
pub fn lua_setuservalue(l: *mut lua_State, idx: c_int);
}
extern "C" {
pub fn lua_callk(
l: *mut lua_State,
nargs: c_int,
nresults: c_int,
ctx: lua_KContext,
k: lua_KFunction,
);
pub fn lua_pcallk(
l: *mut lua_State,
nargs: c_int,
nresults: c_int,
errfunc: c_int,
ctx: lua_KContext,
k: lua_KFunction,
) -> c_int;
pub fn lua_load(
l: *mut lua_State,
reader: lua_Reader,
dt: *mut c_void,
chunkname: *const c_char,
mode: *const c_char,
) -> c_int;
pub fn lua_dump(
l: *mut lua_State,
writer: lua_Writer,
data: *mut c_void,
strip: c_int,
) -> c_int;
}
#[inline(always)]
pub unsafe fn lua_call(l: *mut lua_State, n: c_int, r: c_int) {
lua_callk(l, n, r, 0, None)
}
#[inline(always)]
pub unsafe fn lua_pcall(l: *mut lua_State, n: c_int, r: c_int, f: c_int) -> c_int {
lua_pcallk(l, n, r, f, 0, None)
}
extern "C" {
pub fn lua_yieldk(
l: *mut lua_State,
nresults: c_int,
ctx: lua_KContext,
k: lua_KFunction,
) -> c_int;
pub fn lua_resume(l: *mut lua_State, from: *mut lua_State, narg: c_int) -> c_int;
pub fn lua_status(l: *mut lua_State) -> c_int;
pub fn lua_isyieldable(l: *mut lua_State) -> c_int;
}
#[inline(always)]
pub unsafe fn lua_yield(l: *mut lua_State, n: c_int) -> c_int {
lua_yieldk(l, n, 0, None)
}
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;
extern "C" {
pub fn lua_gc(l: *mut lua_State, what: c_int, data: c_int) -> c_int;
}
extern "C" {
pub fn lua_error(l: *mut lua_State) -> !;
pub fn lua_next(l: *mut lua_State, idx: c_int) -> c_int;
pub fn lua_concat(l: *mut lua_State, n: c_int);
pub fn lua_len(l: *mut lua_State, idx: c_int);
pub fn lua_stringtonumber(l: *mut lua_State, s: *const c_char) -> size_t;
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);
}
#[cfg(debug_assertions)]
const LUA_EXTRASPACE: c_int = 16;
#[cfg(not(debug_assertions))]
const LUA_EXTRASPACE: c_int = 8;
#[inline(always)]
pub unsafe fn lua_getextraspace(l: *mut lua_State) -> *mut c_void {
l.offset(-LUA_EXTRASPACE as isize)
}
#[inline(always)]
pub unsafe fn lua_tonumber(l: *mut lua_State, i: c_int) -> lua_Number {
lua_tonumberx(l, i, ptr::null_mut())
}
#[inline(always)]
pub unsafe fn lua_tointeger(l: *mut lua_State, i: c_int) -> lua_Integer {
lua_tointegerx(l, i, ptr::null_mut())
}
#[inline(always)]
pub unsafe fn lua_pop(l: *mut lua_State, n: c_int) {
lua_settop(l, -n - 1);
}
#[inline(always)]
pub unsafe fn lua_newtable(l: *mut lua_State) {
lua_createtable(l, 0, 0);
}
#[inline(always)]
pub unsafe fn lua_register(l: *mut lua_State, n: *const c_char, f: lua_CFunction) {
lua_pushcfunction(l, f);
lua_setglobal(l, n);
}
#[inline(always)]
pub unsafe fn lua_pushcfunction(l: *mut lua_State, f: lua_CFunction) {
lua_pushcclosure(l, f, 0);
}
#[inline(always)]
pub unsafe fn lua_isfunction(l: *mut lua_State, n: c_int) -> c_int {
(lua_type(l, n) == LUA_TFUNCTION) as c_int
}
#[inline(always)]
pub unsafe fn lua_istable(l: *mut lua_State, n: c_int) -> c_int {
(lua_type(l, n) == LUA_TTABLE) as c_int
}
#[inline(always)]
pub unsafe fn lua_islightuserdata(l: *mut lua_State, n: c_int) -> c_int {
(lua_type(l, n) == LUA_TLIGHTUSERDATA) as c_int
}
#[inline(always)]
pub unsafe fn lua_isnil(l: *mut lua_State, n: c_int) -> c_int {
(lua_type(l, n) == LUA_TNIL) as c_int
}
#[inline(always)]
pub unsafe fn lua_isboolean(l: *mut lua_State, n: c_int) -> c_int {
(lua_type(l, n) == LUA_TBOOLEAN) as c_int
}
#[inline(always)]
pub unsafe fn lua_isthread(l: *mut lua_State, n: c_int) -> c_int {
(lua_type(l, n) == LUA_TTHREAD) as c_int
}
#[inline(always)]
pub unsafe fn lua_isnone(l: *mut lua_State, n: c_int) -> c_int {
(lua_type(l, n) == LUA_TNONE) as c_int
}
#[inline(always)]
pub unsafe fn lua_isnoneornil(l: *mut lua_State, n: c_int) -> c_int {
(lua_type(l, n) <= 0) as c_int
}
#[inline(always)]
pub unsafe fn lua_pushliteral(l: *mut lua_State, s: &'static str) -> *const c_char {
lua_pushlstring(l, s.as_ptr() as *const c_char, s.as_bytes().len())
}
#[inline(always)]
pub unsafe fn lua_pushglobaltable(l: *mut lua_State) {
let _ = lua_rawgeti(l, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
}
#[inline(always)]
pub unsafe fn lua_tostring(l: *mut lua_State, i: c_int) -> *const c_char {
lua_tolstring(l, i, ptr::null_mut())
}
#[inline(always)]
pub unsafe fn lua_insert(l: *mut lua_State, idx: c_int) {
lua_rotate(l, idx, 1);
}
#[inline(always)]
pub unsafe fn lua_remove(l: *mut lua_State, idx: c_int) {
lua_rotate(l, idx, -1);
lua_pop(l, 1);
}
#[inline(always)]
pub unsafe fn lua_replace(l: *mut lua_State, idx: c_int) {
lua_copy(l, -1, idx);
lua_pop(l, 1);
}
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_HOOKTAILCALL: c_int = 4;
pub const LUA_MASKCALL: c_int = 1 << (LUA_HOOKCALL as usize);
pub const LUA_MASKRET: c_int = 1 << (LUA_HOOKRET as usize);
pub const LUA_MASKLINE: c_int = 1 << (LUA_HOOKLINE as usize);
pub const LUA_MASKCOUNT: c_int = 1 << (LUA_HOOKCOUNT as usize);
pub type lua_Hook = Option<extern "C" fn(l: *mut lua_State, ar: *mut lua_Debug)>;
extern "C" {
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_upvalueid(l: *mut lua_State, fidx: c_int, n: c_int) -> *mut c_void;
pub fn lua_upvaluejoin(l: *mut lua_State, fidx1: c_int, n1: c_int, fidx2: c_int, n2: c_int);
pub fn lua_sethook(l: *mut lua_State, func: lua_Hook, mask: c_int, count: c_int);
pub fn lua_gethook(l: *mut lua_State) -> lua_Hook;
pub fn lua_gethookmask(l: *mut lua_State) -> c_int;
pub fn lua_gethookcount(l: *mut lua_State) -> c_int;
}
const LUA_IDSIZE: c_int = 60;
#[repr(C)]
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub struct lua_Debug {
pub event: c_int,
pub name: *const c_char,
pub namewhat: *const c_char,
pub what: *const c_char,
pub source: *const c_char,
pub currentline: c_int,
pub linedefined: c_int,
pub lastlinedefined: c_int,
pub nups: c_uchar,
pub nparams: c_uchar,
pub isvararg: c_char,
pub istailcall: c_char,
pub short_src: [c_char; LUA_IDSIZE as usize],
i_ci: *mut c_void,
}