configure: detect lua integer size

Lua 5.1 and 5.3 use a different integer size. Run a test program
to set the integer size used in the Rust FFI layer to Rust.
pull/4350/head
Jason Ish 6 years ago committed by Victor Julien
parent a946c6e195
commit 2abcd5d27f

@ -2034,6 +2034,25 @@
AM_CONDITIONAL([HAVE_LUA], [test "x$enable_lua" != "xno"])
# If Lua is enabled, test the integer size.
if test "x$enable_lua" = "xyes"; then
AC_MSG_CHECKING([size of lua integer])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[ #include <lua.h> ]],
[[
if (sizeof(lua_Integer) == 8) {
exit(1);
}
exit(0);
]])],
[
AC_MSG_RESULT([4])
],
[
AC_MSG_RESULT([8])
AC_SUBST([LUA_INT8], ["lua_int8"])
])
fi
# libmaxminddb
AC_ARG_ENABLE(geoip,
AS_HELP_STRING([--enable-geoip],[Enable GeoIP support]),

@ -11,6 +11,7 @@ debug = true
[features]
lua = []
lua_int8 = ["lua"]
strict = []
debug = []

@ -22,7 +22,7 @@ endif
endif
if HAVE_LUA
RUST_FEATURES += lua
RUST_FEATURES += lua $(LUA_INT8)
endif
if DEBUG

@ -19,6 +19,12 @@ use std::os::raw::c_char;
use std::os::raw::c_int;
use std::os::raw::c_long;
#[cfg(feature = "lua_int8")]
type LuaInteger = i64;
#[cfg(not(feature = "lua_int8"))]
type LuaInteger = i32;
/// The Rust place holder for lua_State.
pub enum CLuaState {}
@ -26,7 +32,7 @@ extern {
fn lua_createtable(lua: *mut CLuaState, narr: c_int, nrec: c_int);
fn lua_settable(lua: *mut CLuaState, idx: c_long);
fn lua_pushlstring(lua: *mut CLuaState, s: *const c_char, len: usize);
fn lua_pushinteger(lua: *mut CLuaState, n: c_long);
fn lua_pushinteger(lua: *mut CLuaState, n: LuaInteger);
}
pub struct LuaState {
@ -55,7 +61,7 @@ impl LuaState {
pub fn pushinteger(&self, val: i64) {
unsafe {
lua_pushinteger(self.lua, val as c_long);
lua_pushinteger(self.lua, val as LuaInteger);
}
}
}

Loading…
Cancel
Save