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);
60
61 pub fn lua_error(L: *mut lua_State) -> !;
63
64 pub fn lua_getfield(L: *mut lua_State, index: c_int, k: *const c_char);
66
67 pub fn lua_getmetatable(L: *mut lua_State, index: c_int) -> c_int;
69
70 pub fn lua_gettop(L: *mut lua_State) -> c_int;
72
73 pub fn lua_newuserdata(L: *mut lua_State, size: usize) -> *mut c_void;
75
76 pub fn lua_next(L: *mut lua_State, index: c_int) -> c_int;
78
79 pub fn lua_objlen(L: *mut lua_State, index: c_int) -> usize;
81
82 pub fn lua_pcall(
84 L: *mut lua_State,
85 nargs: c_int,
86 nresults: c_int,
87 errorfunc: c_int,
88 ) -> c_int;
89
90 pub fn lua_pushboolean(L: *mut lua_State, n: lua_Integer);
92
93 pub fn lua_pushcclosure(L: *mut lua_State, r#fn: lua_CFunction, n: c_int);
95
96 pub fn lua_pushinteger(L: *mut lua_State, n: lua_Integer);
98
99 pub fn lua_pushlightuserdata(L: *mut lua_State, p: *mut c_void);
101
102 pub fn lua_pushlstring(L: *mut lua_State, s: *const c_char, len: usize);
104
105 pub fn lua_pushnil(L: *mut lua_State);
107
108 pub fn lua_pushnumber(L: *mut lua_State, n: lua_Number);
110
111 pub fn lua_pushstring(L: *mut lua_State, s: *const c_char);
113
114 pub fn lua_pushvalue(L: *mut lua_State, index: c_int);
116
117 pub fn lua_rawgeti(L: *mut lua_State, index: c_int, n: c_int);
119
120 pub fn lua_rawset(L: *mut lua_State, index: c_int);
122
123 pub fn lua_rawseti(L: *mut lua_State, index: c_int, n: c_int);
125
126 pub fn lua_settop(L: *mut lua_State, index: c_int);
128
129 pub fn lua_toboolean(L: *mut lua_State, index: c_int) -> c_int;
131
132 pub fn lua_tointeger(L: *mut lua_State, index: c_int) -> lua_Integer;
134
135 pub fn lua_tolstring(
137 L: *mut lua_State,
138 index: c_int,
139 len: *mut usize,
140 ) -> *const c_char;
141
142 pub fn lua_tonumber(L: *mut lua_State, index: c_int) -> lua_Number;
144
145 pub fn lua_touserdata(L: *mut lua_State, index: c_int) -> *mut c_void;
147
148 pub fn lua_type(L: *mut lua_State, index: c_int) -> c_int;
150
151 pub fn lua_typename(L: *mut lua_State, tp: c_int) -> *const c_char;
153
154 pub fn luaL_error(L: *mut lua_State, fmt: *const c_char, ...) -> !;
158
159 pub fn luaL_ref(L: *mut lua_State, t: c_int) -> c_int;
161
162 pub fn luaL_unref(L: *mut lua_State, t: c_int, r#ref: c_int);
164}
165
166pub unsafe fn lua_getglobal(L: *mut lua_State, name: *const c_char) {
168 lua_getfield(L, LUA_GLOBALSINDEX, name)
169}
170
171pub unsafe fn lua_pop(L: *mut lua_State, n: c_int) {
173 lua_settop(L, -n - 1)
174}
175
176pub unsafe fn lua_pushcfunction(L: *mut lua_State, r#fn: lua_CFunction) {
178 lua_pushcclosure(L, r#fn, 0)
179}
180
181pub unsafe fn lua_tostring(L: *mut lua_State, index: c_int) -> *const c_char {
183 lua_tolstring(L, index, std::ptr::null_mut())
184}
185
186pub unsafe fn luaL_typename(L: *mut lua_State, index: c_int) -> *const c_char {
188 lua_typename(L, lua_type(L, index))
189}