lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>>>>> "bel" == bel  <bel2125@gmail.com> writes:

 bel> Thank you for your explanations. Using the registry works well in
 bel> my tests, and it seems there is no way to break the sandbox from
 bel> inside. In case someone is interested in the code, this worked for
 bel> me:

 bel> static int lua_regkey_dtor;

 bel> lua_pushlightuserdata(L, &lua_regkey_dtor);
 bel> lua_newuserdata(L, 0);
 bel> lua_newtable(L);
 bel> lua_pushliteral(L, "__gc");
 bel> lua_pushlightuserdata(L, my_luaclose_argument);
 bel> lua_pushcclosure(L, luaclose_mylib, 1);
 bel> lua_rawset(L, -3);
 bel> lua_setmetatable(L, -2);
 bel> lua_settable(L, LUA_REGISTRYINDEX);

You can simplify:

    lua_newuserdata(L, 0);
    lua_newtable(L);
    lua_pushlightuserdata(L, my_luaclose_argument);
    lua_pushcclosure(L, luaclose_mylib, 1);
    lua_setfield(L, -2, "__gc");
    lua_setmetatable(L, -2);
    lua_rawsetp(L, LUA_REGISTRYINDEX, &lua_regkey_dtor);

-- 
Andrew.