| 206 | |
| 207 | #if CROWN_DEBUG |
| 208 | static int require_internal(lua_State *L) |
| 209 | { |
| 210 | bool already_loaded = false; |
| 211 | const char *module_name = lua_tostring(L, 1); |
| 212 | lua_settop(L, 1); |
| 213 | |
| 214 | lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); |
| 215 | lua_getfield(L, -1, module_name); |
| 216 | already_loaded = lua_toboolean(L, -1); |
| 217 | lua_pop(L, 2); |
| 218 | |
| 219 | lua_getglobal(L, "original_require"); |
| 220 | lua_pushvalue(L, 1); |
| 221 | lua_call(L, 1, 1); |
| 222 | |
| 223 | lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); |
| 224 | lua_getfield(L, -1, module_name); |
| 225 | if (lua_toboolean(L, -1) && !already_loaded) { |
| 226 | lua_pop(L, 2); |
| 227 | lua_getglobal(L, "package"); |
| 228 | lua_getfield(L, -1, "load_order"); |
| 229 | lua_pushstring(L, module_name); |
| 230 | lua_rawseti(L, -2, int(lua_objlen(L, -2) + 1)); |
| 231 | lua_pop(L, 2); // Pop "package.load_order" and "package" |
| 232 | } else { |
| 233 | lua_pop(L, 2); // Pop "_LOADED" and "_LOADED[module]" |
| 234 | } |
| 235 | |
| 236 | lua_remove(L, 1); |
| 237 | return 1; |
| 238 | } |
| 239 | #endif // if CROWN_DEBUG |
| 240 | |
| 241 | LuaEnvironment::LuaEnvironment() |
nothing calls this directly
no test coverage detected