lua-users home
lua-l archive

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


Is it possible for a C/C++ program to halt the execution of a lua function 
that it has called, and then resume at the stopping point at a later time.

For instance, an application where the entire Lua function has to be 
run but is only given resources every so often.

Possible answers
1. There is some mechanism to say how much time a Lua script has to run
2. There is some mechanism to say how many steps a Lua script can take
3. Using the Lua VM, you can set a pointer to the stack so that you can 
resume at that point
4. Lua does not support anything like this...once a script is called, it 
has to run to the end
5. None of the above, but Lua probably has some way to do this

I am using Lua 5.0 and from my early tests when I call a Lua function from 
C/C++, I get the function executed along with anything not in a function.
For instance, lua script is

io.write("out")

function a()
 io.write("a")
end

function b()
 io.write("b")
end

My result when calling a() would be "outa" when I would expect only "a"
Is this because I am using lua_dofile(...) then lua_getglobal(..., "a") 
and finally a lua_pcall(...)