On Thu, Feb 26, 2009 at 11:35 AM, Dr Christopher S Kirk
<drcskirk@fastmail.fm> wrote:
Subject: using lua to call a continuous 'C' function and passing data
back to lua without terminating the 'C' loop
I am attempting the use of lua calling 'C' functions from a 'C' library.
All 'C' functions are self-contained in a library but one is a loop (do
forever). This function waits for input from a networked source and
produces five variables.
If this function were to be called from lua only once and then to result
in termination, it would be reasonable for 'C' to pass the variables to
the lua_stack and 'return' the number of 'pushed' variables (5) as it
terminates.
However, this case is continuous, (it is a loop) so is it possible to
push variables to the stack and to 'return' the number (5) and to have
lua poll for results to enable further manipulation yet maintain the
loop within 'C'? How would lua 'know' of the update?
Is the only route to terminate the 'C' loop, return the results and have
lua restart the loop?
I would appreciate pointers or direct advice.
Many thanks for considering the problem.
--
If you have control over the C code, one way is to rewrite your code and move the loop to the Lua side. If the loop must be in C, another approach could be to invoke a Lua function to handle your results from within the C loop, which would then return control to the C loop when it's finished.
A little more background info might be helpful; do you have control of the C code too?
Evan