From 87b33c2e0c6f4c28ce45c5e561c8ef9a912aa95c Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Sun, 2 Feb 2025 05:00:54 +0300 Subject: [PATCH] /apps/twnlua: replace dots to forward slashes in module lookup --- apps/twnlua/game.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/twnlua/game.c b/apps/twnlua/game.c index 6b091b3..1e2a530 100644 --- a/apps/twnlua/game.c +++ b/apps/twnlua/game.c @@ -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;