[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why is my thread not resuming? (very simple code inside)
- From: "John Klimek" <jklimek@...>
- Date: Thu, 9 Aug 2007 11:48:05 -0400
After further investigation, it looks like lua_yield(L, 0) is
returning -1 from inside my CFunction called AskQuestion().
What does that mean?
The Lua 5.0 documentation (the version I'm using) says that if you
want to yield inside a C Function then you should pass the result of
lua_yield as the return value of the function. (this is what I'm
doing)
The -1 value seems incorrect to me though... (but maybe thats normal?)
Either way, lua_resume is returning a "1" after I try to resume it
AFTER the CFunction returns lua_yield()
On 8/9/07, John Klimek <jklimek@gmail.com> wrote:
> Here's what I'm doing:
>
> // ********
> // startup.lua (my script)
> // ********
> io.write("startup: before\n");
> io.write("startup: " .. AskQuestion() .. "\n");
> io.write("startup: after\n");
>
>
> // ********
> // Delphi Code
> // ********
>
> // My "C" Function
> function AskQuestion(L : Lua_State) : integer; cdecl;
> begin
> result := lua_yield(L, 0);
> end;
>
> // Register the c-function
> lua_register(L, 'AskQuestion', AskQuestion);
>
> // Create a new thread, load a file into it, and then resume (eg. start it)
> l_thread := lua_newthread(L);
> lual_loadfile(l_thread, 'startup.lua'); // returns 0
> lua_resume(l_thread, 0); // returns 0
>
> At this point the script begins executing and prints "startup:
> before". The script hits the coroutine.yield() and execution is back
> inside my Delphi program.
>
> If I try to resume the coroutine: lua_resume(l_thread, 0); it
> returns "1" and does not do anything. The script does not continue.
>
> What am I doing wrong?
>
> Also, are coroutines just the name for a Lua "thread"? This is very
> confusing because they seem to be two different things but I don't
> know...
>