@@ -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