SHOW:
|
|
- or go back to the newest paste.
1 | class LuaSlot { | |
2 | public: | |
3 | static inline sigc::slot<void> Wrap(lua_State *l) { | |
4 | lua_getfield(l, LUA_REGISTRYINDEX, "PiUISlot"); | |
5 | if (lua_isnil(l, -1)) { | |
6 | lua_newtable(l); | |
7 | lua_pushvalue(l, -1); | |
8 | lua_setfield(l, LUA_REGISTRYINDEX, "PiUISlot"); | |
9 | } | |
10 | lua_pushvalue(l, -2); | |
11 | int ref = luaL_ref(l, -2); | |
12 | lua_pop(l, 1); | |
13 | return sigc::bind(sigc::ptr_fun(&trampoline), l, ref); | |
14 | } | |
15 | ||
16 | private: | |
17 | static inline void trampoline(lua_State *l, int ref) { | |
18 | lua_getfield(l, LUA_REGISTRYINDEX, "PiUISlot"); | |
19 | lua_rawgeti(l, -1, ref); | |
20 | luaL_unref(l, -2, ref); | |
21 | lua_remove(l, -2); | |
22 | - | lua_pop(l, 2); |
22 | + | |
23 | } | |
24 | }; |