3

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?

4
  • It probably wasn't shipped because that code won't wrk. Commented Apr 25, 2012 at 13:24
  • Why wouldn't it work? It uses the standard lua DLL. Commented Apr 25, 2012 at 13:38
  • Does your code work when written in C? Commented Apr 25, 2012 at 21:44
  • Also, more info pls, how does it crash, which compiler did you use, give a complete test program etc. Commented Apr 25, 2012 at 21:45

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I was indeed using a wrong version, but only of the dlua head file. I changed them according to their C header equivalents and now everything works!
1

Maybe you should take a look at the existing Lua-Bindings for D, LuaD.

2 Comments

That's not quite the solution I was looking for. My existing code in C++ is written without LuaD.
N.B.: LuaD is a lot easier to use cause it's not a simple binding but a very clever wrapper that leverages D's capabilities.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.