From d34e33904d1e967149174de29f782b22209d8d33 Mon Sep 17 00:00:00 2001 From: PeachyPeach <72323920+PeachyPeachSM64@users.noreply.github.com> Date: Tue, 28 Mar 2023 00:50:49 +0200 Subject: [PATCH] /luaf; fix compilation issues with audio and debug + dev (#328) /luaf command to execute lua code from a file. Note that this command doesn't load the file the same way mod files are loaded, so no access to gGlobalSyncTable and gPlayerSyncTable. hook_chat_command cannot be called, but hook_event can. Fix some compilation issues --- Makefile | 3 ++- src/pc/chat_commands.c | 6 ++++++ src/pc/lua/smlua.c | 2 +- src/pc/lua/smlua.h | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 276c1b2a..72305d3f 100644 --- a/Makefile +++ b/Makefile @@ -1363,7 +1363,8 @@ endif $(BUILD_DIR)/%.table: %.aiff $(call print,Extracting codebook:,$<,$@) - $(V)$(AIFF_EXTRACT_CODEBOOK) $< >$@ + $(V)$(shell while ! test -s $@.tmp ; do $(AIFF_EXTRACT_CODEBOOK) $< >$@.tmp ; done) + $(V)$(shell mv $@.tmp $@ ) $(call print,Piping:,$<,$@.inc.c) $(V)hexdump -v -e '1/1 "0x%X,"' $< > $@.inc.c $(V)echo >> $@.inc.c diff --git a/src/pc/chat_commands.c b/src/pc/chat_commands.c index becb4b2d..f843f5b0 100644 --- a/src/pc/chat_commands.c +++ b/src/pc/chat_commands.c @@ -317,6 +317,11 @@ bool exec_chat_command(char* command) { smlua_exec_str(&command[5]); return true; } + + if (str_starts_with("/luaf ", command)) { + smlua_exec_file(&command[6]); + return true; + } #endif return smlua_call_chat_command_hook(command); @@ -333,6 +338,7 @@ void display_chat_commands(void) { #if defined(DEVELOPMENT) djui_chat_message_create("/warp [LEVEL] [AREA] [ACT] - Level can be either a numeric value or a shorthand name"); djui_chat_message_create("/lua [LUA] - Execute Lua code from a string"); + djui_chat_message_create("/luaf [FILENAME] - Execute Lua code from a file"); #endif if (sConfirming != CCC_NONE) { djui_chat_message_create("/confirm"); } smlua_display_chat_commands(); diff --git a/src/pc/lua/smlua.c b/src/pc/lua/smlua.c index 6063d5af..7c0836d0 100644 --- a/src/pc/lua/smlua.c +++ b/src/pc/lua/smlua.c @@ -43,7 +43,7 @@ int smlua_pcall(lua_State* L, int nargs, int nresults, UNUSED int errfunc) { return rc; } -static void smlua_exec_file(char* path) { +void smlua_exec_file(char* path) { lua_State* L = gLuaState; if (luaL_dofile(L, path) != LUA_OK) { LOG_LUA("Failed to load lua file '%s'.", path); diff --git a/src/pc/lua/smlua.h b/src/pc/lua/smlua.h index 49a4517e..38ee4911 100644 --- a/src/pc/lua/smlua.h +++ b/src/pc/lua/smlua.h @@ -40,6 +40,7 @@ extern struct Mod* gLuaLastHookMod; void smlua_mod_error(void); int smlua_error_handler(UNUSED lua_State* L); int smlua_pcall(lua_State* L, int nargs, int nresults, int errfunc); +void smlua_exec_file(char* path); void smlua_exec_str(char* str); void smlua_init(void);