Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 6179ffe

Browse files
committed
Add a lot of functions
* lua_pushinteger * Rest of the LuaJIT functions * luaL_opt<integer,number,string> * lua_to<integer,number>x * luaL_traceback * luaL_where * luaL_testudata * luaL_buffinit * luaL_prepbuffer * luaL_getmetafield * luaL_<exec,file,find>result * luaL_gsub
1 parent 572abb5 commit 6179ffe

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/lua_shared.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ expose_symbol!( lua_pushcclosure, (), (state: LuaState, fnc: LuaCFunction, idx:
117117
expose_symbol!( lua_pushlightuserdata, (), (state: LuaState, p: *mut CVoid) );
118118
expose_symbol!( lua_pushthread, (), (state: LuaState) );
119119
expose_symbol!( lua_pushfstring, CharBuf, (state: LuaState, fmt: CharBuf, ...) );
120+
expose_symbol!( lua_pushinteger, (), (state: LuaState, n: LuaInteger) );
120121

121122
// Type Checks
122123
expose_symbol!( luaL_checkinteger, LuaInteger, (state: LuaState, narg: CInt) );
@@ -139,6 +140,11 @@ expose_symbol!( lua_close, (), (state: LuaState) ); // Destroys the lua state
139140
// JIT
140141
// Returns 1 for success, 0 for failure
141142
expose_symbol!( luaJIT_setmode, CInt, (state: LuaState, idx: CInt, jit_mode: CInt) );
143+
expose_symbol!( luaJIT_profile_stop, (), (state: LuaState) );
144+
145+
type LuaJITProfileCallback = extern "C" fn(data: *mut CVoid, l: LuaState, samples: CInt, vmstate: CInt) -> ();
146+
expose_symbol!( luaJIT_profile_start, (), (state: LuaState, mode: CharBuf, cb: LuaJITProfileCallback, data: *mut CVoid) );
147+
expose_symbol!( luaJIT_profile_dumpstack, CharBuf, (state: LuaState, fmt: CharBuf, depth: CInt, len: SizeT) );
142148

143149
// Coroutines
144150
expose_symbol!( lua_yield, CInt, (state: LuaState, nresults: CInt) );
@@ -174,6 +180,34 @@ expose_symbol!( luaL_unref, (), (state: LuaState, t: CInt, r: CInt) );
174180
// Metatables
175181
expose_symbol!( luaL_newmetatable, CInt, (state: LuaState, tname: CharBuf) );
176182
expose_symbol!( luaL_newmetatable_type, CInt, (state: LuaState, tname: CharBuf, typ: CInt) );
183+
expose_symbol!( luaL_getmetafield, CInt, (state: LuaState, obj: CInt, e: CharBuf) );
184+
185+
// Optional / Default to ``d``
186+
expose_symbol!( luaL_optinteger, CInt, (state: LuaState, narg: CInt, d: LuaInteger) );
187+
expose_symbol!( luaL_optlstring, CharBuf, (state: LuaState, arg: CInt, d: CharBuf, l: SizeT) );
188+
expose_symbol!( luaL_optnumber, LuaNumber, (state: LuaState, arg: CInt, d: LuaNumber) );
189+
190+
// x / ref functions
191+
expose_symbol!( lua_tointegerx, LuaInteger, (state: LuaState, index: CInt, isnum: *mut CInt) );
192+
expose_symbol!( lua_tonumberx, LuaNumber, (state: LuaState, index: CInt, isnum: *mut CInt) );
193+
194+
// Debug
195+
expose_symbol!( luaL_traceback, (), (state: LuaState, state1: LuaState, msg: CharBuf, level: CInt) );
196+
expose_symbol!( luaL_where, (), (state: LuaState, lvl: CInt) );
197+
198+
// Misc
199+
expose_symbol!( luaL_testudata, (), (state: LuaState, arg: CInt, tname: CharBuf) );
200+
expose_symbol!( luaL_execresult, CInt, (state: LuaState, stat: CInt) );
201+
expose_symbol!( luaL_fileresult, CInt, (state: LuaState, stat: CInt, fname: CharBuf) );
202+
expose_symbol!( luaL_findtable, CharBuf, (state: LuaState, idx: CInt, fname: CharBuf, szhint: CInt) );
203+
204+
// luaL_Buffer
205+
expose_symbol!( luaL_buffinit, (), (state: LuaState, b: *mut LuaL_Buffer) );
206+
expose_symbol!( luaL_prepbuffer, *mut i8, (b: *mut LuaL_Buffer) );
207+
208+
// String methods
209+
expose_symbol!( luaL_gsub, CharBuf, (s: CharBuf, pattern: CharBuf, replace: CharBuf) );
210+
177211

178212
#[inline(always)]
179213
pub fn lua_pop(state: LuaState, ind: CInt) {

src/types.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ pub type LuaInteger = isize;
1313

1414
pub type LuaState = *mut CVoid; // Raw Lua state.
1515
pub type LuaCFunction = extern "C" fn(LuaState) -> CInt;
16+
17+
#[repr(C)]
18+
pub struct LuaL_Buffer {
19+
b: *mut i8,
20+
size: SizeT,
21+
n: SizeT, // number of chars in buffer
22+
state: LuaState,
23+
initbuffer: [i8; 8192_usize],
24+
}

0 commit comments

Comments
 (0)