#![allow(non_camel_case_types)]
#![allow(clippy::missing_safety_doc)]
use std::os::raw::{c_char, c_double, c_int, c_void};
use std::ptr::null_mut;
pub const LUA_REGISTRYINDEX: c_int = -10000;
pub const LUA_ENVIRONINDEX: c_int = -10001;
pub const LUA_GLOBALSINDEX: c_int = -10002;
pub fn is_relative_index(index: c_int) -> bool {
index < 0 && index > LUA_REGISTRYINDEX
}
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_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_TCDATA: c_int = 10;
pub const LUA_MINSTACK: c_int = 20;
pub const LUA_NOREF: c_int = -2;
pub const LUA_REFNIL: c_int = -1;
pub const LUA_MULTRET: c_int = -1;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct lua_State {
pub _unused: [u8; 0],
}
#[repr(C)]
pub struct luaL_Reg {
pub name: *const c_char,
pub func: lua_CFunction,
}
pub type lua_Number = libc::c_double;
pub type lua_Integer = libc::ptrdiff_t;
pub type lua_CFunction = unsafe extern "C" fn(l: *mut lua_State) -> c_int;
pub type lua_Alloc = extern "C" fn(
ud: *mut libc::c_void,
ptr: *mut libc::c_void,
osize: libc::size_t,
nsize: libc::size_t,
) -> *mut libc::c_void;
pub type lua_Reader = extern "C" fn(
L: *mut lua_State,
data: *mut libc::c_void,
size: *mut libc::size_t,
) -> *const libc::c_char;
pub type lua_Writer = extern "C" fn(
L: *mut lua_State,
p: *const libc::c_void,
sz: libc::size_t,
ud: *mut libc::c_void,
) -> libc::c_int;
extern "C" {
pub fn lua_newstate(f: lua_Alloc, ud: *mut libc::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_gettop(l: *mut lua_State) -> c_int;
pub fn lua_settop(l: *mut lua_State, index: c_int);
pub fn lua_pushboolean(l: *mut lua_State, n: c_int);
pub fn lua_pushlstring(l: *mut lua_State, s: *const libc::c_char, l: libc::size_t);
pub fn lua_pushstring(l: *mut lua_State, s: *const c_char) -> *const c_char;
pub fn lua_pushinteger(l: *mut lua_State, n: isize);
pub fn lua_pushnumber(l: *mut lua_State, n: c_double);
pub fn lua_pushcclosure(l: *mut lua_State, fun: lua_CFunction, n: c_int);
pub fn lua_pushnil(l: *mut lua_State);
pub fn lua_pushvalue(l: *mut lua_State, index: c_int);
pub fn lua_tointeger(l: *mut lua_State, index: c_int) -> isize;
pub fn lua_toboolean(l: *mut lua_State, index: c_int) -> c_int;
pub fn lua_tolstring(l: *mut lua_State, index: c_int, len: *mut usize) -> *const c_char;
pub fn lua_touserdata(l: *mut lua_State, index: c_int) -> *mut libc::c_void;
pub fn lua_setfield(l: *mut lua_State, index: c_int, k: *const c_char);
pub fn lua_getfield(l: *mut lua_State, index: c_int, k: *const c_char);
pub fn lua_createtable(l: *mut lua_State, narr: c_int, nrec: c_int);
pub fn lua_newuserdata(l: *mut lua_State, sz: libc::size_t) -> *mut libc::c_void;
pub fn lua_pushlightuserdata(l: *mut lua_State, ud: *mut c_void);
pub fn lua_gettable(l: *mut lua_State, index: c_int);
pub fn lua_rawget(l: *mut lua_State, index: c_int);
pub fn lua_rawgeti(l: *mut lua_State, index: c_int, n: c_int);
pub fn lua_settable(l: *mut lua_State, index: c_int);
pub fn lua_rawset(l: *mut lua_State, index: c_int);
pub fn lua_rawseti(l: *mut lua_State, index: c_int, n: c_int);
pub fn lua_type(state: *mut lua_State, index: c_int) -> c_int;
pub fn lua_typename(state: *mut lua_State, tp: c_int) -> *mut c_char;
pub fn lua_setmetatable(l: *mut lua_State, index: c_int) -> c_int;
pub fn lua_getmetatable(l: *mut lua_State, index: c_int) -> c_int;
pub fn lua_tonumber(l: *mut lua_State, index: c_int) -> lua_Number;
pub fn lua_tonumberx(l: *mut lua_State, index: c_int, isnum: *mut c_int) -> lua_Number;
pub fn lua_tointegerx(l: *mut lua_State, index: c_int, isnum: *mut c_int) -> lua_Integer;
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 libc::c_void,
chunkname: *const libc::c_char,
) -> c_int;
pub fn lua_loadx(
l: *mut lua_State,
reader: lua_Reader,
dt: *mut libc::c_void,
chunkname: *const libc::c_char,
mode: *const libc::c_char,
) -> c_int;
pub fn lua_dump(l: *mut lua_State, writer: lua_Writer, data: *mut libc::c_void) -> 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_len(l: *mut lua_State, index: c_int);
pub fn lua_insert(l: *mut lua_State, index: c_int);
pub fn lua_remove(l: *mut lua_State, index: c_int);
pub fn luaopen_base(l: *mut lua_State);
pub fn luaopen_bit(l: *mut lua_State);
pub fn luaopen_debug(l: *mut lua_State);
pub fn luaopen_io(l: *mut lua_State);
pub fn luaopen_math(l: *mut lua_State);
pub fn luaopen_os(l: *mut lua_State);
pub fn luaopen_package(l: *mut lua_State);
pub fn luaopen_string(l: *mut lua_State);
pub fn luaopen_table(l: *mut lua_State);
pub fn luaL_newstate() -> *mut lua_State;
pub fn luaL_register(l: *mut lua_State, libname: *const c_char, lr: *const luaL_Reg);
pub fn luaL_error(l: *mut lua_State, fmt: *const c_char, ...) -> c_int;
pub fn luaL_openlibs(L: *mut lua_State);
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: c_int);
}
#[inline(always)]
pub unsafe fn lua_getglobal(state: *mut lua_State, name: *const c_char) {
lua_getfield(state, LUA_GLOBALSINDEX, name);
}
#[inline(always)]
pub unsafe fn lua_setglobal(state: *mut lua_State, name: *const c_char) {
lua_setfield(state, LUA_GLOBALSINDEX, name);
}
#[inline(always)]
pub unsafe fn lua_pop(state: *mut lua_State, n: c_int) {
lua_settop(state, -n - 1);
}
#[inline(always)]
pub unsafe fn lua_pushcfunction(state: *mut lua_State, f: lua_CFunction) {
lua_pushcclosure(state, f, 0);
}
#[inline(always)]
pub unsafe fn lua_tostring(state: *mut lua_State, i: c_int) -> *const c_char {
lua_tolstring(state, i, null_mut())
}
#[inline(always)]
pub unsafe fn lua_newtable(state: *mut lua_State) {
lua_createtable(state, 0, 0);
}
#[inline(always)]
pub fn lua_upvalueindex(i: c_int) -> c_int {
LUA_GLOBALSINDEX - i
}
#[inline(always)]
pub unsafe fn lua_isfunction(state: *mut lua_State, index: c_int) -> bool {
lua_type(state, index) == LUA_TFUNCTION
}
#[inline(always)]
pub unsafe fn lua_istable(state: *mut lua_State, index: c_int) -> bool {
lua_type(state, index) == LUA_TTABLE
}
#[inline(always)]
pub unsafe fn lua_islightuserdata(state: *mut lua_State, index: c_int) -> bool {
lua_type(state, index) == LUA_TLIGHTUSERDATA
}
#[inline(always)]
pub unsafe fn lua_isnil(state: *mut lua_State, index: c_int) -> bool {
lua_type(state, index) == LUA_TNIL
}
#[inline(always)]
pub unsafe fn lua_isboolean(state: *mut lua_State, index: c_int) -> bool {
lua_type(state, index) == LUA_TBOOLEAN
}
#[inline(always)]
pub unsafe fn lua_isthread(state: *mut lua_State, index: c_int) -> bool {
lua_type(state, index) == LUA_TTHREAD
}
#[allow(non_snake_case)]
#[inline(always)]
pub unsafe fn luaL_iscdata(state: *mut lua_State, index: c_int) -> bool {
lua_type(state, index) == LUA_TCDATA
}
#[inline(always)]
pub unsafe fn lua_isnumber(state: *mut lua_State, index: c_int) -> bool {
lua_type(state, index) == LUA_TNUMBER
}
#[inline(always)]
pub unsafe fn lua_isnone(state: *mut lua_State, index: c_int) -> bool {
lua_type(state, index) == LUA_TNONE
}
#[inline(always)]
pub unsafe fn lua_isnoneornil(state: *mut lua_State, index: c_int) -> bool {
lua_type(state, index) <= 0
}
#[inline(always)]
pub unsafe fn lua_pushglobaltable(state: *mut lua_State) {
lua_pushvalue(state, LUA_GLOBALSINDEX)
}
pub type CTypeID = u32;
pub const CTID_NONE: CTypeID = 0;
pub const CTID_VOID: CTypeID = 1;
pub const CTID_CVOID: CTypeID = 2;
pub const CTID_BOOL: CTypeID = 3;
pub const CTID_CCHAR: CTypeID = 4;
pub const CTID_INT8: CTypeID = 5;
pub const CTID_UINT8: CTypeID = 6;
pub const CTID_INT16: CTypeID = 7;
pub const CTID_UINT16: CTypeID = 8;
pub const CTID_INT32: CTypeID = 9;
pub const CTID_UINT32: CTypeID = 10;
pub const CTID_INT64: CTypeID = 11;
pub const CTID_UINT64: CTypeID = 12;
pub const CTID_FLOAT: CTypeID = 13;
pub const CTID_DOUBLE: CTypeID = 14;
pub const CTID_COMPLEX_FLOAT: CTypeID = 15;
pub const CTID_COMPLEX_DOUBLE: CTypeID = 16;
pub const CTID_P_VOID: CTypeID = 17;
pub const CTID_P_CVOID: CTypeID = 18;
pub const CTID_P_CCHAR: CTypeID = 19;
pub const CTID_A_CCHAR: CTypeID = 20;
pub const CTID_CTYPEID: CTypeID = 21;
extern "C" {
pub fn luaL_pushuint64(l: *mut lua_State, val: u64);
pub fn luaL_pushint64(l: *mut lua_State, val: i64);
pub fn luaL_touint64(l: *mut lua_State, idx: c_int) -> u64;
pub fn luaL_toint64(l: *mut lua_State, idx: c_int) -> i64;
pub fn luaL_pushcdata(l: *mut lua_State, ctypeid: CTypeID) -> *mut c_void;
pub fn luaL_checkcdata(l: *mut lua_State, idx: c_int, ctypeid: *mut CTypeID) -> *mut c_void;
pub fn luaL_ctypeid(l: *mut lua_State, ctypename: *const c_char) -> CTypeID;
pub fn luaL_iscallable(l: *mut lua_State, index: i32) -> i32;
pub fn luaL_getmetafield(l: *mut lua_State, index: i32, field: *const c_char) -> i32;
}
#[inline(always)]
#[allow(non_snake_case)]
pub unsafe fn luaL_hasmetafield(l: *mut lua_State, index: i32, field: *const c_char) -> bool {
luaL_getmetafield(l, index, field) != 0 && {
lua_pop(l, 1);
true
}
}
extern "C" {
pub fn luaT_tolstring(l: *mut lua_State, idx: c_int, len: *mut usize) -> *const c_char;
}