diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 8ddceffed..95d80b6a9 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -11605,7 +11605,7 @@ function get_active_mod() end --- @param mod Mod ---- @param subDirectory string +--- @param subDirectory? string --- @return table --- Gets all files a mod contains function get_mod_files(mod, subDirectory) diff --git a/docs/lua/functions-7.md b/docs/lua/functions-7.md index b3b10e893..94a807cd2 100644 --- a/docs/lua/functions-7.md +++ b/docs/lua/functions-7.md @@ -2104,7 +2104,7 @@ Gets all files a mod contains - `table` ### C Prototype -`LuaTable get_mod_files(struct Mod* mod, const char* subDirectory);` +`LuaTable get_mod_files(struct Mod* mod, OPTIONAL const char* subDirectory);` [:arrow_up_small:](#) diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 319ee4efc..b0efdfb8c 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -34633,15 +34633,18 @@ int smlua_func_get_mod_files(lua_State* L) { if (L == NULL) { return 0; } int top = lua_gettop(L); - if (top != 2) { - LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "get_mod_files", 2, top); + if (top < 1 || top > 2) { + LOG_LUA_LINE("Improper param count for '%s': Expected between %u and %u, Received %u", "get_mod_files", 1, 2, top); return 0; } struct Mod* mod = (struct Mod*)smlua_to_cobject(L, 1, LOT_MOD); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "get_mod_files"); return 0; } - const char* subDirectory = smlua_to_string(L, 2); - if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "get_mod_files"); return 0; } + const char* subDirectory = (const char*) NULL; + if (top >= 2) { + subDirectory = smlua_to_string(L, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "get_mod_files"); return 0; } + } smlua_push_lua_table(L, get_mod_files(mod, subDirectory)); diff --git a/src/pc/lua/utils/smlua_misc_utils.c b/src/pc/lua/utils/smlua_misc_utils.c index e16506914..85a86889a 100644 --- a/src/pc/lua/utils/smlua_misc_utils.c +++ b/src/pc/lua/utils/smlua_misc_utils.c @@ -601,7 +601,7 @@ struct Mod* get_active_mod(void) { return gLuaActiveMod; } -LuaTable get_mod_files(struct Mod* mod, const char* subDirectory) { +LuaTable get_mod_files(struct Mod* mod, OPTIONAL const char* subDirectory) { if (!mod || !subDirectory) { struct lua_State *L = gLuaState; if (L) { diff --git a/src/pc/lua/utils/smlua_misc_utils.h b/src/pc/lua/utils/smlua_misc_utils.h index a768dd96a..773fb4059 100644 --- a/src/pc/lua/utils/smlua_misc_utils.h +++ b/src/pc/lua/utils/smlua_misc_utils.h @@ -244,7 +244,7 @@ bool mod_file_exists(const char* filename); /* |description|Gets the mod currently being processed|descriptionEnd| */ struct Mod* get_active_mod(void); /* |description|Gets all files a mod contains|descriptionEnd| */ -LuaTable get_mod_files(struct Mod* mod, const char* subDirectory); +LuaTable get_mod_files(struct Mod* mod, OPTIONAL const char* subDirectory); /* |description|Sets the window title to a custom title|descriptionEnd| */ void set_window_title(const char* title);