Created
April 21, 2012 22:26
-
-
Save ScatteredRay/2439988 to your computer and use it in GitHub Desktop.
package.loaders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int lua_load_module(lua_State* lua) | |
{ | |
const char* lua_file = lua_tostring(lua, -1); | |
lua_pop(lua, 1); | |
luaL_loadfile(lua, lua_file); | |
return 1; | |
} | |
int lua_find_module(lua_State* lua) | |
{ | |
const char* package = lua_tostring(lua, -1); | |
const char* lua_file = get_resource_path(resource_manager, "script", package, "lua"); | |
lua_pop(lua, 1); | |
lua_pushcfunction(lua, lua_load_module); | |
lua_pushstring(lua, lua_file); | |
return 2; | |
} | |
void lua_setup_loader(lua_State* lua) | |
{ | |
lua_getglobal(lua, "package"); | |
lua_getfield(lua, -1, "searchers"); | |
lua_pushcfunction(lua, lua_find_module); | |
lua_rawseti(lua, -2, 1); | |
lua_pop(lua, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment