From c29b5521ed189c9c03367a83157ab146f3a03289 Mon Sep 17 00:00:00 2001 From: Hailey Somerville Date: Sun, 4 Feb 2024 14:28:54 +1100 Subject: [PATCH] add luarun command --- src/app_console/app_console.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/app_console/app_console.cpp b/src/app_console/app_console.cpp index 4b755c67..4742c940 100644 --- a/src/app_console/app_console.cpp +++ b/src/app_console/app_console.cpp @@ -628,14 +628,41 @@ int CmdLua(int argc, char** argv) { return 0; } +int CmdLuaRun(int argc, char** argv) { + std::unique_ptr context{ + lua::LuaThread::Start(*AppConsole::sServices)}; + if (!context) { + return 1; + } + + if (argc != 2) { + std::cout << "luarun expects 1 argument" << std::endl; + return 1; + } + + if (context->RunString(argv[1])) { + return 0; + } else { + return 1; + } +} + void RegisterLua() { - esp_console_cmd_t cmd{ + esp_console_cmd_t cmd_lua{ .command = "lua", .help = "Executes a lua script. With no args, begins a lua repl session", .hint = NULL, .func = &CmdLua, .argtable = NULL}; - esp_console_cmd_register(&cmd); + esp_console_cmd_register(&cmd_lua); + + esp_console_cmd_t cmd_luarun{ + .command = "luarun", + .help = "Executes a string of lua source code given as argument", + .hint = NULL, + .func = &CmdLuaRun, + .argtable = NULL}; + esp_console_cmd_register(&cmd_luarun); } auto AppConsole::RegisterExtraComponents() -> void {