Skip to content

Commit

Permalink
directvt#393 WIP: Unify pro::luafx
Browse files Browse the repository at this point in the history
  • Loading branch information
o-sdn-o committed Jan 3, 2025
1 parent 5df22f1 commit 6aa0e47
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 43 deletions.
11 changes: 11 additions & 0 deletions src/netxs/desktopio/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,17 @@ namespace netxs::ui
gear.board::brush = props.clip_preview_clrs;
gear.board::alpha = props.clip_preview_alfa;
gear.mouse::delay = props.dblclick_timeout;

static auto proc_map = pro::luafx::fxmap<hids>
{
{ "IsKeyRepeated", [](hids& gear, auto lua)
{
auto repeated = gear.keystat == input::key::repeated;
::lua_settop(lua, 0);
::lua_pushboolean(lua, repeated);
}},
};
gear.base::plugin<pro::luafx>(proc_map);
}
auto& [_id, gear_ptr] = *gear_it;
gear_ptr->hids::take(device);
Expand Down
33 changes: 33 additions & 0 deletions src/netxs/desktopio/controls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2873,6 +2873,39 @@ namespace netxs::ui
};
}
};

// pro: Lua scripting.
class luafx
: public skill
{
using skill::boss,
skill::memo;
public:
template<class T>
using fxmap = std::unordered_map<text, std::function<void(T&, lua_State*)>>;

luafx(base&&) = delete;
template<class T>
luafx(base& boss, fxmap<T>& proc_map)
: skill{ boss }
{
auto& owner = dynamic_cast<T&>(boss);
boss.LISTEN(tier::release, e2::luafx, lua)
{
auto fx_name = ::lua_tostring(lua, lua_upvalueindex(2)); // Get fx name.
auto iter = proc_map.find(fx_name);
if (iter != proc_map.end())
{
auto& fx = iter->second;
fx(owner, lua); // After call, all values in the stack will be returned as a result.
}
else
{
::lua_settop(lua, 0); // No results.
}
};
}
};
}

auto& tui_domain()
Expand Down
25 changes: 0 additions & 25 deletions src/netxs/desktopio/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,31 +1526,6 @@ namespace netxs::input
mouse::coord = dot_mx;
keybd::gear_id = bell::id;
bell::signal(tier::general, events::device::user::login, user_index);

static auto proc_map = std::unordered_map<text, std::function<void(hids&, lua_State*)>>
{
{ "IsKeyRepeated", [](hids& gear, lua_State* lua)
{
auto repeated = gear.keystat == input::key::repeated;
::lua_settop(lua, 0);
::lua_pushboolean(lua, repeated);
}
},
};
LISTEN(tier::release, ui::e2::luafx, lua)
{
auto fx_name = ::lua_tostring(lua, lua_upvalueindex(2)); // Get fx name.
auto iter = proc_map.find(fx_name);
if (iter != proc_map.end())
{
auto& fx = iter->second;
fx(*this, lua);
}
else
{
::lua_settop(lua, 0);
}
};
}
virtual ~hids()
{
Expand Down
22 changes: 4 additions & 18 deletions src/vtm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,9 +1293,9 @@ namespace netxs::app::vtm
auto& keybd = boss.template plugins<pro::keybd>();
keybd.bind(window_bindings);

static auto proc_map = std::unordered_map<text, std::function<void(base&, lua_State*)>>
static auto proc_map = pro::luafx::fxmap<base>
{
{ "WarpWindow", [](base& boss, lua_State* lua)
{ "WarpWindow", [](base& boss, auto lua)
{
auto warp = dent{ (si32)::lua_tonumber(lua, 1), // Args...
(si32)::lua_tonumber(lua, 2), //
Expand All @@ -1306,23 +1306,9 @@ namespace netxs::app::vtm
boss.bell::signal(tier::preview, e2::form::layout::swarp, warp);
});
::lua_settop(lua, 0);
}
},
};
boss.LISTEN(tier::release, e2::luafx, lua)
{
auto fx_name = ::lua_tostring(lua, lua_upvalueindex(2)); // Get fx name.
auto iter = proc_map.find(fx_name);
if (iter != proc_map.end())
{
auto& fx = iter->second;
fx(boss, lua);
}
else
{
::lua_settop(lua, 0);
}
}},
};
boss.base::plugin<pro::luafx>(proc_map);
//boss.LISTEN(tier::release, e2::runscript, gear)
//{
// //todo unify
Expand Down

0 comments on commit 6aa0e47

Please sign in to comment.