I'd say lua_tointeger depends on the underlying machine word size. On a 32 bit platform this would be max 7fffffff since integer is signed. Have you verified this is a luajit issue and not expected lua behaviour? On Thu, May 10, 2012 at 3:35 AM, Fredrik Ehnbom <quarnster@xxxxxxxxx> wrote: > Hi, > > I'm having an issue with LuaJit on ARM android. Large parts of my scripts > work great, but for some reason lua_tointeger doesn't return what I'm > expecting. > > On android the output of this little reproduction case is: > $ adb shell /data/repro > 0x400fe1c0 > 0 > 0 > 7fffffff, 2852126720.000000 > Segmentation fault > > Whereas on OSX it is the expected: > $ ./repro > 0x42378 > 0 > 0 > 0 > aa000000, 2852126720.000000 > > Any idea why tointeger would differ so much? The right number is clearly > there as shown by the tonumber call... Any number up to and > including 7fffffff will be correct on android, but 80000000 and above gets > "clamped" to 7fffffff. > > Is there any compiler flag or setting I've missed? > > Also, any idea why it's segfaulting at the end? > > BTW, I had to set TARGET_SYS=Linux when cross compiling for arm android on > my MAC, otherwise lj_vm.s wouldn't assemble. Exact commands used to build > LuaJit 2.0.0-beta10 were: > > NDK=~/android/android-ndk-r7 > NDKABI=8 > NDKVER=$NDK/toolchains/arm-linux-androideabi-4.4.3 > NDKP=$NDKVER/prebuilt/darwin-x86/bin/arm-linux-androideabi- > NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-arm" > make HOST_CC="gcc -m32" CROSS=$NDKP TARGET_FLAGS="$NDKF" TARGET_SYS=Linux > > > > Sources create my little sample that I'm having problems with: > > > > > CMakeLists.txt: > cmake_minimum_required(VERSION 2.8) > > if(ANDROID) > set(CMAKE_REQUIRED_INCLUDES "${ANDROID_TOOLCHAIN_ROOT}/user/include") > include_directories(${ANDROID_TOOLCHAIN_ROOT}/user/include/luajit-2.0/) > link_directories(${ANDROID_TOOLCHAIN_ROOT}/user/lib) > else() > set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pagezero_size 10000 > -image_base 100000000") > include_directories(/usr/local/include/luajit-2.0) > endif() > > add_executable(repro repro.cpp) > target_link_libraries(repro luajit-5.1) > > > > > repro.cpp: > > > #include <lua.hpp> > #include <stdio.h> > > > int main(int argc, char **argv) > { > lua_State *L = luaL_newstate(); > printf("%p\n", L); > LUAJIT_VERSION_SYM(); > lua_gc(L, LUA_GCSTOP, 0); > luaL_openlibs(L); > lua_gc(L, LUA_GCRESTART, -1); > > printf("%d\n", luaL_dostring(L, "background_color = 0xaa000000")); > printf("%d\n", luaL_dostring(L, "return background_color")); > > printf("%x, %f\n", lua_tointeger(L, -1), lua_tonumber(L, -1)); > lua_close(L); > return 0; > } > > > Cheers, > > /f >