diff --git a/lutro.c b/lutro.c index b02b069..570cd04 100644 --- a/lutro.c +++ b/lutro.c @@ -388,21 +388,29 @@ int lutro_unzip(const char *path, const char *extraction_directory) int lutro_load(const char *path) { char mainfile[PATH_MAX_LENGTH]; + // conf.lua https://love2d.org/wiki/Config_Files + char conffile[PATH_MAX_LENGTH]; char gamedir[PATH_MAX_LENGTH]; strlcpy(mainfile, path, PATH_MAX_LENGTH); + strlcpy(conffile, path, PATH_MAX_LENGTH); strlcpy(gamedir, path, PATH_MAX_LENGTH); - if (path_is_directory(mainfile)) + if (path_is_directory(mainfile)) { fill_pathname_join(mainfile, gamedir, "main.lua", sizeof(mainfile)); - else + fill_pathname_join(conffile, gamedir, "conf.lua", sizeof(conffile)); + } + else { path_basedir(gamedir); + } if (!strcmp(path_get_extension(mainfile), "lutro")) { fill_pathname(gamedir, mainfile, "/", sizeof(gamedir)); + fill_pathname(gamedir, conffile, "/", sizeof(gamedir)); lutro_unzip(mainfile, gamedir); fill_pathname_join(mainfile, gamedir, "main.lua", sizeof(mainfile)); + fill_pathname_join(conffile, gamedir, "conf.lua", sizeof(conffile)); } fill_pathname_slash(gamedir, sizeof(gamedir)); @@ -411,6 +419,10 @@ int lutro_load(const char *path) snprintf(package_path, PATH_MAX_LENGTH, ";%s?.lua;%s?/init.lua", gamedir, gamedir); lutro_set_package_path(L, package_path); + // Load the configuration file, ignoring any errors. + dofile(L, conffile); + + // Now that configuration is in place, load main.lua. if(dofile(L, mainfile)) { fprintf(stderr, "%s\n", lua_tostring(L, -1)); diff --git a/test.lutro b/test.lutro new file mode 100644 index 0000000..448378d Binary files /dev/null and b/test.lutro differ diff --git a/test/conf.lua b/test/conf.lua new file mode 100644 index 0000000..8dd6e60 --- /dev/null +++ b/test/conf.lua @@ -0,0 +1,4 @@ +function lutro.conf(t) + t.width = 640 + t.height = 480 +end diff --git a/test/main.lua b/test/main.lua index cf7cabd..afce461 100644 --- a/test/main.lua +++ b/test/main.lua @@ -17,9 +17,8 @@ local intervalTime = 2.5 local joystickButton = 0 local keypressed = "" -function lutro.conf(t) - t.width = 640 - t.height = 480 +function lutro.load() + lutro.graphics.setBackgroundColor(0, 0, 0) -- Initiate all available test states. for i, state in ipairs(availableStates) do @@ -27,10 +26,6 @@ function lutro.conf(t) test['name'] = "lutro." .. string.gsub(state, "/", ".") table.insert(states, test) end -end - -function lutro.load() - lutro.graphics.setBackgroundColor(0, 0, 0) -- Load all states. for i, state in ipairs(states) do