/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 6253241e4a
commit d34e33904d
4 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -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();

View File

@ -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);

View File

@ -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);