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
custom
cooljqln 1 year ago
commit 8c628590b2
  1. 31
      src/app_console/app_console.cpp

@ -628,14 +628,41 @@ int CmdLua(int argc, char** argv) {
return 0; 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() { void RegisterLua() {
esp_console_cmd_t cmd{ esp_console_cmd_t cmd_lua{
.command = "lua", .command = "lua",
.help = "Executes a lua script. With no args, begins a lua repl session", .help = "Executes a lua script. With no args, begins a lua repl session",
.hint = NULL, .hint = NULL,
.func = &CmdLua, .func = &CmdLua,
.argtable = NULL}; .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 { auto AppConsole::RegisterExtraComponents() -> void {

Loading…
Cancel
Save