1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2019-2021 A. Orlenko
4 // Copyright (c) 2014 J.C. Moyer
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 
24 //! Contains definitions from `lua.h`.
25 
26 use std::marker::{PhantomData, PhantomPinned};
27 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
28 use std::os::raw::c_uchar;
29 use std::os::raw::{c_char, c_int, c_void};
30 #[cfg(feature = "lua54")]
31 use std::os::raw::{c_uint, c_ushort};
32 use std::ptr;
33 
34 use super::luaconf;
35 
36 #[cfg(any(feature = "lua51", feature = "luajit"))]
37 pub use super::glue::{LUA_ENVIRONINDEX, LUA_GLOBALSINDEX};
38 pub use super::glue::{LUA_REGISTRYINDEX, LUA_VERSION_NUM};
39 
40 #[cfg(not(feature = "luajit"))]
41 pub const LUA_SIGNATURE: &[u8] = b"\x1bLua";
42 #[cfg(feature = "luajit")]
43 pub const LUA_SIGNATURE: &[u8] = b"\x1bLJ";
44 
45 // option for multiple returns in 'lua_pcall' and 'lua_call'
46 pub const LUA_MULTRET: c_int = -1;
47 
48 #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
49 pub use super::compat53::{
50     lua_dump, lua_getextraspace, lua_getfield, lua_geti, lua_gettable, lua_getuservalue,
51     lua_isinteger, lua_pushlstring, lua_rawget, lua_rawgeti, lua_rawgetp, lua_rotate, lua_seti,
52     lua_stringtonumber, lua_tointegerx,
53 };
54 
55 #[cfg(any(feature = "lua51", feature = "luajit"))]
56 pub use super::compat53::{
57     lua_absindex, lua_arith, lua_compare, lua_copy, lua_len, lua_pushglobaltable, lua_pushstring,
58     lua_rawlen, lua_rawsetp, lua_resume as lua_resume_53, lua_setuservalue, lua_tonumberx,
59     lua_upvalueindex,
60 };
61 
62 #[cfg(feature = "lua52")]
63 pub use super::compat53::lua_getglobal;
64 
65 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
66 #[inline(always)]
lua_upvalueindex(i: c_int) -> c_int67 pub const fn lua_upvalueindex(i: c_int) -> c_int {
68     LUA_REGISTRYINDEX - i
69 }
70 
71 // thread status
72 pub const LUA_OK: c_int = 0;
73 pub const LUA_YIELD: c_int = 1;
74 pub const LUA_ERRRUN: c_int = 2;
75 pub const LUA_ERRSYNTAX: c_int = 3;
76 pub const LUA_ERRMEM: c_int = 4;
77 #[cfg(any(feature = "lua53", feature = "lua52"))]
78 pub const LUA_ERRGCMM: c_int = 5;
79 #[cfg(any(feature = "lua54", feature = "lua51", feature = "luajit"))]
80 pub const LUA_ERRERR: c_int = 5;
81 #[cfg(any(feature = "lua53", feature = "lua52"))]
82 pub const LUA_ERRERR: c_int = 6;
83 
84 /// A raw Lua state associated with a thread.
85 #[repr(C)]
86 pub struct lua_State {
87     _data: [u8; 0],
88     _marker: PhantomData<(*mut u8, PhantomPinned)>,
89 }
90 
91 // basic types
92 pub const LUA_TNONE: c_int = -1;
93 
94 pub const LUA_TNIL: c_int = 0;
95 pub const LUA_TBOOLEAN: c_int = 1;
96 pub const LUA_TLIGHTUSERDATA: c_int = 2;
97 pub const LUA_TNUMBER: c_int = 3;
98 pub const LUA_TSTRING: c_int = 4;
99 pub const LUA_TTABLE: c_int = 5;
100 pub const LUA_TFUNCTION: c_int = 6;
101 pub const LUA_TUSERDATA: c_int = 7;
102 pub const LUA_TTHREAD: c_int = 8;
103 
104 #[cfg(feature = "lua54")]
105 pub const LUA_NUMTYPES: c_int = 9;
106 #[cfg(any(feature = "lua53", feature = "lua52"))]
107 pub const LUA_NUMTAGS: c_int = 9;
108 
109 // minimum stack available to a C function
110 pub const LUA_MINSTACK: c_int = 20;
111 
112 // predefined values in the registry
113 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
114 pub const LUA_RIDX_MAINTHREAD: lua_Integer = 1;
115 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
116 pub const LUA_RIDX_GLOBALS: lua_Integer = 2;
117 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
118 pub const LUA_RIDX_LAST: lua_Integer = LUA_RIDX_GLOBALS;
119 
120 // I believe `luaL_traceback` < 5.4 requires this much free stack to not error.
121 // 5.4 uses `luaL_Buffer`
122 pub const LUA_TRACEBACK_STACK: c_int = 11;
123 
124 /// A Lua number, usually equivalent to `f64`.
125 pub type lua_Number = luaconf::LUA_NUMBER;
126 
127 /// A Lua integer, usually equivalent to `i64`.
128 pub type lua_Integer = luaconf::LUA_INTEGER;
129 
130 /// A Lua unsigned integer, usually equivalent to `u64`.
131 pub type lua_Unsigned = luaconf::LUA_UNSIGNED;
132 
133 // type for continuation-function contexts
134 #[cfg(any(feature = "lua54", feature = "lua53"))]
135 pub type lua_KContext = luaconf::LUA_KCONTEXT;
136 
137 /// Type for native C functions that can be passed to Lua.
138 pub type lua_CFunction = unsafe extern "C" fn(L: *mut lua_State) -> c_int;
139 
140 // Type for continuation functions
141 #[cfg(any(feature = "lua54", feature = "lua53"))]
142 pub type lua_KFunction =
143     unsafe extern "C" fn(L: *mut lua_State, status: c_int, ctx: lua_KContext) -> c_int;
144 
145 // Type for functions that read/write blocks when loading/dumping Lua chunks
146 pub type lua_Reader =
147     unsafe extern "C" fn(L: *mut lua_State, ud: *mut c_void, sz: *mut usize) -> *const c_char;
148 pub type lua_Writer =
149     unsafe extern "C" fn(L: *mut lua_State, p: *const c_void, sz: usize, ud: *mut c_void) -> c_int;
150 
151 // Type for memory-allocation functions.
152 pub type lua_Alloc = unsafe extern "C" fn(
153     ud: *mut c_void,
154     ptr: *mut c_void,
155     osize: usize,
156     nsize: usize,
157 ) -> *mut c_void;
158 
159 // Type for warning functions
160 #[cfg(feature = "lua54")]
161 pub type lua_WarnFunction =
162     unsafe extern "C" fn(ud: *mut c_void, msg: *const c_char, tocont: c_int);
163 
164 extern "C" {
165     // state manipulation
lua_newstate(f: lua_Alloc, ud: *mut c_void) -> *mut lua_State166     pub fn lua_newstate(f: lua_Alloc, ud: *mut c_void) -> *mut lua_State;
lua_close(L: *mut lua_State)167     pub fn lua_close(L: *mut lua_State);
lua_newthread(L: *mut lua_State) -> *mut lua_State168     pub fn lua_newthread(L: *mut lua_State) -> *mut lua_State;
169 
170     #[cfg(feature = "lua54")]
171     #[link_name = "lua_resetthread"]
lua_resetthread_54(L: *mut lua_State) -> c_int172     pub fn lua_resetthread_54(L: *mut lua_State) -> c_int;
173     #[cfg(all(feature = "luajit", feature = "vendored"))]
174     #[link_name = "lua_resetthread"]
lua_resetthread_jit(L: *mut lua_State, th: *mut lua_State)175     pub fn lua_resetthread_jit(L: *mut lua_State, th: *mut lua_State);
176 
lua_atpanic(L: *mut lua_State, panicf: lua_CFunction) -> lua_CFunction177     pub fn lua_atpanic(L: *mut lua_State, panicf: lua_CFunction) -> lua_CFunction;
178 
179     #[cfg(feature = "lua54")]
lua_version(L: *mut lua_State) -> lua_Number180     pub fn lua_version(L: *mut lua_State) -> lua_Number;
181     #[cfg(feature = "lua53")]
lua_version(L: *mut lua_State) -> *const lua_Number182     pub fn lua_version(L: *mut lua_State) -> *const lua_Number;
183 
184     // basic stack manipulation
185     #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
lua_absindex(L: *mut lua_State, idx: c_int) -> c_int186     pub fn lua_absindex(L: *mut lua_State, idx: c_int) -> c_int;
lua_gettop(L: *mut lua_State) -> c_int187     pub fn lua_gettop(L: *mut lua_State) -> c_int;
lua_settop(L: *mut lua_State, idx: c_int)188     pub fn lua_settop(L: *mut lua_State, idx: c_int);
lua_pushvalue(L: *mut lua_State, idx: c_int)189     pub fn lua_pushvalue(L: *mut lua_State, idx: c_int);
190     #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
lua_remove(L: *mut lua_State, idx: c_int)191     pub fn lua_remove(L: *mut lua_State, idx: c_int);
192     #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
lua_insert(L: *mut lua_State, idx: c_int)193     pub fn lua_insert(L: *mut lua_State, idx: c_int);
194     #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
lua_replace(L: *mut lua_State, idx: c_int)195     pub fn lua_replace(L: *mut lua_State, idx: c_int);
196     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_rotate(L: *mut lua_State, idx: c_int, n: c_int)197     pub fn lua_rotate(L: *mut lua_State, idx: c_int, n: c_int);
198     #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
lua_copy(L: *mut lua_State, fromidx: c_int, toidx: c_int)199     pub fn lua_copy(L: *mut lua_State, fromidx: c_int, toidx: c_int);
lua_checkstack(L: *mut lua_State, sz: c_int) -> c_int200     pub fn lua_checkstack(L: *mut lua_State, sz: c_int) -> c_int;
201 
lua_xmove(from: *mut lua_State, to: *mut lua_State, n: c_int)202     pub fn lua_xmove(from: *mut lua_State, to: *mut lua_State, n: c_int);
203 
204     // access functions (stack -> C)
lua_isnumber(L: *mut lua_State, idx: c_int) -> c_int205     pub fn lua_isnumber(L: *mut lua_State, idx: c_int) -> c_int;
lua_isstring(L: *mut lua_State, idx: c_int) -> c_int206     pub fn lua_isstring(L: *mut lua_State, idx: c_int) -> c_int;
lua_iscfunction(L: *mut lua_State, idx: c_int) -> c_int207     pub fn lua_iscfunction(L: *mut lua_State, idx: c_int) -> c_int;
208     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_isinteger(L: *mut lua_State, idx: c_int) -> c_int209     pub fn lua_isinteger(L: *mut lua_State, idx: c_int) -> c_int;
lua_isuserdata(L: *mut lua_State, idx: c_int) -> c_int210     pub fn lua_isuserdata(L: *mut lua_State, idx: c_int) -> c_int;
lua_type(L: *mut lua_State, idx: c_int) -> c_int211     pub fn lua_type(L: *mut lua_State, idx: c_int) -> c_int;
lua_typename(L: *mut lua_State, tp: c_int) -> *const c_char212     pub fn lua_typename(L: *mut lua_State, tp: c_int) -> *const c_char;
213 
214     #[cfg(any(feature = "lua51", feature = "luajit"))]
lua_tonumber(L: *mut lua_State, idx: c_int) -> lua_Number215     pub fn lua_tonumber(L: *mut lua_State, idx: c_int) -> lua_Number;
216     #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
lua_tonumberx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Number217     pub fn lua_tonumberx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Number;
218     #[cfg(any(feature = "lua51", feature = "luajit"))]
lua_tointeger(L: *mut lua_State, idx: c_int) -> lua_Integer219     pub fn lua_tointeger(L: *mut lua_State, idx: c_int) -> lua_Integer;
220     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_tointegerx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Integer221     pub fn lua_tointegerx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Integer;
lua_toboolean(L: *mut lua_State, idx: c_int) -> c_int222     pub fn lua_toboolean(L: *mut lua_State, idx: c_int) -> c_int;
lua_tolstring(L: *mut lua_State, idx: c_int, len: *mut usize) -> *const c_char223     pub fn lua_tolstring(L: *mut lua_State, idx: c_int, len: *mut usize) -> *const c_char;
224     #[cfg(any(feature = "lua51", feature = "luajit"))]
lua_objlen(L: *mut lua_State, idx: c_int) -> usize225     pub fn lua_objlen(L: *mut lua_State, idx: c_int) -> usize;
226     #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
lua_rawlen(L: *mut lua_State, idx: c_int) -> usize227     pub fn lua_rawlen(L: *mut lua_State, idx: c_int) -> usize;
lua_tocfunction(L: *mut lua_State, idx: c_int) -> lua_CFunction228     pub fn lua_tocfunction(L: *mut lua_State, idx: c_int) -> lua_CFunction;
lua_touserdata(L: *mut lua_State, idx: c_int) -> *mut c_void229     pub fn lua_touserdata(L: *mut lua_State, idx: c_int) -> *mut c_void;
lua_tothread(L: *mut lua_State, idx: c_int) -> *mut lua_State230     pub fn lua_tothread(L: *mut lua_State, idx: c_int) -> *mut lua_State;
lua_topointer(L: *mut lua_State, idx: c_int) -> *const c_void231     pub fn lua_topointer(L: *mut lua_State, idx: c_int) -> *const c_void;
232 }
233 
234 #[cfg(any(feature = "lua54", all(feature = "luajit", feature = "vendored")))]
lua_resetthread(_L: *mut lua_State, th: *mut lua_State) -> c_int235 pub unsafe fn lua_resetthread(_L: *mut lua_State, th: *mut lua_State) -> c_int {
236     #[cfg(all(feature = "luajit", feature = "vendored"))]
237     {
238         lua_resetthread_jit(_L, th);
239         LUA_OK
240     }
241     #[cfg(feature = "lua54")]
242     lua_resetthread_54(th)
243 }
244 
245 // Comparison and arithmetic functions
246 pub const LUA_OPADD: c_int = 0;
247 pub const LUA_OPSUB: c_int = 1;
248 pub const LUA_OPMUL: c_int = 2;
249 
250 #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
251 pub const LUA_OPDIV: c_int = 3;
252 #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
253 pub const LUA_OPMOD: c_int = 4;
254 #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
255 pub const LUA_OPPOW: c_int = 5;
256 #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
257 pub const LUA_OPUNM: c_int = 6;
258 
259 #[cfg(any(feature = "lua54", feature = "lua53"))]
260 pub const LUA_OPMOD: c_int = 3;
261 #[cfg(any(feature = "lua54", feature = "lua53"))]
262 pub const LUA_OPPOW: c_int = 4;
263 #[cfg(any(feature = "lua54", feature = "lua53"))]
264 pub const LUA_OPDIV: c_int = 5;
265 #[cfg(any(feature = "lua54", feature = "lua53"))]
266 pub const LUA_OPIDIV: c_int = 6;
267 #[cfg(any(feature = "lua54", feature = "lua53"))]
268 pub const LUA_OPBAND: c_int = 7;
269 #[cfg(any(feature = "lua54", feature = "lua53"))]
270 pub const LUA_OPBOR: c_int = 8;
271 #[cfg(any(feature = "lua54", feature = "lua53"))]
272 pub const LUA_OPBXOR: c_int = 9;
273 #[cfg(any(feature = "lua54", feature = "lua53"))]
274 pub const LUA_OPSHL: c_int = 10;
275 #[cfg(any(feature = "lua54", feature = "lua53"))]
276 pub const LUA_OPSHR: c_int = 11;
277 #[cfg(any(feature = "lua54", feature = "lua53"))]
278 pub const LUA_OPUNM: c_int = 12;
279 #[cfg(any(feature = "lua54", feature = "lua53"))]
280 pub const LUA_OPBNOT: c_int = 13;
281 
282 extern "C" {
283     #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
lua_arith(L: *mut lua_State, op: c_int)284     pub fn lua_arith(L: *mut lua_State, op: c_int);
285 }
286 
287 pub const LUA_OPEQ: c_int = 0;
288 pub const LUA_OPLT: c_int = 1;
289 pub const LUA_OPLE: c_int = 2;
290 
291 extern "C" {
292     #[cfg(any(feature = "lua51", feature = "luajit"))]
lua_equal(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int293     pub fn lua_equal(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int;
lua_rawequal(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int294     pub fn lua_rawequal(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int;
295     #[cfg(any(feature = "lua51", feature = "luajit"))]
lua_lessthan(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int296     pub fn lua_lessthan(L: *mut lua_State, idx1: c_int, idx2: c_int) -> c_int;
297     #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
lua_compare(L: *mut lua_State, idx1: c_int, idx2: c_int, op: c_int) -> c_int298     pub fn lua_compare(L: *mut lua_State, idx1: c_int, idx2: c_int, op: c_int) -> c_int;
299 }
300 
301 // push functions (C -> stack)
302 extern "C" {
lua_pushnil(L: *mut lua_State)303     pub fn lua_pushnil(L: *mut lua_State);
lua_pushnumber(L: *mut lua_State, n: lua_Number)304     pub fn lua_pushnumber(L: *mut lua_State, n: lua_Number);
lua_pushinteger(L: *mut lua_State, n: lua_Integer)305     pub fn lua_pushinteger(L: *mut lua_State, n: lua_Integer);
306 
307     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_pushlstring(L: *mut lua_State, s: *const c_char, l: usize) -> *const c_char308     pub fn lua_pushlstring(L: *mut lua_State, s: *const c_char, l: usize) -> *const c_char;
309     #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
310     #[link_name = "lua_pushlstring"]
lua_pushlstring_old(L: *mut lua_State, s: *const c_char, l: usize) -> *const c_char311     pub fn lua_pushlstring_old(L: *mut lua_State, s: *const c_char, l: usize) -> *const c_char;
312 
313     #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
lua_pushstring(L: *mut lua_State, s: *const c_char) -> *const c_char314     pub fn lua_pushstring(L: *mut lua_State, s: *const c_char) -> *const c_char;
315     #[cfg(any(feature = "lua51", feature = "luajit"))]
316     #[link_name = "lua_pushstring"]
lua_pushstring_old(L: *mut lua_State, s: *const c_char) -> *const c_char317     pub fn lua_pushstring_old(L: *mut lua_State, s: *const c_char) -> *const c_char;
318 
319     // TODO: omitted:
320     // lua_pushvfstring
lua_pushfstring(L: *mut lua_State, fmt: *const c_char, ...) -> *const c_char321     pub fn lua_pushfstring(L: *mut lua_State, fmt: *const c_char, ...) -> *const c_char;
lua_pushcclosure(L: *mut lua_State, f: lua_CFunction, n: c_int)322     pub fn lua_pushcclosure(L: *mut lua_State, f: lua_CFunction, n: c_int);
lua_pushboolean(L: *mut lua_State, b: c_int)323     pub fn lua_pushboolean(L: *mut lua_State, b: c_int);
lua_pushlightuserdata(L: *mut lua_State, p: *mut c_void)324     pub fn lua_pushlightuserdata(L: *mut lua_State, p: *mut c_void);
lua_pushthread(L: *mut lua_State) -> c_int325     pub fn lua_pushthread(L: *mut lua_State) -> c_int;
326 }
327 
328 // get functions (Lua -> stack)
329 extern "C" {
330     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_getglobal(L: *mut lua_State, var: *const c_char) -> c_int331     pub fn lua_getglobal(L: *mut lua_State, var: *const c_char) -> c_int;
332     #[cfg(feature = "lua52")]
333     #[link_name = "lua_getglobal"]
lua_getglobal_old(L: *mut lua_State, var: *const c_char)334     pub fn lua_getglobal_old(L: *mut lua_State, var: *const c_char);
335 
336     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_gettable(L: *mut lua_State, idx: c_int) -> c_int337     pub fn lua_gettable(L: *mut lua_State, idx: c_int) -> c_int;
338     #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
339     #[link_name = "lua_gettable"]
lua_gettable_old(L: *mut lua_State, idx: c_int)340     pub fn lua_gettable_old(L: *mut lua_State, idx: c_int);
341 
342     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_getfield(L: *mut lua_State, idx: c_int, k: *const c_char) -> c_int343     pub fn lua_getfield(L: *mut lua_State, idx: c_int, k: *const c_char) -> c_int;
344     #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
345     #[link_name = "lua_getfield"]
lua_getfield_old(L: *mut lua_State, idx: c_int, k: *const c_char)346     pub fn lua_getfield_old(L: *mut lua_State, idx: c_int, k: *const c_char);
347 
348     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_geti(L: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int349     pub fn lua_geti(L: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int;
350 
351     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_rawget(L: *mut lua_State, idx: c_int) -> c_int352     pub fn lua_rawget(L: *mut lua_State, idx: c_int) -> c_int;
353     #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
354     #[link_name = "lua_rawget"]
lua_rawget_old(L: *mut lua_State, idx: c_int)355     pub fn lua_rawget_old(L: *mut lua_State, idx: c_int);
356 
357     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_rawgeti(L: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int358     pub fn lua_rawgeti(L: *mut lua_State, idx: c_int, n: lua_Integer) -> c_int;
359     #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
360     #[link_name = "lua_rawgeti"]
lua_rawgeti_old(L: *mut lua_State, idx: c_int, n: lua_Integer)361     pub fn lua_rawgeti_old(L: *mut lua_State, idx: c_int, n: lua_Integer);
362 
363     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_rawgetp(L: *mut lua_State, idx: c_int, p: *const c_void) -> c_int364     pub fn lua_rawgetp(L: *mut lua_State, idx: c_int, p: *const c_void) -> c_int;
365     #[cfg(feature = "lua52")]
366     #[link_name = "lua_rawgetp"]
lua_rawgetp_old(L: *mut lua_State, idx: c_int, p: *const c_void)367     pub fn lua_rawgetp_old(L: *mut lua_State, idx: c_int, p: *const c_void);
368 
lua_createtable(L: *mut lua_State, narr: c_int, nrec: c_int)369     pub fn lua_createtable(L: *mut lua_State, narr: c_int, nrec: c_int);
370     #[cfg(feature = "lua54")]
lua_newuserdatauv(L: *mut lua_State, sz: usize, nuvalue: c_int) -> *mut c_void371     pub fn lua_newuserdatauv(L: *mut lua_State, sz: usize, nuvalue: c_int) -> *mut c_void;
372     #[cfg(any(
373         feature = "lua53",
374         feature = "lua52",
375         feature = "lua51",
376         feature = "luajit"
377     ))]
lua_newuserdata(L: *mut lua_State, sz: usize) -> *mut c_void378     pub fn lua_newuserdata(L: *mut lua_State, sz: usize) -> *mut c_void;
lua_getmetatable(L: *mut lua_State, objindex: c_int) -> c_int379     pub fn lua_getmetatable(L: *mut lua_State, objindex: c_int) -> c_int;
380 
381     #[cfg(feature = "lua54")]
lua_getiuservalue(L: *mut lua_State, idx: c_int, n: c_int) -> c_int382     pub fn lua_getiuservalue(L: *mut lua_State, idx: c_int, n: c_int) -> c_int;
383     #[cfg(feature = "lua53")]
lua_getuservalue(L: *mut lua_State, idx: c_int) -> c_int384     pub fn lua_getuservalue(L: *mut lua_State, idx: c_int) -> c_int;
385     #[cfg(feature = "lua52")]
386     #[link_name = "lua_getuservalue"]
lua_getuservalue_old(L: *mut lua_State, idx: c_int)387     pub fn lua_getuservalue_old(L: *mut lua_State, idx: c_int);
388     #[cfg(any(feature = "lua51", feature = "luajit"))]
lua_getfenv(L: *mut lua_State, idx: c_int)389     pub fn lua_getfenv(L: *mut lua_State, idx: c_int);
390 }
391 
392 #[cfg(feature = "lua54")]
393 #[inline(always)]
lua_newuserdata(L: *mut lua_State, sz: usize) -> *mut c_void394 pub unsafe fn lua_newuserdata(L: *mut lua_State, sz: usize) -> *mut c_void {
395     lua_newuserdatauv(L, sz, 1)
396 }
397 
398 #[cfg(feature = "lua54")]
399 #[inline(always)]
lua_getuservalue(L: *mut lua_State, idx: c_int) -> c_int400 pub unsafe fn lua_getuservalue(L: *mut lua_State, idx: c_int) -> c_int {
401     lua_getiuservalue(L, idx, 1)
402 }
403 
404 // set functions (stack -> Lua)
405 extern "C" {
406     #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
lua_setglobal(L: *mut lua_State, var: *const c_char)407     pub fn lua_setglobal(L: *mut lua_State, var: *const c_char);
lua_settable(L: *mut lua_State, idx: c_int)408     pub fn lua_settable(L: *mut lua_State, idx: c_int);
lua_setfield(L: *mut lua_State, idx: c_int, k: *const c_char)409     pub fn lua_setfield(L: *mut lua_State, idx: c_int, k: *const c_char);
410     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_seti(L: *mut lua_State, idx: c_int, n: lua_Integer)411     pub fn lua_seti(L: *mut lua_State, idx: c_int, n: lua_Integer);
lua_rawset(L: *mut lua_State, idx: c_int)412     pub fn lua_rawset(L: *mut lua_State, idx: c_int);
lua_rawseti(L: *mut lua_State, idx: c_int, n: lua_Integer)413     pub fn lua_rawseti(L: *mut lua_State, idx: c_int, n: lua_Integer);
414     #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
lua_rawsetp(L: *mut lua_State, idx: c_int, p: *const c_void)415     pub fn lua_rawsetp(L: *mut lua_State, idx: c_int, p: *const c_void);
lua_setmetatable(L: *mut lua_State, objindex: c_int) -> c_int416     pub fn lua_setmetatable(L: *mut lua_State, objindex: c_int) -> c_int;
417     #[cfg(feature = "lua54")]
lua_setiuservalue(L: *mut lua_State, idx: c_int, n: c_int) -> c_int418     pub fn lua_setiuservalue(L: *mut lua_State, idx: c_int, n: c_int) -> c_int;
419     #[cfg(any(feature = "lua53", feature = "lua52"))]
lua_setuservalue(L: *mut lua_State, idx: c_int)420     pub fn lua_setuservalue(L: *mut lua_State, idx: c_int);
421     #[cfg(any(feature = "lua51", feature = "luajit"))]
lua_setfenv(L: *mut lua_State, idx: c_int) -> c_int422     pub fn lua_setfenv(L: *mut lua_State, idx: c_int) -> c_int;
423 }
424 
425 #[cfg(feature = "lua54")]
426 #[inline(always)]
lua_setuservalue(L: *mut lua_State, idx: c_int)427 pub unsafe fn lua_setuservalue(L: *mut lua_State, idx: c_int) {
428     lua_setiuservalue(L, idx, 1);
429 }
430 
431 // 'load' and 'call' functions (load and run Lua code)
432 extern "C" {
433     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_callk( L: *mut lua_State, nargs: c_int, nresults: c_int, ctx: lua_KContext, k: Option<lua_KFunction>, )434     pub fn lua_callk(
435         L: *mut lua_State,
436         nargs: c_int,
437         nresults: c_int,
438         ctx: lua_KContext,
439         k: Option<lua_KFunction>,
440     );
441     #[cfg(feature = "lua52")]
lua_callk( L: *mut lua_State, nargs: c_int, nresults: c_int, ctx: c_int, k: Option<lua_CFunction>, )442     pub fn lua_callk(
443         L: *mut lua_State,
444         nargs: c_int,
445         nresults: c_int,
446         ctx: c_int,
447         k: Option<lua_CFunction>,
448     );
449 
450     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_pcallk( L: *mut lua_State, nargs: c_int, nresults: c_int, errfunc: c_int, ctx: lua_KContext, k: Option<lua_KFunction>, ) -> c_int451     pub fn lua_pcallk(
452         L: *mut lua_State,
453         nargs: c_int,
454         nresults: c_int,
455         errfunc: c_int,
456         ctx: lua_KContext,
457         k: Option<lua_KFunction>,
458     ) -> c_int;
459     #[cfg(feature = "lua52")]
lua_pcallk( L: *mut lua_State, nargs: c_int, nresults: c_int, errfunc: c_int, ctx: c_int, k: Option<lua_CFunction>, ) -> c_int460     pub fn lua_pcallk(
461         L: *mut lua_State,
462         nargs: c_int,
463         nresults: c_int,
464         errfunc: c_int,
465         ctx: c_int,
466         k: Option<lua_CFunction>,
467     ) -> c_int;
468 
469     #[cfg(feature = "lua52")]
lua_getctx(L: *mut lua_State, ctx: *mut c_int) -> c_int470     pub fn lua_getctx(L: *mut lua_State, ctx: *mut c_int) -> c_int;
471 
472     #[cfg(any(feature = "lua51", feature = "luajit"))]
lua_call(L: *mut lua_State, nargs: c_int, nresults: c_int)473     pub fn lua_call(L: *mut lua_State, nargs: c_int, nresults: c_int);
474     #[cfg(any(feature = "lua51", feature = "luajit"))]
lua_pcall(L: *mut lua_State, nargs: c_int, nresults: c_int, errfunc: c_int) -> c_int475     pub fn lua_pcall(L: *mut lua_State, nargs: c_int, nresults: c_int, errfunc: c_int) -> c_int;
476 
477     // TODO
lua_load( L: *mut lua_State, reader: lua_Reader, dt: *mut c_void, chunkname: *const c_char, mode: *const c_char, ) -> c_int478     pub fn lua_load(
479         L: *mut lua_State,
480         reader: lua_Reader,
481         dt: *mut c_void,
482         chunkname: *const c_char,
483         mode: *const c_char,
484     ) -> c_int;
485 
486     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_dump( L: *mut lua_State, writer: lua_Writer, data: *mut c_void, strip: c_int, ) -> c_int487     pub fn lua_dump(
488         L: *mut lua_State,
489         writer: lua_Writer,
490         data: *mut c_void,
491         strip: c_int,
492     ) -> c_int;
493     #[cfg(any(feature = "lua52", feature = "lua51", feature = "luajit"))]
494     #[link_name = "lua_dump"]
lua_dump_old(L: *mut lua_State, writer: lua_Writer, data: *mut c_void) -> c_int495     pub fn lua_dump_old(L: *mut lua_State, writer: lua_Writer, data: *mut c_void) -> c_int;
496 }
497 
498 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
499 #[inline(always)]
lua_call(L: *mut lua_State, n: c_int, r: c_int)500 pub unsafe fn lua_call(L: *mut lua_State, n: c_int, r: c_int) {
501     lua_callk(L, n, r, 0, None)
502 }
503 
504 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
505 #[inline(always)]
lua_pcall(L: *mut lua_State, n: c_int, r: c_int, f: c_int) -> c_int506 pub unsafe fn lua_pcall(L: *mut lua_State, n: c_int, r: c_int, f: c_int) -> c_int {
507     lua_pcallk(L, n, r, f, 0, None)
508 }
509 
510 // coroutine functions
511 extern "C" {
512     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_yieldk( L: *mut lua_State, nresults: c_int, ctx: lua_KContext, k: Option<lua_KFunction>, ) -> c_int513     pub fn lua_yieldk(
514         L: *mut lua_State,
515         nresults: c_int,
516         ctx: lua_KContext,
517         k: Option<lua_KFunction>,
518     ) -> c_int;
519     #[cfg(feature = "lua52")]
lua_yieldk( L: *mut lua_State, nresults: c_int, ctx: c_int, k: Option<lua_CFunction>, ) -> c_int520     pub fn lua_yieldk(
521         L: *mut lua_State,
522         nresults: c_int,
523         ctx: c_int,
524         k: Option<lua_CFunction>,
525     ) -> c_int;
526     #[cfg(any(feature = "lua51", feature = "luajit"))]
lua_yield(L: *mut lua_State, nresults: c_int) -> c_int527     pub fn lua_yield(L: *mut lua_State, nresults: c_int) -> c_int;
528 
529     #[cfg(feature = "lua54")]
lua_resume( L: *mut lua_State, from: *mut lua_State, narg: c_int, nres: *mut c_int, ) -> c_int530     pub fn lua_resume(
531         L: *mut lua_State,
532         from: *mut lua_State,
533         narg: c_int,
534         nres: *mut c_int,
535     ) -> c_int;
536     #[cfg(any(feature = "lua53", feature = "lua52"))]
537     #[link_name = "lua_resume"]
lua_resume_53(L: *mut lua_State, from: *mut lua_State, narg: c_int) -> c_int538     pub fn lua_resume_53(L: *mut lua_State, from: *mut lua_State, narg: c_int) -> c_int;
539     #[cfg(any(feature = "lua51", feature = "luajit"))]
540     #[link_name = "lua_resume"]
lua_resume_old(L: *mut lua_State, narg: c_int) -> c_int541     pub fn lua_resume_old(L: *mut lua_State, narg: c_int) -> c_int;
542 
lua_status(L: *mut lua_State) -> c_int543     pub fn lua_status(L: *mut lua_State) -> c_int;
544     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_isyieldable(L: *mut lua_State) -> c_int545     pub fn lua_isyieldable(L: *mut lua_State) -> c_int;
546 }
547 
548 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
549 #[inline(always)]
lua_yield(L: *mut lua_State, n: c_int) -> c_int550 pub unsafe fn lua_yield(L: *mut lua_State, n: c_int) -> c_int {
551     lua_yieldk(L, n, 0, None)
552 }
553 
554 #[cfg(any(
555     feature = "lua53",
556     feature = "lua52",
557     feature = "lua51",
558     feature = "luajit"
559 ))]
560 #[inline(always)]
lua_resume( L: *mut lua_State, from: *mut lua_State, narg: c_int, nres: *mut c_int, ) -> c_int561 pub unsafe fn lua_resume(
562     L: *mut lua_State,
563     from: *mut lua_State,
564     narg: c_int,
565     nres: *mut c_int,
566 ) -> c_int {
567     let ret = lua_resume_53(L, from, narg);
568     if ret == LUA_OK || ret == LUA_YIELD {
569         *nres = lua_gettop(L);
570     }
571     ret
572 }
573 
574 // warning-related functions
575 #[cfg(feature = "lua54")]
576 extern "C" {
lua_setwarnf(L: *mut lua_State, f: Option<lua_WarnFunction>, ud: *mut c_void)577     pub fn lua_setwarnf(L: *mut lua_State, f: Option<lua_WarnFunction>, ud: *mut c_void);
lua_warning(L: *mut lua_State, msg: *const c_char, tocont: c_int)578     pub fn lua_warning(L: *mut lua_State, msg: *const c_char, tocont: c_int);
579 }
580 
581 // garbage-collection function and options
582 pub const LUA_GCSTOP: c_int = 0;
583 pub const LUA_GCRESTART: c_int = 1;
584 pub const LUA_GCCOLLECT: c_int = 2;
585 pub const LUA_GCCOUNT: c_int = 3;
586 pub const LUA_GCCOUNTB: c_int = 4;
587 pub const LUA_GCSTEP: c_int = 5;
588 pub const LUA_GCSETPAUSE: c_int = 6;
589 pub const LUA_GCSETSTEPMUL: c_int = 7;
590 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
591 pub const LUA_GCISRUNNING: c_int = 9;
592 #[cfg(feature = "lua54")]
593 pub const LUA_GCGEN: c_int = 10;
594 #[cfg(feature = "lua54")]
595 pub const LUA_GCINC: c_int = 11;
596 
597 extern "C" {
598     #[cfg(feature = "lua54")]
lua_gc(L: *mut lua_State, what: c_int, ...) -> c_int599     pub fn lua_gc(L: *mut lua_State, what: c_int, ...) -> c_int;
600     #[cfg(any(
601         feature = "lua53",
602         feature = "lua52",
603         feature = "lua51",
604         feature = "luajit"
605     ))]
lua_gc(L: *mut lua_State, what: c_int, data: c_int) -> c_int606     pub fn lua_gc(L: *mut lua_State, what: c_int, data: c_int) -> c_int;
607 }
608 
609 // miscellaneous functions
610 extern "C" {
lua_error(L: *mut lua_State) -> !611     pub fn lua_error(L: *mut lua_State) -> !;
lua_next(L: *mut lua_State, idx: c_int) -> c_int612     pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int;
lua_concat(L: *mut lua_State, n: c_int)613     pub fn lua_concat(L: *mut lua_State, n: c_int);
614     #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
lua_len(L: *mut lua_State, idx: c_int)615     pub fn lua_len(L: *mut lua_State, idx: c_int);
616     #[cfg(any(feature = "lua54", feature = "lua53"))]
lua_stringtonumber(L: *mut lua_State, s: *const c_char) -> usize617     pub fn lua_stringtonumber(L: *mut lua_State, s: *const c_char) -> usize;
lua_getallocf(L: *mut lua_State, ud: *mut *mut c_void) -> lua_Alloc618     pub fn lua_getallocf(L: *mut lua_State, ud: *mut *mut c_void) -> lua_Alloc;
lua_setallocf(L: *mut lua_State, f: lua_Alloc, ud: *mut c_void)619     pub fn lua_setallocf(L: *mut lua_State, f: lua_Alloc, ud: *mut c_void);
620     #[cfg(feature = "lua54")]
lua_toclose(L: *mut lua_State, idx: c_int)621     pub fn lua_toclose(L: *mut lua_State, idx: c_int);
622 }
623 
624 // some useful macros
625 // here, implemented as Rust functions
626 #[cfg(any(feature = "lua54", feature = "lua53"))]
627 #[inline(always)]
lua_getextraspace(L: *mut lua_State) -> *mut c_void628 pub unsafe fn lua_getextraspace(L: *mut lua_State) -> *mut c_void {
629     (L as *mut c_char).offset(-super::glue::LUA_EXTRASPACE as isize) as *mut c_void
630 }
631 
632 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
633 #[inline(always)]
lua_tonumber(L: *mut lua_State, i: c_int) -> lua_Number634 pub unsafe fn lua_tonumber(L: *mut lua_State, i: c_int) -> lua_Number {
635     lua_tonumberx(L, i, ptr::null_mut())
636 }
637 
638 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
639 #[inline(always)]
lua_tointeger(L: *mut lua_State, i: c_int) -> lua_Integer640 pub unsafe fn lua_tointeger(L: *mut lua_State, i: c_int) -> lua_Integer {
641     lua_tointegerx(L, i, ptr::null_mut())
642 }
643 
644 #[inline(always)]
lua_pop(L: *mut lua_State, n: c_int)645 pub unsafe fn lua_pop(L: *mut lua_State, n: c_int) {
646     lua_settop(L, -n - 1)
647 }
648 
649 #[inline(always)]
lua_newtable(L: *mut lua_State)650 pub unsafe fn lua_newtable(L: *mut lua_State) {
651     lua_createtable(L, 0, 0)
652 }
653 
654 #[inline(always)]
lua_register(L: *mut lua_State, n: *const c_char, f: lua_CFunction)655 pub unsafe fn lua_register(L: *mut lua_State, n: *const c_char, f: lua_CFunction) {
656     lua_pushcfunction(L, f);
657     lua_setglobal(L, n)
658 }
659 
660 #[inline(always)]
lua_pushcfunction(L: *mut lua_State, f: lua_CFunction)661 pub unsafe fn lua_pushcfunction(L: *mut lua_State, f: lua_CFunction) {
662     lua_pushcclosure(L, f, 0)
663 }
664 
665 #[inline(always)]
lua_isfunction(L: *mut lua_State, n: c_int) -> c_int666 pub unsafe fn lua_isfunction(L: *mut lua_State, n: c_int) -> c_int {
667     (lua_type(L, n) == LUA_TFUNCTION) as c_int
668 }
669 
670 #[inline(always)]
lua_istable(L: *mut lua_State, n: c_int) -> c_int671 pub unsafe fn lua_istable(L: *mut lua_State, n: c_int) -> c_int {
672     (lua_type(L, n) == LUA_TTABLE) as c_int
673 }
674 
675 #[inline(always)]
lua_islightuserdata(L: *mut lua_State, n: c_int) -> c_int676 pub unsafe fn lua_islightuserdata(L: *mut lua_State, n: c_int) -> c_int {
677     (lua_type(L, n) == LUA_TLIGHTUSERDATA) as c_int
678 }
679 
680 #[inline(always)]
lua_isnil(L: *mut lua_State, n: c_int) -> c_int681 pub unsafe fn lua_isnil(L: *mut lua_State, n: c_int) -> c_int {
682     (lua_type(L, n) == LUA_TNIL) as c_int
683 }
684 
685 #[inline(always)]
lua_isboolean(L: *mut lua_State, n: c_int) -> c_int686 pub unsafe fn lua_isboolean(L: *mut lua_State, n: c_int) -> c_int {
687     (lua_type(L, n) == LUA_TBOOLEAN) as c_int
688 }
689 
690 #[inline(always)]
lua_isthread(L: *mut lua_State, n: c_int) -> c_int691 pub unsafe fn lua_isthread(L: *mut lua_State, n: c_int) -> c_int {
692     (lua_type(L, n) == LUA_TTHREAD) as c_int
693 }
694 
695 #[inline(always)]
lua_isnone(L: *mut lua_State, n: c_int) -> c_int696 pub unsafe fn lua_isnone(L: *mut lua_State, n: c_int) -> c_int {
697     (lua_type(L, n) == LUA_TNONE) as c_int
698 }
699 
700 #[inline(always)]
lua_isnoneornil(L: *mut lua_State, n: c_int) -> c_int701 pub unsafe fn lua_isnoneornil(L: *mut lua_State, n: c_int) -> c_int {
702     (lua_type(L, n) <= 0) as c_int
703 }
704 
705 #[inline(always)]
lua_pushliteral(L: *mut lua_State, s: &'static str) -> *const c_char706 pub unsafe fn lua_pushliteral(L: *mut lua_State, s: &'static str) -> *const c_char {
707     use std::ffi::CString;
708     let c_str = CString::new(s).unwrap();
709     lua_pushlstring(L, c_str.as_ptr(), c_str.as_bytes().len())
710 }
711 
712 #[cfg(any(feature = "lua51", feature = "luajit"))]
713 #[inline(always)]
lua_setglobal(L: *mut lua_State, var: *const c_char)714 pub unsafe fn lua_setglobal(L: *mut lua_State, var: *const c_char) {
715     lua_setfield(L, LUA_GLOBALSINDEX, var)
716 }
717 
718 #[cfg(any(feature = "lua51", feature = "luajit"))]
719 #[inline(always)]
lua_getglobal(L: *mut lua_State, var: *const c_char) -> c_int720 pub unsafe fn lua_getglobal(L: *mut lua_State, var: *const c_char) -> c_int {
721     lua_getfield(L, LUA_GLOBALSINDEX, var)
722 }
723 
724 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
725 #[inline(always)]
lua_pushglobaltable(L: *mut lua_State) -> c_int726 pub unsafe fn lua_pushglobaltable(L: *mut lua_State) -> c_int {
727     lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS)
728 }
729 
730 #[inline(always)]
lua_tostring(L: *mut lua_State, i: c_int) -> *const c_char731 pub unsafe fn lua_tostring(L: *mut lua_State, i: c_int) -> *const c_char {
732     lua_tolstring(L, i, ptr::null_mut())
733 }
734 
735 #[cfg(any(feature = "lua54", feature = "lua53"))]
736 #[inline(always)]
lua_insert(L: *mut lua_State, idx: c_int)737 pub unsafe fn lua_insert(L: *mut lua_State, idx: c_int) {
738     lua_rotate(L, idx, 1)
739 }
740 
741 #[cfg(any(feature = "lua54", feature = "lua53"))]
742 #[inline(always)]
lua_remove(L: *mut lua_State, idx: c_int)743 pub unsafe fn lua_remove(L: *mut lua_State, idx: c_int) {
744     lua_rotate(L, idx, -1);
745     lua_pop(L, 1)
746 }
747 
748 #[cfg(any(feature = "lua54", feature = "lua53"))]
749 #[inline(always)]
lua_replace(L: *mut lua_State, idx: c_int)750 pub unsafe fn lua_replace(L: *mut lua_State, idx: c_int) {
751     lua_copy(L, -1, idx);
752     lua_pop(L, 1)
753 }
754 
755 // Debug API
756 // Event codes
757 pub const LUA_HOOKCALL: c_int = 0;
758 pub const LUA_HOOKRET: c_int = 1;
759 pub const LUA_HOOKLINE: c_int = 2;
760 pub const LUA_HOOKCOUNT: c_int = 3;
761 pub const LUA_HOOKTAILCALL: c_int = 4;
762 
763 // Event masks
764 pub const LUA_MASKCALL: c_int = 1 << (LUA_HOOKCALL as usize);
765 pub const LUA_MASKRET: c_int = 1 << (LUA_HOOKRET as usize);
766 pub const LUA_MASKLINE: c_int = 1 << (LUA_HOOKLINE as usize);
767 pub const LUA_MASKCOUNT: c_int = 1 << (LUA_HOOKCOUNT as usize);
768 
769 /// Type for functions to be called on debug events.
770 pub type lua_Hook = unsafe extern "C" fn(L: *mut lua_State, ar: *mut lua_Debug);
771 
772 extern "C" {
lua_getstack(L: *mut lua_State, level: c_int, ar: *mut lua_Debug) -> c_int773     pub fn lua_getstack(L: *mut lua_State, level: c_int, ar: *mut lua_Debug) -> c_int;
lua_getinfo(L: *mut lua_State, what: *const c_char, ar: *mut lua_Debug) -> c_int774     pub fn lua_getinfo(L: *mut lua_State, what: *const c_char, ar: *mut lua_Debug) -> c_int;
lua_getlocal(L: *mut lua_State, ar: *const lua_Debug, n: c_int) -> *const c_char775     pub fn lua_getlocal(L: *mut lua_State, ar: *const lua_Debug, n: c_int) -> *const c_char;
lua_setlocal(L: *mut lua_State, ar: *const lua_Debug, n: c_int) -> *const c_char776     pub fn lua_setlocal(L: *mut lua_State, ar: *const lua_Debug, n: c_int) -> *const c_char;
lua_getupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char777     pub fn lua_getupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char;
lua_setupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char778     pub fn lua_setupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char;
779 
780     #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
lua_upvalueid(L: *mut lua_State, fidx: c_int, n: c_int) -> *mut c_void781     pub fn lua_upvalueid(L: *mut lua_State, fidx: c_int, n: c_int) -> *mut c_void;
782     #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
lua_upvaluejoin(L: *mut lua_State, fidx1: c_int, n1: c_int, fidx2: c_int, n2: c_int)783     pub fn lua_upvaluejoin(L: *mut lua_State, fidx1: c_int, n1: c_int, fidx2: c_int, n2: c_int);
784 
lua_sethook(L: *mut lua_State, func: Option<lua_Hook>, mask: c_int, count: c_int)785     pub fn lua_sethook(L: *mut lua_State, func: Option<lua_Hook>, mask: c_int, count: c_int);
lua_gethook(L: *mut lua_State) -> Option<lua_Hook>786     pub fn lua_gethook(L: *mut lua_State) -> Option<lua_Hook>;
lua_gethookmask(L: *mut lua_State) -> c_int787     pub fn lua_gethookmask(L: *mut lua_State) -> c_int;
lua_gethookcount(L: *mut lua_State) -> c_int788     pub fn lua_gethookcount(L: *mut lua_State) -> c_int;
789 
790     #[cfg(feature = "lua54")]
lua_setcstacklimit(L: *mut lua_State, limit: c_uint) -> c_int791     pub fn lua_setcstacklimit(L: *mut lua_State, limit: c_uint) -> c_int;
792 }
793 
794 #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52"))]
795 #[repr(C)]
796 pub struct lua_Debug {
797     pub event: c_int,
798     pub name: *const c_char,
799     pub namewhat: *const c_char,
800     pub what: *const c_char,
801     pub source: *const c_char,
802     #[cfg(feature = "lua54")]
803     pub srclen: usize,
804     pub currentline: c_int,
805     pub linedefined: c_int,
806     pub lastlinedefined: c_int,
807     pub nups: c_uchar,
808     pub nparams: c_uchar,
809     pub isvararg: c_char,
810     pub istailcall: c_char,
811     #[cfg(feature = "lua54")]
812     pub ftransfer: c_ushort,
813     #[cfg(feature = "lua54")]
814     pub ntransfer: c_ushort,
815     pub short_src: [c_char; luaconf::LUA_IDSIZE as usize],
816     // lua.h mentions this is for private use
817     i_ci: *mut c_void,
818 }
819 
820 #[cfg(any(feature = "lua51", feature = "luajit"))]
821 #[repr(C)]
822 pub struct lua_Debug {
823     pub event: c_int,
824     pub name: *const c_char,
825     pub namewhat: *const c_char,
826     pub what: *const c_char,
827     pub source: *const c_char,
828     pub currentline: c_int,
829     pub nups: c_int,
830     pub linedefined: c_int,
831     pub lastlinedefined: c_int,
832     pub short_src: [c_char; luaconf::LUA_IDSIZE as usize],
833     // lua.h mentions this is for private use
834     i_ci: c_int,
835 }
836