1#![allow(non_snake_case)]
2#![allow(non_camel_case_types)]
3
4use std::ffi::{c_char, c_double, c_int, c_void};
5use std::marker::{PhantomData, PhantomPinned};
6
7#[repr(C)]
8#[doc(hidden)]
9pub struct lua_State {
10 _data: [u8; 0],
11
12 _marker: PhantomData<(*mut u8, PhantomPinned)>,
16}
17
18pub const LUA_REGISTRYINDEX: c_int = -10000;
20pub const LUA_ENVIRONINDEX: c_int = -10001;
21pub const LUA_GLOBALSINDEX: c_int = -10002;
22
23pub const fn lua_upvalueindex(i: c_int) -> c_int {
24 LUA_GLOBALSINDEX - i
25}
26
27pub const LUA_OK: c_int = 0;
29pub const LUA_ERRRUN: c_int = 2;
30pub const LUA_ERRMEM: c_int = 4;
31pub const LUA_ERRERR: c_int = 5;
32
33pub const LUA_TNONE: c_int = -1;
35pub const LUA_TNIL: c_int = 0;
36pub const LUA_TBOOLEAN: c_int = 1;
37pub const LUA_TLIGHTUSERDATA: c_int = 2;
38pub const LUA_TNUMBER: c_int = 3;
39pub const LUA_TSTRING: c_int = 4;
40pub const LUA_TTABLE: c_int = 5;
41pub const LUA_TFUNCTION: c_int = 6;
42pub const LUA_TUSERDATA: c_int = 7;
43pub const LUA_TTHREAD: c_int = 8;
44
45pub type lua_CFunction = unsafe extern "C" fn(L: *mut lua_State) -> c_int;
47
48pub type lua_Integer = isize;
50
51pub type lua_Number = c_double;
53
54extern "C" {
55 pub fn lua_call(L: *mut lua_State, nargs: c_int, nresults: c_int);
57
58 pub fn lua_createtable(L: *mut lua_State, narr: c_int, nrec: c_int);
70
71 pub fn lua_error(L: *mut lua_State) -> !;
73
74 pub fn lua_getfield(L: *mut lua_State, index: c_int, k: *const c_char);
76
77 pub fn lua_getmetatable(L: *mut lua_State, index: c_int) -> c_int;
79
80 pub fn lua_gettop(L: *mut lua_State) -> c_int;
82
83 pub fn lua_newuserdata(L: *mut lua_State, size: usize) -> *mut c_void;
85
86 pub fn lua_next(L: *mut lua_State, index: c_int) -> c_int;
88
89 pub fn lua_objlen(L: *mut lua_State, index: c_int) -> usize;
91
92 pub fn lua_pcall(
94 L: *mut lua_State,
95 nargs: c_int,
96 nresults: c_int,
97 errorfunc: c_int,
98 ) -> c_int;
99
100 pub fn lua_pushboolean(L: *mut lua_State, n: lua_Integer);
102
103 pub fn lua_pushcclosure(L: *mut lua_State, r#fn: lua_CFunction, n: c_int);
105
106 pub fn lua_pushinteger(L: *mut lua_State, n: lua_Integer);
108
109 pub fn lua_pushlightuserdata(L: *mut lua_State, p: *mut c_void);
111
112 pub fn lua_pushlstring(L: *mut lua_State, s: *const c_char, len: usize);
114
115 pub fn lua_pushnil(L: *mut lua_State);
117
118 pub fn lua_pushnumber(L: *mut lua_State, n: lua_Number);
120
121 pub fn lua_pushstring(L: *mut lua_State, s: *const c_char);
123
124 pub fn lua_pushvalue(L: *mut lua_State, index: c_int);
126
127 pub fn lua_rawgeti(L: *mut lua_State, index: c_int, n: c_int);
129
130 pub fn lua_rawset(L: *mut lua_State, index: c_int);
132
133 pub fn lua_rawseti(L: *mut lua_State, index: c_int, n: c_int);
135
136 pub fn lua_settop(L: *mut lua_State, index: c_int);
138
139 pub fn lua_toboolean(L: *mut lua_State, index: c_int) -> c_int;
141
142 pub fn lua_tointeger(L: *mut lua_State, index: c_int) -> lua_Integer;
144
145 pub fn lua_tolstring(
147 L: *mut lua_State,
148 index: c_int,
149 len: *mut usize,
150 ) -> *const c_char;
151
152 pub fn lua_tonumber(L: *mut lua_State, index: c_int) -> lua_Number;
154
155 pub fn lua_touserdata(L: *mut lua_State, index: c_int) -> *mut c_void;
157
158 pub fn lua_type(L: *mut lua_State, index: c_int) -> c_int;
160
161 pub fn lua_typename(L: *mut lua_State, tp: c_int) -> *const c_char;
163
164 pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> !;
168
169 pub fn luaL_ref(L: *mut lua_State, t: c_int) -> c_int;
171
172 pub fn luaL_unref(L: *mut lua_State, t: c_int, r#ref: c_int);
174}
175
176pub unsafe fn lua_getglobal(L: *mut lua_State, name: *const c_char) {
178 lua_getfield(L, LUA_GLOBALSINDEX, name)
179}
180
181pub unsafe fn lua_pop(L: *mut lua_State, n: c_int) {
183 lua_settop(L, -n - 1)
184}
185
186pub unsafe fn lua_pushcfunction(L: *mut lua_State, r#fn: lua_CFunction) {
188 lua_pushcclosure(L, r#fn, 0)
189}
190
191pub unsafe fn lua_tostring(L: *mut lua_State, index: c_int) -> *const c_char {
193 lua_tolstring(L, index, std::ptr::null_mut())
194}
195
196pub unsafe fn luaL_typename(L: *mut lua_State, index: c_int) -> *const c_char {
198 lua_typename(L, lua_type(L, index))
199}