#![allow(nonstandard_style)] use std::{ffi::*, ptr}; include!(env!("LUAJIT_SYS_BINDGEN")); // #[cfg(all(panic = "abort", feature = "unwind"))] // compile_error!(r#"feature "unwind" cannot be enabled if panic = "abort""#); // #[cfg(all(panic = "unwind", not(feature = "unwind")))] // compile_error!(r#"feature "unwind" must be enabled if panic = "unwind""#); // constants not exposed by lua.h pub const LUA_TPROTO: c_int = LUA_TTHREAD + 1; pub const LUA_TCDATA: c_int = LUA_TTHREAD + 2; // macros not translated by bindgen pub unsafe fn lua_upvalueindex(i: c_int) -> c_int { LUA_GLOBALSINDEX - i } 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_register(L: *mut lua_State, n: *const c_char, f: lua_CFunction) { unsafe { (lua_pushcfunction(L, f), lua_setglobal(L, n)) }; } pub unsafe fn lua_pushcfunction(L: *mut lua_State, f: lua_CFunction) { unsafe { lua_pushcclosure(L, f, 0) } } pub unsafe fn lua_strlen(L: *mut lua_State, i: c_int) -> usize { unsafe { lua_objlen(L, i) } } pub unsafe fn lua_isfunction(L: *mut lua_State, n: c_int) -> c_int { unsafe { (lua_type(L, n) == LUA_TFUNCTION) as c_int } } pub unsafe fn lua_istable(L: *mut lua_State, n: c_int) -> c_int { unsafe { (lua_type(L, n) == LUA_TTABLE) as c_int } } pub unsafe fn lua_islightuserdata(L: *mut lua_State, n: c_int) -> c_int { unsafe { (lua_type(L, n) == LUA_TLIGHTUSERDATA) as c_int } } pub unsafe fn lua_isnil(L: *mut lua_State, n: c_int) -> c_int { unsafe { (lua_type(L, n) == LUA_TNIL) as c_int } } pub unsafe fn lua_isboolean(L: *mut lua_State, n: c_int) -> c_int { unsafe { (lua_type(L, n) == LUA_TBOOLEAN) as c_int } } pub unsafe fn lua_isthread(L: *mut lua_State, n: c_int) -> c_int { unsafe { (lua_type(L, n) == LUA_TTHREAD) as c_int } } pub unsafe fn lua_isnone(L: *mut lua_State, n: c_int) -> c_int { unsafe { (lua_type(L, n) == LUA_TNONE) as c_int } } pub unsafe fn lua_isnoneornil(L: *mut lua_State, n: c_int) -> c_int { unsafe { (lua_type(L, n) <= LUA_TNIL) as c_int } } pub unsafe fn lua_pushliteral(L: *mut lua_State, s: impl AsRef<[u8]>) { unsafe { lua_pushlstring(L, s.as_ref().as_ptr().cast(), s.as_ref().len()) } } pub unsafe fn lua_setglobal(L: *mut lua_State, s: *const c_char) { unsafe { lua_setfield(L, LUA_GLOBALSINDEX, s) } } pub unsafe fn lua_getglobal(L: *mut lua_State, s: *const c_char) { unsafe { lua_getfield(L, LUA_GLOBALSINDEX, s) } } pub unsafe fn lua_tostring(L: *mut lua_State, i: c_int) -> *const c_char { unsafe { lua_tolstring(L, i, ptr::null_mut()) } } pub unsafe fn lua_open() -> *mut lua_State { unsafe { luaL_newstate() } } pub unsafe fn lua_getregistry(L: *mut lua_State) { unsafe { lua_pushvalue(L, LUA_REGISTRYINDEX) } } pub unsafe fn lua_getgccount(L: *mut lua_State) -> c_int { unsafe { lua_gc(L, LUA_GCCOUNT, 0) } }