Skip to content

Commit

Permalink
directvt#393 WIP: Lua scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Dec 27, 2024
1 parent b941bfe commit 62a4c8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/netxs/desktopio/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<lua_State, decltype(&::lua_close)>(::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)
Expand Down
1 change: 1 addition & 0 deletions src/netxs/desktopio/directvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 62a4c8e

Please sign in to comment.