Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LuaSlot {
- public:
- static inline sigc::slot<void> Wrap(lua_State *l, int idx) {
- idx = lua_absindex(l, idx);
- lua_getfield(l, LUA_REGISTRYINDEX, "PiUISlot");
- if (lua_isnil(l, -1)) {
- lua_pop(l, 1);
- lua_newtable(l);
- lua_pushvalue(l, -1);
- lua_setfield(l, LUA_REGISTRYINDEX, "PiUISlot");
- }
- lua_pushvalue(l, idx);
- int ref = luaL_ref(l, -2);
- lua_pop(l, 1);
- return sigc::bind(sigc::ptr_fun(&trampoline), l, ref);
- }
- private:
- static inline void trampoline(lua_State *l, int ref) {
- lua_getfield(l, LUA_REGISTRYINDEX, "PiUISlot");
- lua_rawgeti(l, -1, ref);
- luaL_unref(l, -2, ref);
- lua_call(l, 0, 0);
- lua_pop(l, 1);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement