[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Why is my thread not resuming? (very simple code inside)
- From: "John Klimek" <jklimek@...>
- Date: Thu, 9 Aug 2007 11:28:56 -0400
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...