[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Classes with member co-routines.
- From: Dan Laufer <dlaufer@...>
- Date: Thu, 2 Dec 2004 14:55:17 -0000
Hello all,
I'm trying to set up a simple task management system, where I'd like to
create task objects, and then per-update interval, resume a member function
of each task as a coroutine.
At the moment, my test code looks like :
-- Lua code starts.
function TestTask:new (o)
o = o or {
-- Data
internalVal = 0,
taskName = "TestTask"
}
setmetatable(o, self)
self.__index = self
return o
end
function TestTask:tick()
while 1 do
self.internalVal = self.internalVal + 1;
print("Internal val of TestTask "..self.taskName.." :
"..self.internalVal);
coroutine.yield();
end
end
Task1 = TestTask:new();
Task1.taskName = "Task1";
Task1Co = coroutine.create(Task1:tick());
coroutine.resume(Task1Co);
-- Lua code ends.
Using Lua 5.1w2, this generates the following error :
attempt to yield across metamethod/C-call boundary
stack traceback:
[C]: in function `yield'
/LuaClassTest.lua:21.0000: in function `tick'
/LuaClassTest.lua:28.0000: in main chunk
This happens on the call to coroutine.create()
Anyone got a clue as to what I'm doing wrong here? I'm hoping it's not my
entire approach...
D.