elua: load modules from local dirs first

This fixes cases when running scripts locally - local modules
are preferred over systemwide, avoiding possibly outdated system
scripts from being run.
This commit is contained in:
Daniel Kolesa 2016-08-08 14:38:08 +01:00
parent a5fd63067d
commit d27c27528c
1 changed files with 14 additions and 9 deletions

View File

@ -499,28 +499,33 @@ _elua_module_system_init(lua_State *L)
const char *modpath = es->moddir; const char *modpath = es->moddir;
const char *appspath = es->appsdir; const char *appspath = es->appsdir;
Eina_Stringshare *data = NULL; Eina_Stringshare *data = NULL;
int n = 4;
if (!corepath || !modpath || !appspath) if (!corepath || !modpath || !appspath)
return 0; return 0;
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
es->requireref = luaL_ref(L, LUA_REGISTRYINDEX); es->requireref = luaL_ref(L, LUA_REGISTRYINDEX);
lua_pushvalue(L, 2); lua_pushvalue(L, 2);
es->apploadref = luaL_ref(L, LUA_REGISTRYINDEX); es->apploadref = luaL_ref(L, LUA_REGISTRYINDEX);
lua_pushfstring(L, "%s/?.lua;", corepath);
/* module path, local directories take priority */
int n = 0;
lua_pushvalue(L, 3); ++n;
lua_pushfstring(L, ";%s/?.lua", corepath); ++n;
EINA_LIST_FREE(es->lincs, data) EINA_LIST_FREE(es->lincs, data)
{ {
lua_pushfstring(L, "%s/?.lua;", data); lua_pushfstring(L, ";%s/?.lua", data);
eina_stringshare_del(data); eina_stringshare_del(data);
++n; ++n;
} }
lua_pushfstring(L, "%s/?.eo.lua;", modpath); lua_pushfstring(L, ";%s/?.eo.lua", modpath); ++n;
lua_pushfstring(L, "%s/?.lua;", modpath); lua_pushfstring(L, ";%s/?.lua", modpath); ++n;
lua_pushfstring(L, "%s/?.lua;", appspath); lua_pushfstring(L, ";%s/?.lua", appspath); ++n;
lua_pushvalue(L, 3); lua_concat(L, n);
lua_concat(L, n + 1);
lua_pushfstring(L, "%s/?.lua;", appspath); /* apps path, local directory takes priority as well */
lua_pushvalue(L, 4); lua_pushvalue(L, 4);
lua_pushfstring(L, ";%s/?.lua", appspath);
lua_concat(L, 2); lua_concat(L, 2);
return 2; return 2;
} }