| 261 | } |
| 262 | |
| 263 | void LuaStack::addLuaLoader(lua_CFunction func) |
| 264 | { |
| 265 | if (!func) |
| 266 | return; |
| 267 | |
| 268 | #if LUA_VERSION_NUM >= 504 || (LUA_VERSION_NUM >= 502 && !defined(LUA_COMPAT_LOADERS)) |
| 269 | const char* realname = "searchers"; |
| 270 | #else |
| 271 | const char* realname = "loaders"; |
| 272 | #endif |
| 273 | |
| 274 | // stack content after the invoking of the function |
| 275 | // get loader table |
| 276 | lua_getglobal(_state, "package"); /* L: package */ |
| 277 | lua_getfield(_state, -1, realname); /* L: package, loaders */ |
| 278 | |
| 279 | // insert loader into index 2 |
| 280 | lua_pushcfunction(_state, func); /* L: package, loaders, func */ |
| 281 | for (int i = (int)(lua_objlen(_state, -2) + 1); i > 2; --i) |
| 282 | { |
| 283 | lua_rawgeti(_state, -2, i - 1); /* L: package, loaders, func, function */ |
| 284 | // we call lua_rawgeti, so the loader table now is at -3 |
| 285 | lua_rawseti(_state, -3, i); /* L: package, loaders, func */ |
| 286 | } |
| 287 | lua_rawseti(_state, -2, 2); /* L: package, loaders */ |
| 288 | |
| 289 | // set loaders into package |
| 290 | lua_setfield(_state, -2, realname); /* L: package */ |
| 291 | |
| 292 | lua_pop(_state, 1); |
| 293 | } |
| 294 | |
| 295 | void LuaStack::removeScriptObjectByObject(Object* pObj) |
| 296 | { |
nothing calls this directly
no test coverage detected