Skip to content

Commit b16f389

Browse files
committed
lua54: use changed return type for lua_rawlen
Lua 5.4 changed lua_rawlen to return lua_Unsigned, versus size_t in earlier versions. Change the C API signature to match, and add a wrapper function with the same name that maintains a stable Rust API by casting to usize.
1 parent a4c9192 commit b16f389

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

mlua-sys/src/lua54/lua.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,20 @@ extern "C-unwind" {
149149
pub fn lua_tointegerx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Integer;
150150
pub fn lua_toboolean(L: *mut lua_State, idx: c_int) -> c_int;
151151
pub fn lua_tolstring(L: *mut lua_State, idx: c_int, len: *mut usize) -> *const c_char;
152-
pub fn lua_rawlen(L: *mut lua_State, idx: c_int) -> usize;
152+
#[link_name = "lua_rawlen"]
153+
fn lua_rawlen_(L: *mut lua_State, idx: c_int) -> lua_Unsigned;
153154
pub fn lua_tocfunction(L: *mut lua_State, idx: c_int) -> Option<lua_CFunction>;
154155
pub fn lua_touserdata(L: *mut lua_State, idx: c_int) -> *mut c_void;
155156
pub fn lua_tothread(L: *mut lua_State, idx: c_int) -> *mut lua_State;
156157
pub fn lua_topointer(L: *mut lua_State, idx: c_int) -> *const c_void;
157158
}
158159

160+
// lua_rawlen's return type changed from size_t to lua_Unsigned int in Lua 5.4.
161+
// This adapts the crate API to the new Lua ABI.
162+
pub unsafe fn lua_rawlen(L: *mut lua_State, idx: c_int) -> usize {
163+
lua_rawlen_(L, idx) as usize
164+
}
165+
159166
//
160167
// Comparison and arithmetic functions
161168
//

0 commit comments

Comments
 (0)