diff options
| author | cooljqln <cooljqln@noreply.codeberg.org> | 2024-02-05 23:24:32 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2024-02-05 23:24:32 +0000 |
| commit | 8c628590b2c7b573aa8bea18f1f0eaa48eb58102 (patch) | |
| tree | 59336d29cc1623e8c96aca31bccf6a47e1a7a153 /src/app_console | |
| parent | 2184b6c5f7fb026b52508ec1e234c7f32d3ace25 (diff) | |
| parent | c29b5521ed189c9c03367a83157ab146f3a03289 (diff) | |
| download | tangara-fw-8c628590b2c7b573aa8bea18f1f0eaa48eb58102.tar.gz | |
Merge pull request 'Add luarun command' (#28) from hails/tangara-fw:luarun into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/28
Diffstat (limited to 'src/app_console')
| -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 { |
