D Lua doesn't get metatable

d, lua

Solution

It sounds like you are using the ancient dlua bindings, not LuaD, which has always had `luaL_getmetatable`.

However, both these bindings as well as your code are for Lua 5.1, not 5.2; make sure you link to the correct version of Lua. There is no `lua_open` in Lua 5.2 (and it's deprecated in 5.1).

If you encounter the same problem after linking to the right library, I recommend compiling Lua with the macro `LUA_USE_APICHECK` set and trying again to see exactly what went wrong.

Problem

I'm trying to get Lua to work with the new programming language D. Everything works fine (library, lua52.dll, etc.) but `luaL_getmetatable` crashes. Originally, the function was not defined in dlua, but I added it: ``` //C #define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) void luaL_getmetatable(lua_State* L, const(char)* s) { lua_getfield(L, LUA_REGISTRYINDEX, s); } ``` But when I run: ``` L = lua_open(); luaL_openlibs(L); // prevent script kiddies luaL_dostring(L, "os = nil; io = nil"); // reprogram 'print' luaL_newmetatable(L, "vector"); luaL_getmetatable(L, "vector"); // CRASH ``` it crashes. Any ideas why this is?

Original source