As I integrate Lua into my C program, I used a pointer staticto the C structure to store the object that I need to reuse in the methods that I bind to the Lua state.
However, this will not work when I split Lua lib from the main program, so it seems to me that I need to use the registry to store my structure.
How do I put my C structure pointer in the Lua registry?
This is what I am doing now:
static augeas *aug = NULL;
static int lua_aug_get(lua_State *L) {
return 1;
}
struct lua_State *luaopen_augeas(augeas *a) {
lua_State *L = luaL_newstate();
aug = a;
luaL_openlibs(L);
static const luaL_Reg augfuncs[] = {
{ "get", lua_aug_get },
{ "label", lua_aug_label },
{ "set", lua_aug_set },
{ NULL, NULL }
};
luaL_newlib(L, augfuncs);
lua_setglobal(L, "aug");
return L;
}
Edit: from the answer I received in the IRC, it seems that I should use metatable , so I'm studying this now.
source
share