/apps/twnlua: replace dots to forward slashes in module lookup

This commit is contained in:
veclavtalica 2025-02-02 05:00:54 +03:00
parent 732a3579b0
commit 87b33c2e0c

View File

@ -14,10 +14,19 @@ void bindgen_upload_context(lua_State *L);
/* require will go through physicsfs exclusively so that scripts can be in the data dir */
/* TODO: allow for bytecode files */
/* TODO: support .lua suffixes files? */
static int physfs_loader(lua_State *L) {
const char *name = luaL_checkstring(L, 1);
/* replace dots with path slashes */
char *path_copy = SDL_strdup(name);
char *ch = NULL;
while ((ch = SDL_strchr(path_copy, '.')))
*ch = '/';
char *final_path = NULL;
SDL_asprintf(&final_path, "/scripts/%s.lua", name);
SDL_asprintf(&final_path, "/scripts/%s.lua", path_copy);
SDL_free(path_copy);
if (!file_exists(final_path)) {
char *error_message = NULL;