Namely, I have library code for our game built into a .so/.dll using gcc (for both Linux and Windows.) Unfortunately, when I run in Windows I get a segfault when I attempt to register my C functions. Here is the first line in my main.lua:
Code: Select all
-- This loads the C library and binds is to a 'ds' object
ds = require 'libds'
Code: Select all
// How Lua registers the functions.
int luaopen_libds (lua_State *L){
printf("Registering functions...\n");
fflush(stdout);
luaL_register(L, "libds", lslib);
printf("Functions Registered.\n");
fflush(stdout);
return 1;
}
From what I researched on the internet, I've noticed that if threads are used (which gdb reports Love2d is using) then the passed in lua_State may have a race condition with the garbage collection. A solution listed is to use only the global lua state when Lua was instantiated. Unfortunately, I don't know how to get it. Although, I don't know how this would happen as the thread should still be open...
Is there a love2d C function to get the global lua state? Maybe in a Love2d .dll? I noticed in lua 5.2 that there is a function call to get this, but we have 5.1.
Also, is there a way to run love2d in a single thread? It is annoying running a debugger and/or Valgrind on love2d...