Make love loaders the first 2, preventing lua loaders from loading the wrong files (issue #283)

This commit is contained in:
Bart van Strien
2011-08-22 18:04:19 +02:00
parent 515596d389
commit 09367dc3bd
3 changed files with 42 additions and 9 deletions
+27 -5
View File
@@ -215,8 +215,32 @@ namespace love
lua_pop(L, 1); // Pops metatable.
return 0;
}
int luax_table_insert(lua_State * L, int tindex, int vindex, int pos)
{
if (tindex < 0)
tindex = lua_gettop(L)+1+tindex;
if (vindex < 0)
vindex = lua_gettop(L)+1+vindex;
if (pos == -1)
{
lua_pushvalue(L, vindex);
lua_rawseti(L, tindex, lua_objlen(L, tindex)+1);
return 0;
}
else if (pos < 0)
pos = lua_objlen(L, tindex)+1+pos;
for (int i = lua_objlen(L, tindex)+1; i > pos; i--)
{
lua_rawgeti(L, tindex, i-1);
lua_rawseti(L, tindex, i);
}
lua_pushvalue(L, vindex);
lua_rawseti(L, tindex, pos);
return 0;
}
int luax_register_searcher(lua_State * L, lua_CFunction f)
int luax_register_searcher(lua_State * L, lua_CFunction f, int pos)
{
// Add the package loader to the package.loaders table.
lua_getglobal(L, "package");
@@ -229,11 +253,9 @@ namespace love
if(lua_isnil(L, -1))
return luaL_error(L, "Can't register searcher: package.loaders table does not exist.");
int len = lua_objlen(L, -1);
lua_pushinteger(L, len+1);
lua_pushcfunction(L, f);
lua_settable(L, -3);
lua_pop(L, 2);
luax_table_insert(L, -2, -1, pos);
lua_pop(L, 3);
return 0;
}