| 266 | } |
| 267 | |
| 268 | void LuaEnvironment::load_libs() |
| 269 | { |
| 270 | lua_gc(L, LUA_GCSTOP, 0); |
| 271 | |
| 272 | // Open default libraries |
| 273 | lua_pushcfunction(L, luaopen_base); |
| 274 | lua_pushstring(L, ""); |
| 275 | lua_call(L, 1, 0); |
| 276 | lua_pushcfunction(L, luaopen_package); |
| 277 | lua_pushstring(L, LUA_LOADLIBNAME); |
| 278 | lua_call(L, 1, 0); |
| 279 | lua_pushcfunction(L, luaopen_table); |
| 280 | lua_pushstring(L, LUA_TABLIBNAME); |
| 281 | lua_call(L, 1, 0); |
| 282 | lua_pushcfunction(L, luaopen_string); |
| 283 | lua_pushstring(L, LUA_STRLIBNAME); |
| 284 | lua_call(L, 1, 0); |
| 285 | lua_pushcfunction(L, luaopen_math); |
| 286 | lua_pushstring(L, LUA_MATHLIBNAME); |
| 287 | lua_call(L, 1, 0); |
| 288 | lua_pushcfunction(L, luaopen_debug); |
| 289 | lua_pushstring(L, LUA_DBLIBNAME); |
| 290 | lua_call(L, 1, 0); |
| 291 | lua_pushcfunction(L, luaopen_os); |
| 292 | lua_pushstring(L, LUA_OSLIBNAME); |
| 293 | lua_call(L, 1, 0); |
| 294 | #if CROWN_USE_LUAJIT |
| 295 | lua_pushcfunction(L, luaopen_bit); |
| 296 | lua_pushstring(L, LUA_BITLIBNAME); |
| 297 | lua_call(L, 1, 0); |
| 298 | lua_pushcfunction(L, luaopen_jit); |
| 299 | lua_pushstring(L, LUA_JITLIBNAME); |
| 300 | lua_call(L, 1, 0); |
| 301 | #endif |
| 302 | |
| 303 | // Override print to redirect output to logging system |
| 304 | add_module_function("_G", "print", luaB_print); |
| 305 | |
| 306 | // Register crown libraries |
| 307 | load_api(*this); |
| 308 | |
| 309 | // Register custom loader |
| 310 | lua_getglobal(L, "package"); |
| 311 | lua_getfield(L, -1, "loaders"); |
| 312 | lua_pushcfunction(L, loader); |
| 313 | lua_rawseti(L, -2, 1); // package.loaders[1] = loader |
| 314 | lua_pushnil(L); |
| 315 | lua_rawseti(L, -2, 2); // package.loaders[2] = nil |
| 316 | lua_pushnil(L); |
| 317 | lua_rawseti(L, -2, 3); // package.loaders[3] = nil |
| 318 | lua_pushnil(L); |
| 319 | lua_rawseti(L, -2, 4); // package.loaders[4] = nil |
| 320 | lua_pop(L, 1); // pop "package.loaders" |
| 321 | #if CROWN_DEBUG |
| 322 | // Create new empty table to store package load order |
| 323 | lua_newtable(L); |
| 324 | lua_setfield(L, -2, "load_order"); // package.load_order = {} |
| 325 |
no test coverage detected