diff options
| author | Hailey Somerville <hailey@hailey.lol> | 2024-02-04 14:28:54 +1100 |
|---|---|---|
| committer | Hailey Somerville <hailey@hailey.lol> | 2024-02-05 22:10:21 +1100 |
| commit | c29b5521ed189c9c03367a83157ab146f3a03289 (patch) | |
| tree | ae0acd79854714f7aa24bbc86c1afcda821280cc /src/app_console/app_console.cpp | |
| parent | e2a6c3b5b35bb0038fbb61a154cbae3e5625cf54 (diff) | |
| download | tangara-fw-c29b5521ed189c9c03367a83157ab146f3a03289.tar.gz | |
add luarun command
Diffstat (limited to 'src/app_console/app_console.cpp')
| -rw-r--r-- | src/app_console/app_console.cpp | 31 |
1 files 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<lua::LuaThread> 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 { |
