replacement for luaL_getMetaTable

I want to enable Lua-Scripting (Lua 5.1) in my Delphi application. For this purpose I use the header Files of Thomas Lavergne.

Now I try to register a userdata type following this example:

At the "new array function" it uses the command *luaL_getmetatable*.

static int newarray (lua_State *L) {
  int n = luaL_checkint(L, 1);
  size_t nbytes = sizeof(NumArray) + (n - 1)*sizeof(double);
  NumArray *a = (NumArray *)lua_newuserdata(L, nbytes);

  luaL_getmetatable(L, "LuaBook.array");
  lua_setmetatable(L, -2);

  a->size = n;
  return 1;  /* new userdatum is already on the stack */

Unfortunately the *luaL_getmetatable* Function is marked al old at my header File and commented out. I tried to activate it again but as expected I will get an error because the dll entrancepoint couldn't be found.

This is the Delphi-translation of that example (using another non array datatype)

  tMyType = tWhatever;
  pMyType = ^tMyType;

Function newusertype(aState : pLua_State) : LongInt; cdecl;
    NewData : pMyType;
    Result := 0;
    NewData := lua_newuserdata(aState, SizeOf(tMyType ));
    NewData^ := GetInitValue;
    luaL_getMetaTable(aState, 'myexcample.mytype'); // Error/unknown function
    lua_setmetatable(aState, -2);
    Result := 1;

Now I'm looking for an replacement of luaL_getMetaTable. I haven't found any information about one. In fact I haven't found any information that luaL_getMetaTable is outdated but it seems to be :(.


use lua_newmetatable(aState, 'myexample.mytype'). The thing is (if you only want to continue if the metatable already exists) you'll need to evaluate whether it returns a 0! If it returns 0, then it's wanting to create the metatable... in which case you can lua_pop(aState, 1).

Just remember that lua_newmetatable is a function returning an Integer (which in reality should be a Boolean).

Otherwise you can wait a few weeks for me to release Lua4Delphi version 2, which makes all of this super easy (and the Professional version actually automates the registration of Delphi Types and Instances with Lua)

Need Your Help

Using Generic List(Of Form), Trouble gathering Object's Name Property list foreach arraylist

I have been very interested as of late in interfaces and the ability to further customize them beyond using them in their default state.

Java name clash, have the same erasure, neither hides the other

java generics name-clash

I am getting this name clash error and i don't know how should i solve the problem.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.