From 0c7de174d21ab8556cbacc49843c179a848cc348 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Wed, 8 Mar 2023 19:26:03 -0500 Subject: [PATCH] Add /lua to chat commands with dev flag --- src/pc/chat_commands.c | 6 ++++++ src/pc/lua/smlua.c | 2 +- src/pc/lua/smlua.h | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pc/chat_commands.c b/src/pc/chat_commands.c index df498d7d2..becb4b2db 100644 --- a/src/pc/chat_commands.c +++ b/src/pc/chat_commands.c @@ -312,6 +312,11 @@ bool exec_chat_command(char* command) { djui_chat_message_create(message); return true; } + + if (str_starts_with("/lua ", command)) { + smlua_exec_str(&command[5]); + return true; + } #endif return smlua_call_chat_command_hook(command); @@ -327,6 +332,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"); #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 f8abc8972..57c9cf4e7 100644 --- a/src/pc/lua/smlua.c +++ b/src/pc/lua/smlua.c @@ -52,7 +52,7 @@ static void smlua_exec_file(char* path) { lua_pop(L, lua_gettop(L)); } -static void smlua_exec_str(char* str) { +void smlua_exec_str(char* str) { lua_State* L = gLuaState; if (luaL_dostring(L, str) != LUA_OK) { LOG_LUA("Failed to load lua string."); diff --git a/src/pc/lua/smlua.h b/src/pc/lua/smlua.h index d757f207a..49a4517ea 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_str(char* str); void smlua_init(void); void smlua_update(void);