D Lua does not receive metadata

I am trying to get Lua to work with the new programming language D. Everything works fine (library, lua52.dll, etc.), but luaL_getmetatablecrashes. The function was not originally 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 will work. Any ideas why this is?

+3
source share
2 answers

It looks like you are using the ancient dlua bindings , not LuaD , which are always luaL_getmetatable.

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

, Lua LUA_USE_APICHECK , , .

+8

, Lua-Bindings D, LuaD.

+1

All Articles