lua-users home
lua-l archive

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

On Thursday 02 December 2004 11:32 am, Dan Laufer wrote:
> Whoops.
> It was actually all down to me getting in a tangle over :'s and .'s.

only that?  i was thinking that maybe the problem is with the unrolling of the 
':' . in other words:

 Task1Co = coroutine.create(Task1:tick());


 Task1Co = coroutine.create(Task1.tick(Task1));

but coroutine.create expects a function, not the result of tick(Task1)

one way would be to add a new method 'GetTask'

 function TestTask:GetTask ()
  self.task = self.task or coroutine.wrap (self.tick)
  return self.task

then, you could use like this:

 Task1 = TestTask:new();
 Task1.taskName = "Task1";

 Task1Co = Task1:GetTask ();
 -- somewhere in the loop
 Task1Co (Task1Co);

 -- or maybe,
 Task1:GetTask() (Task1Co)

there are better ways to do it... but 'tick' would be better as the name of an 
interface function, not the work function.  for example:

 function TestTask:work()
         while 1 do
                 self.internalVal = self.internalVal + 1;
                 print("Internal val of TestTask "..self.taskName..
    " : "..self.internalVal);

 funtcion TestTask:tick () = or croutine.create ( (self)

 -- using it:
 Task1 = TestTask:new();
 Task1.taskName = "Task1";

 -- somewhere in the loop


Attachment: pgp45boApF26L.pgp
Description: PGP signature