Hi Serge,
your layout is really cool and I like the way you are experimenting with Lua scripting.
Complex things can be achieved with a bit of creativity!
@reinder to mitigate on_tick() callback hang problem I suggest we allow registering timers.
In this example Serge wants to wait 5 ticks before departing again, instead of checking repeatedly the on_tick() callback, we could pass the time delta or deadline time to Traintastic C++ side and have it callback Lua only once timeout expires.
This then translates directly to a boost::asio timer which if useful could be made cancellable by Lua too and of course on script end/stop every associated timer gets canceled.
About train stopping at red signal, this is an interesting topic, if we go for automatic driving throttle or mixed driving throttle (like manual driving but speed limits automatically enforced by Traintastic or by Lua), then this would remove the deceleration part from having to be implemented in each Lua script manually.
Of course real life railway signalling has greater block lengths and train braking rate are way lower than model trains so mapping real signalling behavior to model layout is challenging.
If needed we could have the concept of “ghost” signal, not shown on the layout but trains react to it.
For my project of Padua station simulation I’m considering implementing ghost signals in simulator.