A crash when loading dll from LuaJIT (works with "regular" Lua)

  • From: Paul Kulchenko <paulclinger@xxxxxxxxx>
  • To: "luajit@xxxxxxxxxxxxx" <luajit@xxxxxxxxxxxxx>
  • Date: Sat, 29 Dec 2012 21:22:33 -0800 (PST)

Hi All,

I'm trying to compile an extension I can use with both a regular Lua 
interpreter and LuaJIT and ran into a possible issue with LuaJIT: the module 
loads normally using Lua, but crashes with c0000005 error when used with LuaJIT.


> LuaJIT is also fully ABI-compatible to Lua 5.1 at the linker/dynamic
loader level. This means you can compile a C module against the
standard Lua headers and load the same shared library from either Lua
or LuaJIT. 


Given the ABI-compatibility I expected this to work. This is most likely a 
problem on my side, but I can't figure out where exactly is the issue. I'm 
running on Windows Vista, using LuaJIT 2.0.0 (a version from Git retrieved two 
weeks ago). The crash happens when I run "require 'mobtest'".


Here is the makefile and the code I'm using. I'd appreciate any help with 
getting this to work. Thank you. Paul.


-- build.bat


set LUA_DIR=D:\Lua\build\lua-5.1.4
set CFLAGS=-c -O1 -DPSAPI_VERSION=1 -I"%LUA_DIR%\src"
gcc %CFLAGS% mobtest.c
gcc -Wl,-s -shared mobtest.o "%LUA_DIR%\src\lua51.a" -o mobtest.dll

-- mobtest.c


#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

#ifdef WIN32
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif

#if LUA_VERSION_NUM > 501
#define lua_objlen lua_rawlen
#endif

static const luaL_Reg mobtest_funs[] = {
   {NULL,NULL}
};

EXPORT int luaopen_mobtest (lua_State *L) {
#if LUA_VERSION_NUM > 501
    lua_newtable(L);
    luaL_setfuncs (L,mobtest_funs,0);
    lua_pushvalue(L,-1);
    lua_setglobal(L,"mobtest");
#else
    luaL_register(L,"mobtest",mobtest_funs);
#endif
    return 1;
}

Other related posts: