Skip to content

Instantly share code, notes, and snippets.

@ScatteredRay
Created April 21, 2012 22:26
Show Gist options
  • Save ScatteredRay/2439988 to your computer and use it in GitHub Desktop.
Save ScatteredRay/2439988 to your computer and use it in GitHub Desktop.
package.loaders
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