From 62a4c8ec5c80aac1d4ed252f9ea9560637714204 Mon Sep 17 00:00:00 2001 From: Dmitry Sapozhnikov <11535558+o-sdn-o@users.noreply.github.com> Date: Fri, 27 Dec 2024 16:21:51 +0500 Subject: [PATCH] #393 WIP: Lua scripting --- src/netxs/desktopio/console.hpp | 17 ++++++++++++++++- src/netxs/desktopio/directvt.hpp | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/netxs/desktopio/console.hpp b/src/netxs/desktopio/console.hpp index 14510a0324..29daf3e53a 100644 --- a/src/netxs/desktopio/console.hpp +++ b/src/netxs/desktopio/console.hpp @@ -1516,7 +1516,22 @@ namespace netxs::ui log(" %name%: id=%%", utf::adjust(object_name, 11, ' ', true), object_ptr->id); } } - scripting_context["gear"] = gear.This(); + //scripting_context["gear"] = gear.This(); + static auto lua = [] + { + auto lua = std::unique_ptr(::luaL_newstate(), &::lua_close); + ::luaL_openlibs(lua.get()); + return lua; + }(); + + auto error = ::luaL_loadbuffer(lua.get(), script_body.data(), script_body.size(), "event") + || ::lua_pcall(lua.get(), 0, 0, 0); + if (error) + { + log("%%%msg%", prompt::lua, ansi::err(::lua_tostring(lua.get(), -1))); + ::lua_pop(lua.get(), 1); // Pop error message from stack. + } + //todo unify //auto cmd_list = utf::split(script_body, '$'); //for (auto cmd : cmd_list) diff --git a/src/netxs/desktopio/directvt.hpp b/src/netxs/desktopio/directvt.hpp index bd9d764adb..72cf4c5721 100644 --- a/src/netxs/desktopio/directvt.hpp +++ b/src/netxs/desktopio/directvt.hpp @@ -13,6 +13,7 @@ namespace netxs::prompt static constexpr auto gui = " gui: "sv; static constexpr auto ack = " ack: "sv; static constexpr auto key = " key: "sv; + static constexpr auto lua = " lua: "sv; static constexpr auto tty = " tty: "sv; static constexpr auto vtm = " vtm: "sv; static constexpr auto xml = " xml: "sv;