lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Am Do., 2. Nov. 2023 um 19:32 Uhr schrieb Luna <lunacb@disroot.org>:
> I mean that there is no native coroutine concept in C. There aren't
> yield and resume functions in C.

Sorry for misunderstanding, yes of course, you are right, C was
invented before the different 'GUI versions like OS or Windows or
Android started their race :), Computers in this startup time were
mainly seen as computational work horses for science, library and
machine control.

As I wrote you already, I unfortunately do NOT use the Lua cotroutine
concept by myself, as I use this own task functions (and I would not
describe me as Lua expert, at least until now I do NOT any tricky
things with Lua Stack or debug library or so - I keep very much mit
the PiL book of Roberto...).

To keep an example for the hanging problem, let's think of a button in
a "parent window" which opens a "child window" with further buttons,
and then all the child and the parent buttons should rund
concurrently.

In my task system the interation of task creation is no problem, as
all tasks run concurrently on the "main level" (in the main loop of my
controller). If a new task.open is met on this main level, a new task
(lua_newthread( LuaBase) - this LuaBase state is always the same, I
use only one Lua base state in my program) is added to the task
list... .

The only weird situation where I ran into problems was the case, that
I want to allow the possibility, that some external communications
like e. g. serial communication interface in the main loop also should
be able to "insert a Lua command" in this "thread carusel", and this
communication "Lua command" of course might appear "any time". This
then will NOT work. For this getting to work, thise "external Lua
commands" must be stort in some FIFO loop, and then in one of the User
Tasks (typically the User main task) a function sys.executeexternals
must be invoiked, which hten will look for the new "external Lua
commands", pull them from the FIFO, and execute them in a new
thread... . Here I needed the yieldk functionality (there is yield and
yieldk - sorry, I just do not know the exact reason).

For this  threading concept / task condcept it is important, that this
task.open (-> lua_newthread(LuaBase) ) is invoked always from some Lua
code... .