[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: running the Lua VM "in time slices"
- From: Gerhard Sittig <Gerhard.Sittig@...>
- Date: Fri, 30 Dec 2005 14:39:07 +0100
On Thu, Dec 29, 2005 at 23:05 -0800, David Andersen wrote:
>
> You want to do this I think:
>
> http://www.icynorth.com/forums/viewtopic.php?p=228&sid=24c427141b80232a86258d2e41c6b0ee#228
Thank you for the pointer. Haven't thought of such an approach yet. I
could start some Lua glue of my own from the C application and have this
Lua glue run another user provided Lua chunk with periodic callbacks.
I took the code snippet and it works as advertised. But then I tried to
make sure that even the initial pcall (where the loop() routine gets
declared) runs with debug hooks set. Because nobody could stop users
providing a script like this:
-- the loop() declaration has been there before
counter = 0
function loop()
while counter < 10000 do
counter = counter + 1
end
end
-- this immediate calling loop() is new
loop
Doing luaL_loadfile(), i.e. compiling the source, is no problem. But
running this code the first time to declare the counter variable and the
loop() routine (as the message you refer to does) may already block in a
possibly infinite loop. Remember, I won't have any influence on the
scripts the VM is fed with. Neither can I (hard) require users to
provide an entry point like a main() routine or something. I want the
thing to look as much Lua as possible.
Will have to look a little more into how to even "supervise" the first
invocation. Maybe wrapping the Lua user code in my own Lua glue will be
the solution.
virtually yours
Gerhard Sittig
--
If you don't understand or are scared by any of the above
ask your parents or an adult to help you.