I've looked high and low for any other posts related to CEGUI and LUAJit compatibility and have found nothing. I hope this helps anyone that might of run into the same issues.
I've been integrating CEGUI 0.8.4 into an Engine that uses LUAJit 2.0.3 (5.1) as its lua virtual machine and I really wanted to be able to share the lua_state between the two. Since luajit uses the same api it should be a simple task of having CEGUILuaScriptModule link with lua51.lib & lua51.dll instead of the provided lua.lib & lua.dll.
However, when CEGUI is creating the lua bindings a stack overflow happens when attempting to execute - lua_CEGUI.cpp:68563
I figured this was because the generated byte code being executed was incompatible with luajit (since tolua++ uses regular lua in all of its madness). But, digging into the *.pkg files in "cegui-0.8.4\cegui\src\ScriptModules\Lua\package" I noticed that it had lua written in between [$ ... $] sections.
After taking all of the string lua sections and replacing it's corresponding byte code section in lua_CEGUI.cpp (they appear in the same order in which the packages were included in CEGUI.pkg) I was able to isolate the issue. Oh, the issue was reproducible in both x86/x64 with msvc110(VS 2012) run times.
Example byte code replacement:
Code: Select all
{ /* begin embedded lua code */
int top = lua_gettop(tolua_S);
//static unsigned char B[] = {
// 10, 67, 69, 71, 85, 73, 46, 87, 105, 110, 100, 111, 119, 70, 97,
// 99, 116, 111, 114, 121, 73, 116, 101, 114, 97, 116, 111, 114, 46, 105,
// 116, 101, 114, 97, 116, 111, 114, 32, 61, 32, 67, 69, 71, 85, 73,
// 46, 105, 116, 101, 114, 97, 116, 111, 114, 95, 105, 109, 112, 108, 59,
// 32
//};
//tolua_dobuffer(tolua_S, (char*)B, sizeof(B), "tolua: embedded Lua code 5");*/
luaL_dostring(tolua_S, "CEGUI.WindowFactoryIterator.iterator = CEGUI.iterator_impl;\n");
lua_settop(tolua_S, top);
} /* end of embedded lua code */
The code that is tripping stack overflows is located in/at "cegui-0.8.4\cegui\src\ScriptModules\Lua\package\HelperFunctions.pkg : 76 & 230 - 271"
For some reason assigning any of those functions from the 'CEGUI' module to the 'CEGUI.Window' module will always trip the overflow. Doing luaL_dostring() without those assignments will allow CEGUI to link and use the oh so delicious luajit.
In summary; Fix / remove the mentioned lines from the package files and CEGUI will be out-of-the-box luajit compatible.
I hope this was helpful,