| 183 | } |
| 184 | |
| 185 | static std::shared_ptr<std::string> create_lambda_handler(State* L) { |
| 186 | auto ptr = reinterpret_cast<ptrdiff_t>(topointer(L, -1)); |
| 187 | auto name = util::mangleid(ptr); |
| 188 | getglobal(L, LAMBDAS_TABLE); |
| 189 | pushvalue(L, -2); |
| 190 | setfield(L, name); |
| 191 | pop(L, 2); |
| 192 | |
| 193 | return std::shared_ptr<std::string>(new std::string(name), [=](std::string* name) { |
| 194 | getglobal(L, LAMBDAS_TABLE); |
| 195 | pushnil(L); |
| 196 | setfield(L, *name); |
| 197 | pop(L); |
| 198 | delete name; |
| 199 | }); |
| 200 | } |
| 201 | |
| 202 | runnable lua::create_runnable(State* L) { |
| 203 | auto funcptr = create_lambda_handler(L); |