Skip to content

Commit 59974d7

Browse files
authored
Merge pull request #337 from tari/emscripten-support
Fix build for emscripten target
2 parents 61e8463 + e3f34f3 commit 59974d7

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

mlua-sys/src/lua51/lua.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,22 @@ extern "C-unwind" {
228228
//
229229
#[cfg_attr(all(windows, raw_dylib), link(name = "lua51", kind = "raw-dylib"))]
230230
extern "C-unwind" {
231-
pub fn lua_error(L: *mut lua_State) -> !;
231+
#[link_name = "lua_error"]
232+
fn lua_error_(L: *mut lua_State) -> c_int;
232233
pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int;
233234
pub fn lua_concat(L: *mut lua_State, n: c_int);
234235
pub fn lua_getallocf(L: *mut lua_State, ud: *mut *mut c_void) -> lua_Alloc;
235236
pub fn lua_setallocf(L: *mut lua_State, f: lua_Alloc, ud: *mut c_void);
236237
}
237238

239+
// lua_error does not return but is declared to return int, and Rust translates
240+
// ! to void which can cause link-time errors if the platform linker is aware
241+
// of return types and requires they match (for example: wasm does this).
242+
pub unsafe fn lua_error(L: *mut lua_State) -> ! {
243+
lua_error_(L);
244+
unreachable!();
245+
}
246+
238247
//
239248
// Some useful macros (implemented as Rust functions)
240249
//

mlua-sys/src/lua52/lua.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,23 @@ extern "C-unwind" {
308308
//
309309
// Miscellaneous functions
310310
//
311-
pub fn lua_error(L: *mut lua_State) -> !;
311+
#[link_name = "lua_error"]
312+
fn lua_error_(L: *mut lua_State) -> c_int;
312313
pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int;
313314
pub fn lua_concat(L: *mut lua_State, n: c_int);
314315
pub fn lua_len(L: *mut lua_State, idx: c_int);
315316
pub fn lua_getallocf(L: *mut lua_State, ud: *mut *mut c_void) -> lua_Alloc;
316317
pub fn lua_setallocf(L: *mut lua_State, f: lua_Alloc, ud: *mut c_void);
317318
}
318319

320+
// lua_error does not return but is declared to return int, and Rust translates
321+
// ! to void which can cause link-time errors if the platform linker is aware
322+
// of return types and requires they match (for example: wasm does this).
323+
pub unsafe fn lua_error(L: *mut lua_State) -> ! {
324+
lua_error_(L);
325+
unreachable!();
326+
}
327+
319328
//
320329
// Some useful macros (implemented as Rust functions)
321330
//

mlua-sys/src/lua53/lua.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ extern "C-unwind" {
314314
//
315315
// Miscellaneous functions
316316
//
317-
pub fn lua_error(L: *mut lua_State) -> !;
317+
#[link_name = "lua_error"]
318+
fn lua_error_(L: *mut lua_State) -> c_int;
318319
pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int;
319320
pub fn lua_concat(L: *mut lua_State, n: c_int);
320321
pub fn lua_len(L: *mut lua_State, idx: c_int);
@@ -323,6 +324,14 @@ extern "C-unwind" {
323324
pub fn lua_setallocf(L: *mut lua_State, f: lua_Alloc, ud: *mut c_void);
324325
}
325326

327+
// lua_error does not return but is declared to return int, and Rust translates
328+
// ! to void which can cause link-time errors if the platform linker is aware
329+
// of return types and requires they match (for example: wasm does this).
330+
pub unsafe fn lua_error(L: *mut lua_State) -> ! {
331+
lua_error_(L);
332+
unreachable!();
333+
}
334+
326335
//
327336
// Some useful macros (implemented as Rust functions)
328337
//

mlua-sys/src/lua54/lua.rs

Lines changed: 18 additions & 2 deletions
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
//
@@ -336,7 +343,8 @@ extern "C-unwind" {
336343
//
337344
// Miscellaneous functions
338345
//
339-
pub fn lua_error(L: *mut lua_State) -> !;
346+
#[link_name = "lua_error"]
347+
fn lua_error_(L: *mut lua_State) -> c_int;
340348
pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int;
341349
pub fn lua_concat(L: *mut lua_State, n: c_int);
342350
pub fn lua_len(L: *mut lua_State, idx: c_int);
@@ -348,6 +356,14 @@ extern "C-unwind" {
348356
pub fn lua_closeslot(L: *mut lua_State, idx: c_int);
349357
}
350358

359+
// lua_error does not return but is declared to return int, and Rust translates
360+
// ! to void which can cause link-time errors if the platform linker is aware
361+
// of return types and requires they match (for example: wasm does this).
362+
pub unsafe fn lua_error(L: *mut lua_State) -> ! {
363+
lua_error_(L);
364+
unreachable!();
365+
}
366+
351367
//
352368
// Some useful macros (implemented as Rust functions)
353369
//

0 commit comments

Comments
 (0)