mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Make love loaders the first 2, preventing lua loaders from loading the wrong files (issue #283)
This commit is contained in:
+27
-5
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+11
-1
@@ -176,13 +176,23 @@ namespace love
|
||||
**/
|
||||
int luax_register_type(lua_State * L, const char * tname, const luaL_Reg * f = 0);
|
||||
|
||||
/**
|
||||
* Do a table.insert from C
|
||||
* @param L the state
|
||||
* @param tindex the stack index of the table
|
||||
* @param vindex the stack index of the value
|
||||
* @param pos the position to insert it in
|
||||
**/
|
||||
int luax_table_insert(lua_State * L, int tindex, int vindex, int pos = -1);
|
||||
|
||||
/**
|
||||
* Register a new searcher function for package.loaders. This can for instance enable
|
||||
* loading of files through love.filesystem using standard require.
|
||||
* @param L The Lua state.
|
||||
* @param f The searcher function.
|
||||
* @param pos The position to insert the loader in.
|
||||
**/
|
||||
int luax_register_searcher(lua_State * L, lua_CFunction f);
|
||||
int luax_register_searcher(lua_State * L, lua_CFunction f, int pos = -1);
|
||||
|
||||
/**
|
||||
* Creates a new Lua-accessible object of the given type, and put it on the stack.
|
||||
|
||||
@@ -389,8 +389,8 @@ namespace physfs
|
||||
try
|
||||
{
|
||||
instance = new Filesystem();
|
||||
love::luax_register_searcher(L, loader);
|
||||
love::luax_register_searcher(L, extloader);
|
||||
love::luax_register_searcher(L, loader, 1);
|
||||
love::luax_register_searcher(L, extloader, 2);
|
||||
}
|
||||
catch(Exception & e)
|
||||
{
|
||||
@@ -400,7 +400,8 @@ namespace physfs
|
||||
else
|
||||
{
|
||||
instance->retain();
|
||||
love::luax_register_searcher(L, loader);
|
||||
love::luax_register_searcher(L, loader, 1);
|
||||
love::luax_register_searcher(L, extloader, 2);
|
||||
}
|
||||
|
||||
WrappedModule w;
|
||||
|
||||
Reference in New Issue
Block a user