I'm integrating Lua in C++, and now I have this table that behaves as a 'class', and for some functions it needs a 'self' argument, which actually is the table. The Lua code:
a = {
numb = 5,
create = function(a)
print(a);
end,
increment = function(self)
--self.numb = 6;
print(self.numb);
end,
decrement = function(self,i)
self.numb = self.numb-i;
print(self.numb);
end
};
b = a;
And the C++ bit to call the functions (I've got Lua running in C++)
luaL_openlibs(L);
luaL_dofile (L,"main.lua");
lua_getglobal(L, "a");
lua_getfield(L, -1, "increment");
string arg = "a";
lua_pushliteral(L,"a");
lua_pcall(L ,1,0,0);
printf(" \nI am done with Lua in C++.\n");
lua_close(L);
So, how can I pass in the self argument, as a table, into the function increment?
any help is appreciated