Skip to content

Instantly share code, notes, and snippets.

@ennorehling
Created February 29, 2012 07:02
Show Gist options
  • Save ennorehling/1938692 to your computer and use it in GitHub Desktop.
Save ennorehling/1938692 to your computer and use it in GitHub Desktop.
static void register_loader(lua_State * L, const char * files_dir) {
char custom_path[PATH_MAX+1];
lua_getglobal(L, "package");
lua_getfield(L, -1, "loaders");
int num_loaders = lua_objlen(L, -1);
lua_pushcfunction(L, asset_loader);
lua_rawseti(L, -2, 2);
lua_pop(L, 1);
lua_getfield(L, -1, "path");
custom_path[0] = ';';
strcpy(custom_path+1, files_dir);
strcat(custom_path, "/?.lua");
lua_pushstring(L, custom_path);
lua_concat(L, 2);
lua_setfield(L, -2, "path");
lua_pop(L, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment