Skip to content

Commit 3023c87

Browse files
authored
Merge pull request #825 from o-sdn-o/gui-bridge
Fix name resolution in scripting
2 parents 02f4c33 + 90c5008 commit 3023c87

File tree

9 files changed

+83
-104
lines changed

9 files changed

+83
-104
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,21 @@ jobs:
106106

107107
- name: Pack (POSIX)
108108
if: matrix.os != 'windows-latest'
109-
run: 7z a -ttar vtm_${{ matrix.platform }}_${{ matrix.arch }}.tar ${{ steps.strings.outputs.bin }}/vtm
109+
run: |
110+
7z a -ttar vtm_${{ matrix.platform }}_${{ matrix.arch }}.tar ${{ steps.strings.outputs.bin }}/vtm
111+
7z a -mx9 -stl -y -r -t7z vtm_${{ matrix.platform }}_${{ matrix.arch }}.tar.7z vtm_${{ matrix.platform }}_${{ matrix.arch }}.tar
112+
113+
- name: Pack (Windows)
114+
if: matrix.os == 'windows-latest'
115+
run: |
116+
7z a -ssp -mx9 -stl -y -r -t7z vtm_${{ matrix.platform }}_${{ matrix.arch }}.7z ${{ steps.strings.outputs.bin }}/Release/vtm.exe
110117
111118
- name: Upload Artifact (POSIX)
112119
if: matrix.os != 'windows-latest'
113120
uses: actions/upload-artifact@main
114121
with:
115122
name: vtm_${{ matrix.platform }}_${{ matrix.arch }}
116-
path: vtm_${{ matrix.platform }}_${{ matrix.arch }}.tar
123+
path: vtm_${{ matrix.platform }}_${{ matrix.arch }}.tar.7z
117124

118125
- name: Upload Symbols (Windows)
119126
if: matrix.os == 'windows-latest'
@@ -127,4 +134,4 @@ jobs:
127134
uses: actions/upload-artifact@main
128135
with:
129136
name: vtm_${{ matrix.platform }}_${{ matrix.arch }}
130-
path: ${{ steps.strings.outputs.bin }}/Release/vtm.exe
137+
path: vtm_${{ matrix.platform }}_${{ matrix.arch }}.7z

readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ It can wrap any console application and be nested indefinitely, forming a text-b
2626

2727
# Binary downloads
2828

29-
![Linux](.resources/status/linux.svg) [![Intel 64-bit](.resources/status/arch_x86_64.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_linux_x86_64.zip) [![Intel 32-bit](.resources/status/arch_x86.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_linux_x86.zip) [![ARM 64-bit](.resources/status/arch_arm64.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_linux_arm64.zip) [![ARM 32-bit](.resources/status/arch_arm32.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_linux_arm32.zip)
29+
![Linux](.resources/status/linux.svg) [![Intel 64-bit](.resources/status/arch_x86_64.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_linux_x86_64.tar.7z) [![Intel 32-bit](.resources/status/arch_x86.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_linux_x86.tar.7z) [![ARM 64-bit](.resources/status/arch_arm64.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_linux_arm64.tar.7z) [![ARM 32-bit](.resources/status/arch_arm32.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_linux_arm32.tar.7z)
3030
![Windows](.resources/status/windows.svg) [![Intel 64-bit](.resources/status/arch_x86_64.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_windows_x86_64.7z) [![Intel 32-bit](.resources/status/arch_x86.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_windows_x86.7z) [![ARM 64-bit](.resources/status/arch_arm64.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_windows_arm64.7z)
31-
![macOS](.resources/status/macos.svg) [![Universal](.resources/status/arch_any.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_macos_any.zip)
31+
![macOS](.resources/status/macos.svg) [![Universal](.resources/status/arch_any.svg)](https://github.com/directvt/vtm/releases/latest/download/vtm_macos_any.tar.7z)
3232

3333
Linux platform notes:
3434
- The Linux binaries are statically built using gcc-12/g++-12 on an Ubuntu 22.04 system provided by Github Actions.

src/netxs/desktopio/application.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace netxs::app
2222

2323
namespace netxs::app::shared
2424
{
25-
static const auto version = "v2025.10.13";
25+
static const auto version = "v2025.10.14";
2626
static const auto repository = "https://github.com/directvt/vtm";
2727
static const auto usr_config = "~/.config/vtm/settings.xml"s;
2828
static const auto sys_config = "/etc/vtm/settings.xml"s;

src/netxs/desktopio/baseui.hpp

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ namespace netxs::ui
735735
netxs::events::vtm_class::list::iterator class_iterator; // base: class_metadata.objects std::list iterator.
736736
};
737737
utf::unordered_map<text, base_class> base_classes; // base: Base classes map by classname.
738-
netxs::events::context_t scripting_context; // base: List of ids of all ancestors.
738+
netxs::events::context_t scripting_context; // base: Temp buffer for the list of ids of all ancestors.
739739

740740
struct mfocus_node
741741
{
@@ -817,35 +817,6 @@ namespace netxs::ui
817817
return sptr{};
818818
}
819819
// base: Update scripting context. Run on anycast, e2::form::upon::started.
820-
void update_scripting_context()
821-
{
822-
if (auto parent_ptr = base::parent())
823-
{
824-
base::scripting_context = parent_ptr->scripting_context;
825-
}
826-
base::scripting_context.emplace_back(this);
827-
//todo Sort all base::base_classes.* references.
828-
//for (auto& [classname, base_class_metadata] : base_classes)
829-
//{
830-
// if (base_class_metadata.class_metadata)
831-
// {
832-
// auto& objects = base_class_metadata.class_metadata->objects;
833-
// auto objects_iterator = base_class_metadata.class_iterator;
834-
// auto head = objects.begin();
835-
// auto tail = objects.end();
836-
// auto next = std::next(objects_iterator);
837-
// if (next != tail)
838-
// {
839-
// // Find valid next.
840-
// }
841-
// if (objects_iterator != head)
842-
// {
843-
// // Find valid prev.
844-
// auto prev = std::prev(objects_iterator);
845-
// }
846-
// }
847-
//}
848-
}
849820
// base: Enqueue task.
850821
template<bool Sync = true>
851822
void enqueue(netxs::events::fx<ui::base> proc)
@@ -871,6 +842,23 @@ namespace netxs::ui
871842
return std::pair{ ref_count, del_count };
872843
}
873844
// base: Cleanup expired weak references.
845+
auto& get_scripting_context()
846+
{
847+
base::scripting_context.clear();
848+
base::scripting_context.push_back(this);
849+
auto parent_ptr = base::father.lock();
850+
while (parent_ptr)
851+
{
852+
base::scripting_context.push_back(parent_ptr.get());
853+
if (auto next_parent_ptr = parent_ptr->base::father.lock())
854+
{
855+
parent_ptr = next_parent_ptr;
856+
}
857+
else break;
858+
}
859+
return base::scripting_context;
860+
}
861+
// base: Cleanup expired weak references.
874862
void cleanup(bool show_details = faux)
875863
{
876864
if (show_details)
@@ -890,7 +878,7 @@ namespace netxs::ui
890878
for (auto& boss_ref : v->objects)
891879
{
892880
auto& boss = boss_ref.get();
893-
log("context: %ctx%", netxs::events::script_ref::to_string(boss.scripting_context));
881+
log("context: %ctx%", netxs::events::script_ref::to_string(boss.base::get_scripting_context()));
894882
}
895883
}
896884
}
@@ -911,7 +899,7 @@ namespace netxs::ui
911899
void broadcast(si32 Tier, hint event, auto&& param, bool forced = true)
912900
{
913901
auto lock = bell::sync();
914-
bell::_signal(Tier, event, param);
902+
indexer.notify(Tier, reactor, event, param);
915903
for (auto item_ptr : base::subset)
916904
{
917905
if (item_ptr && (forced || !item_ptr->master))
@@ -942,7 +930,7 @@ namespace netxs::ui
942930
}
943931
else
944932
{
945-
bell::_signal(Tier, event, param);
933+
indexer.notify(Tier, reactor, event, param);
946934
}
947935
}
948936
// base: Fire an event.

src/netxs/desktopio/console.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,7 @@ namespace netxs::ui
543543
luafx.set_return(is_focused);
544544
}},
545545
});
546-
gear.base::father = This(); // Gear has a fixed parent.
547-
gear.base::update_scripting_context(); //
546+
gear.base::father = This(); // Gear has a fixed parent.
548547
}
549548
auto& [ext_gear_id, gear_ptr] = *gear_it;
550549
auto& gear = *gear_ptr;
@@ -904,7 +903,7 @@ namespace netxs::ui
904903
canvas.face::area(base::area());
905904
LISTEN(tier::release, e2::form::proceed::multihome, world_ptr)
906905
{
907-
multihome = { world_ptr, world_ptr->base::father };
906+
multihome = input::multihome_t{ .world_wptr = world_ptr, .parent_wptr = world_ptr->base::father, .holder = world_ptr->base::holder };
908907
};
909908
LISTEN(tier::release, e2::command::printscreen, gear)
910909
{
@@ -1040,7 +1039,6 @@ namespace netxs::ui
10401039
};
10411040
LISTEN(tier::anycast, e2::form::upon::started, root_ptr)
10421041
{
1043-
base::update_scripting_context(); // Gate has no parents.
10441042
if (props.debug_overlay) debug.start();
10451043
base::signal(tier::release, e2::form::prop::name, props.title);
10461044
//todo revise

src/netxs/desktopio/controls.hpp

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace netxs::events
1010
text script_ref::to_string(context_t& context)
1111
{
1212
auto crop = text{};
13-
for (auto ptr : context)
13+
for (auto ptr : context | std::views::reverse)
1414
{
1515
crop += utf::bytes2shades(view{ (char*)&ptr, sizeof(void*) });
1616
crop += '-';
@@ -219,9 +219,9 @@ namespace netxs::events
219219
{
220220
return luna::vtmlua_run_with_indexer(lua, [&](auth& indexer)
221221
{
222-
auto& param = indexer.script_param;
223-
if (param.has_value())
222+
if (indexer.script_param.size() && indexer.script_param.back().has_value())
224223
{
224+
auto& param = indexer.script_param.back();
225225
if (param.type() == typeid(std::reference_wrapper<time>)) return luna::vtmlua_push_value(lua, std::any_cast<std::reference_wrapper<time>>(param).get());
226226
else if (param.type() == typeid(std::reference_wrapper<bool>)) return luna::vtmlua_push_value(lua, std::any_cast<std::reference_wrapper<bool>>(param).get());
227227
else if (param.type() == typeid(std::reference_wrapper<text>)) return luna::vtmlua_push_value(lua, std::any_cast<std::reference_wrapper<text>>(param).get());
@@ -253,7 +253,7 @@ namespace netxs::events
253253
return luna::vtmlua_run_with_indexer(lua, [&](auth& indexer)
254254
{
255255
auto object_name = luna::vtmlua_torawstring(lua, 2);
256-
auto& source_ctx = indexer.context_ref.get();
256+
auto& source_ctx = indexer.context_refs.back().get();
257257
if (object_name == "config")
258258
{
259259
//log("object_name=", object_name);
@@ -263,24 +263,12 @@ namespace netxs::events
263263
}
264264
else if (auto target_ptr = indexer.get_target(source_ctx, object_name))
265265
{
266-
//if constexpr (debugmode) log(" selected: ", netxs::events::script_ref::to_string(target_ptr->scripting_context));
266+
//if constexpr (debugmode) log(" selected: ", netxs::events::script_ref::to_string(target_ptr->get_scripting_context()));
267267
::lua_pushlightuserdata(lua, target_ptr); // Push object ptr.
268268
::luaL_setmetatable(lua, "vtm_submetaindex"); // Set the vtm_submetaindex for table at -1.
269269
//todo keep target_ptr locked until we are inside the lua
270270
return 1;
271271
}
272-
else if (object_name == "desktop") //todo unify (use set_multihome)
273-
{
274-
//log("object_name=", object_name);
275-
auto iter = indexer.objects.find(1);
276-
if (iter != indexer.objects.end())
277-
{
278-
auto world_ptr = &(iter->second.get());
279-
::lua_pushlightuserdata(lua, world_ptr); // Push address of the world instance.
280-
::luaL_setmetatable(lua, "cfg_submetaindex"); // Set the cfg_submetaindex for table at -1.
281-
return 1;
282-
}
283-
}
284272
log("%%No 'vtm.%%' object found", prompt::lua, object_name);
285273
return 0;
286274
});
@@ -411,8 +399,8 @@ namespace netxs::events
411399
//if constexpr (std::is_same_v<T, noop>) log("%%script:\n%pads%%script%", prompt::lua, prompt::pads, ansi::hi(script_body));
412400
//else log("%%script:\n%pads%%script%\n with arg: %%", prompt::lua, prompt::pads, ansi::hi(script_body), param);
413401

414-
indexer.context_ref = context;
415-
indexer.script_param = std::ref((T&)param);
402+
indexer.context_refs.push_back(context);
403+
indexer.script_param.push_back(std::ref((T&)param));
416404

417405
auto error = faux;
418406
if (push_function_id(script_body))
@@ -429,7 +417,9 @@ namespace netxs::events
429417
|| ::lua_pcall(lua, 0, 0, 0);
430418
}
431419
}
432-
indexer.script_param.reset();
420+
421+
indexer.context_refs.pop_back();
422+
indexer.script_param.pop_back();
433423
auto result = text{};
434424
if (error)
435425
{
@@ -444,9 +434,9 @@ namespace netxs::events
444434
::lua_settop(lua, 0);
445435
return result;
446436
}
447-
text luna::run_script(ui::base& boss, view script_body)
437+
text luna::run_script(ui::base& boss, view script_body, auto&& param)
448438
{
449-
return run(boss.scripting_context, script_body);
439+
return run(boss.get_scripting_context(), script_body, param);
450440
}
451441
void luna::run_ext_script(ui::base& boss, auto& script)
452442
{
@@ -605,9 +595,9 @@ namespace netxs::events
605595
if (lua) ::lua_close(lua);
606596
}
607597

608-
script_ref::script_ref(auth& indexer, context_t& context, sptr<std::pair<ui64, text>> script_body_ptr)
598+
script_ref::script_ref(auth& indexer, std::reference_wrapper<ui::base> boss_ref, sptr<std::pair<ui64, text>> script_body_ptr)
609599
: indexer{ indexer },
610-
context{ context },
600+
boss_ref{ boss_ref },
611601
script_body_ptr{ script_body_ptr }
612602
{
613603
indexer.luafx.precompile_function(script_body_ptr);
@@ -619,7 +609,7 @@ namespace netxs::events
619609

620610
auth::auth(bool use_timer)
621611
: next_id{ 0 },
622-
context_ref{ context },
612+
context_refs{ context },
623613
luafx{ *this },
624614
quartz{ *this },
625615
e2_timer_tick_id{ ui::e2::timer::tick.id },
@@ -679,28 +669,28 @@ namespace netxs::events
679669
while (head != tail)
680670
{
681671
auto& boss = head->get();
682-
auto& target_ctx = boss.scripting_context;
672+
auto& target_ctx = boss.get_scripting_context();
683673
//if constexpr (debugmode) log(" target context: ", netxs::events::script_ref::to_string(target_ctx));
684674
if (target_ctx.empty() // The object is outside the DOM.
685-
|| source_ctx.back() == target_ctx.back()) // Target is the source itself.
675+
|| source_ctx.front() == target_ctx.front()) // Target is the source itself.
686676
{
687677
target_ptr = &boss;
688678
iter2 = head;
689679
break;
690680
}
691-
auto dst_head = target_ctx.begin();
692-
auto dst_tail = target_ctx.end();
693-
auto src_head = source_ctx.begin();
694-
auto src_tail = source_ctx.end();
681+
auto dst_head = target_ctx.rbegin();
682+
auto dst_tail = target_ctx.rend();
683+
auto src_head = source_ctx.rbegin();
684+
auto src_tail = source_ctx.rend();
695685
auto source_ctx_begin = src_head;
686+
//todo don't use context - just iterate over parents
696687
while (src_head != src_tail && dst_head != dst_tail && *src_head == *dst_head)
697688
{
698689
++src_head;
699690
++dst_head;
700691
}
701692
auto m = (si32)(src_head - source_ctx_begin);
702-
if (m > closeness
703-
|| (m == closeness && target_ctx.size() < target_size))
693+
if (m > closeness || (m == closeness && target_ctx.size() < target_size))
704694
{
705695
closeness = m;
706696
target_size = target_ctx.size();
@@ -3572,12 +3562,7 @@ namespace netxs::ui
35723562

35733563
form()
35743564
: base{ ui::tui_domain() }
3575-
{
3576-
LISTEN(tier::anycast, e2::form::upon::started, root_ptr)
3577-
{
3578-
base::update_scripting_context(); // Update scripting context on every reattachement.
3579-
};
3580-
}
3565+
{ }
35813566
};
35823567

35833568
// controls: Splitter.

0 commit comments

Comments
 (0)