diff --git a/mlua-sys/src/lua51/lua.rs b/mlua-sys/src/lua51/lua.rs index 925e9c7f..5cd351d8 100644 --- a/mlua-sys/src/lua51/lua.rs +++ b/mlua-sys/src/lua51/lua.rs @@ -228,13 +228,22 @@ extern "C-unwind" { // #[cfg_attr(all(windows, raw_dylib), link(name = "lua51", kind = "raw-dylib"))] extern "C-unwind" { - pub fn lua_error(L: *mut lua_State) -> !; + #[link_name = "lua_error"] + fn lua_error_(L: *mut lua_State) -> c_int; pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int; pub fn lua_concat(L: *mut lua_State, n: c_int); pub fn lua_getallocf(L: *mut lua_State, ud: *mut *mut c_void) -> lua_Alloc; pub fn lua_setallocf(L: *mut lua_State, f: lua_Alloc, ud: *mut c_void); } +// lua_error does not return but is declared to return int, and Rust translates +// ! to void which can cause link-time errors if the platform linker is aware +// of return types and requires they match (for example: wasm does this). +pub unsafe fn lua_error(L: *mut lua_State) -> ! { + lua_error_(L); + unreachable!(); +} + // // Some useful macros (implemented as Rust functions) // diff --git a/mlua-sys/src/lua52/lua.rs b/mlua-sys/src/lua52/lua.rs index 760140b7..d668d678 100644 --- a/mlua-sys/src/lua52/lua.rs +++ b/mlua-sys/src/lua52/lua.rs @@ -308,7 +308,8 @@ extern "C-unwind" { // // Miscellaneous functions // - pub fn lua_error(L: *mut lua_State) -> !; + #[link_name = "lua_error"] + fn lua_error_(L: *mut lua_State) -> c_int; pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int; pub fn lua_concat(L: *mut lua_State, n: c_int); pub fn lua_len(L: *mut lua_State, idx: c_int); @@ -316,6 +317,14 @@ extern "C-unwind" { pub fn lua_setallocf(L: *mut lua_State, f: lua_Alloc, ud: *mut c_void); } +// lua_error does not return but is declared to return int, and Rust translates +// ! to void which can cause link-time errors if the platform linker is aware +// of return types and requires they match (for example: wasm does this). +pub unsafe fn lua_error(L: *mut lua_State) -> ! { + lua_error_(L); + unreachable!(); +} + // // Some useful macros (implemented as Rust functions) // diff --git a/mlua-sys/src/lua53/lua.rs b/mlua-sys/src/lua53/lua.rs index d918de48..393ff3c7 100644 --- a/mlua-sys/src/lua53/lua.rs +++ b/mlua-sys/src/lua53/lua.rs @@ -314,7 +314,8 @@ extern "C-unwind" { // // Miscellaneous functions // - pub fn lua_error(L: *mut lua_State) -> !; + #[link_name = "lua_error"] + fn lua_error_(L: *mut lua_State) -> c_int; pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int; pub fn lua_concat(L: *mut lua_State, n: c_int); pub fn lua_len(L: *mut lua_State, idx: c_int); @@ -323,6 +324,14 @@ extern "C-unwind" { pub fn lua_setallocf(L: *mut lua_State, f: lua_Alloc, ud: *mut c_void); } +// lua_error does not return but is declared to return int, and Rust translates +// ! to void which can cause link-time errors if the platform linker is aware +// of return types and requires they match (for example: wasm does this). +pub unsafe fn lua_error(L: *mut lua_State) -> ! { + lua_error_(L); + unreachable!(); +} + // // Some useful macros (implemented as Rust functions) // diff --git a/mlua-sys/src/lua54/lua.rs b/mlua-sys/src/lua54/lua.rs index 7eab2af2..b1348661 100644 --- a/mlua-sys/src/lua54/lua.rs +++ b/mlua-sys/src/lua54/lua.rs @@ -343,7 +343,8 @@ extern "C-unwind" { // // Miscellaneous functions // - pub fn lua_error(L: *mut lua_State) -> !; + #[link_name = "lua_error"] + fn lua_error_(L: *mut lua_State) -> c_int; pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int; pub fn lua_concat(L: *mut lua_State, n: c_int); pub fn lua_len(L: *mut lua_State, idx: c_int); @@ -355,6 +356,14 @@ extern "C-unwind" { pub fn lua_closeslot(L: *mut lua_State, idx: c_int); } +// lua_error does not return but is declared to return int, and Rust translates +// ! to void which can cause link-time errors if the platform linker is aware +// of return types and requires they match (for example: wasm does this). +pub unsafe fn lua_error(L: *mut lua_State) -> ! { + lua_error_(L); + unreachable!(); +} + // // Some useful macros (implemented as Rust functions) //