/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
This commit is contained in:
PeachyPeach 2023-03-28 00:50:49 +02:00 committed by GitHub
parent 32e39516d6
commit b738cf73f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 2 deletions

View file

@ -1363,7 +1363,8 @@ endif
$(BUILD_DIR)/%.table: %.aiff $(BUILD_DIR)/%.table: %.aiff
$(call print,Extracting codebook:,$<,$@) $(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) $(call print,Piping:,$<,$@.inc.c)
$(V)hexdump -v -e '1/1 "0x%X,"' $< > $@.inc.c $(V)hexdump -v -e '1/1 "0x%X,"' $< > $@.inc.c
$(V)echo >> $@.inc.c $(V)echo >> $@.inc.c

View file

@ -317,6 +317,11 @@ bool exec_chat_command(char* command) {
smlua_exec_str(&command[5]); smlua_exec_str(&command[5]);
return true; return true;
} }
if (str_starts_with("/luaf ", command)) {
smlua_exec_file(&command[6]);
return true;
}
#endif #endif
return smlua_call_chat_command_hook(command); return smlua_call_chat_command_hook(command);
@ -333,6 +338,7 @@ void display_chat_commands(void) {
#if defined(DEVELOPMENT) #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("/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("/lua [LUA] - Execute Lua code from a string");
djui_chat_message_create("/luaf [FILENAME] - Execute Lua code from a file");
#endif #endif
if (sConfirming != CCC_NONE) { djui_chat_message_create("/confirm"); } if (sConfirming != CCC_NONE) { djui_chat_message_create("/confirm"); }
smlua_display_chat_commands(); smlua_display_chat_commands();

View file

@ -43,7 +43,7 @@ int smlua_pcall(lua_State* L, int nargs, int nresults, UNUSED int errfunc) {
return rc; return rc;
} }
static void smlua_exec_file(char* path) { void smlua_exec_file(char* path) {
lua_State* L = gLuaState; lua_State* L = gLuaState;
if (luaL_dofile(L, path) != LUA_OK) { if (luaL_dofile(L, path) != LUA_OK) {
LOG_LUA("Failed to load lua file '%s'.", path); LOG_LUA("Failed to load lua file '%s'.", path);

View file

@ -40,6 +40,7 @@ extern struct Mod* gLuaLastHookMod;
void smlua_mod_error(void); void smlua_mod_error(void);
int smlua_error_handler(UNUSED lua_State* L); int smlua_error_handler(UNUSED lua_State* L);
int smlua_pcall(lua_State* L, int nargs, int nresults, int errfunc); 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_exec_str(char* str);
void smlua_init(void); void smlua_init(void);