lua-users home
lua-l archive

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

2008/12/6 Stevo <>:
> i am developing a small application for controlling a robot unit. In this
> program is use lua to run scripts which move the robot by calling the
> functions of the c program. This works fine but now i would like to
> implement a variable monitor, to display the value of e.g. the counter of a
> for-loop in the GUI of the c-program.
> The easiest implemetation for me would be to pass another c-function to lua
> which can be added in the script to pass the value of the desired variable
> and update the view. But this is also the least elegant solution ;)
> I read a bit into the lua-debug-facilities but i did not really understand
> if monitoring variables is possible with it.
> The third thing is the variable lua_getglobal. Is it possible to call it
> periodically in the C-programm while the script is running? I read the
> function takes the variable from the stack so i guess it is only valid to
> call lua_getglobal when the skript has finished?

Assuming you have a single thread, you can use lua_getglobal at
anytime from your C code, since your thread cannot execute your C code
and Lua code at the same time. All you have to do is to eventually
clean the stack afterwards depending on how your C code was called
(called by Lua or by another C function).

You don't have to wait for your script to finish, but of course your
script has to give the hand to your C code in some way (this can be
explictly through a function call or a yield, or implicitly through a
hook [1]).