| 213 | } |
| 214 | |
| 215 | void InitializeModule(lua_State* L) |
| 216 | { |
| 217 | int top = lua_gettop(L); |
| 218 | (void) top; |
| 219 | lua_getfield(L, LUA_GLOBALSINDEX, "package"); |
| 220 | if (lua_istable(L, -1)) |
| 221 | { |
| 222 | assert(lua_istable(L, -1)); |
| 223 | |
| 224 | // NOTE: We replace package.loaders table |
| 225 | // only our custom loader |
| 226 | lua_newtable(L); |
| 227 | lua_pushcfunction(L, LoadModule); |
| 228 | lua_rawseti(L, -2, 1); |
| 229 | lua_setfield(L, -2, "loaders"); |
| 230 | lua_pop(L, 1); |
| 231 | } |
| 232 | else |
| 233 | { |
| 234 | // Bare-bone lua, no libs opened. We don't created the package table. |
| 235 | lua_pop(L, 1); |
| 236 | } |
| 237 | assert(top == lua_gettop(L)); |
| 238 | } |
| 239 | |
| 240 | } |
no test coverage detected