All-in-One Lua loader

This commit is contained in:
Ilya Chelyadin 2021-05-01 03:11:28 +03:00 committed by bjorn
parent a45fab4416
commit ce3470a6e6
1 changed files with 15 additions and 1 deletions

View File

@ -409,7 +409,7 @@ static int luaLoader(lua_State* L) {
return 0;
}
static int libLoader(lua_State* L) {
static int libLoaderCommon(lua_State* L, bool allInOneFlag) {
#ifdef _WIN32
const char* extension = ".dll";
#else
@ -452,6 +452,7 @@ static int libLoader(lua_State* L) {
#endif
for (const char* m = module; *m && length < sizeof(path); m++, length++) {
if (allInOneFlag && *m == '.') break;
*p++ = *m == '.' ? LOVR_PATH_SEP : *m;
}
@ -482,6 +483,18 @@ static int libLoader(lua_State* L) {
return 1;
}
static int libLoader(lua_State* L) {
const char* module = lua_tostring(L, 1);
bool allInOneFlag = false;
return libLoaderCommon(L, allInOneFlag);
}
static int libLoaderAllInOne(lua_State* L) {
const char* module = lua_tostring(L, 1);
bool allInOneFlag = true;
return libLoaderCommon(L, allInOneFlag);
}
int luaopen_lovr_filesystem(lua_State* L) {
const char* archive = NULL;
@ -501,5 +514,6 @@ int luaopen_lovr_filesystem(lua_State* L) {
luax_register(L, lovrFilesystem);
luax_registerloader(L, luaLoader, 2);
luax_registerloader(L, libLoader, 3);
luax_registerloader(L, libLoaderAllInOne, 4);
return 1;
}