EDIT: This has been tracked down to a more general problem with shared libraries, the d runtime and os x. See here: Initializing the D runtime on OS X
I'm trying to get a simple d function accessible from the Lua stand-alone interpreter.
I couldn't see an immediately obvious way to get the lua instance to recognise a d library so i tried this hack
import luad.all, luad.c.all;
extern (C) int luaopen_luad_test(lua_State* L) {
auto lua = new LuaState(L);
lua["addition"] = &addition;
return(0);
}
int addition(int a, int b)
{
return(a+b);
}
I know that when I call require("luad_test") it will call luaopen_luad_test(lua_State* L) giving me access to the lua_State of the interpreter. However, when I call require i just get a seg fault.
Am I looking at this completely the wrong way?
edit: I'm using lua 5.1.5 on os x and i've added ";?.dylib" to package.cpath in order to allow loading .dylib instead of .so
edit2: I've narrowed it down a bit. Any use of new in luaopen_luad_test causes a segfault.