[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: GC or Scope problem?!! (Passing pointer to Lua)
- From: Nelson Wong <gogoneruson@...>
- Date: Mon, 11 Apr 2005 18:44:59 +0900
Hi all,
I am having a problem with passing pointer to Lua script.
I want to to be able to create a game stage from the scripts. The
objects that are being created by script will still exist, so the game
code (Native Code) can pick them up and start the game.
I passed pointer as following (in C++)
------------------------------------------------------
....
MyStage * myStage;
Script.run("CreateStage", myStage);
...
System.Starrt(myStage);
in Lua Script,
-------------------
CreateStage = function(stage)
stage = MyStage:Create();
enemy1 = Enemy:Create(Enemy::MALE);
stage.AddCharacter(enemy1);
enemy2 = Enemy:Create(Enemy::FEMALE);
stage.AddCharacter(enemy2);
building1 = Building:Create();
stage.AddBuilding(building1);
end
remark, I have all the binding functions for all those C++ classes and methods.
Problem is, all the objects are GONE, after calling "Script.run(....)
where System.Start(myStage) give me runtime-error. In fact, I found
that all the objects actually successfully created WITHIN the
Script:run(...) calls.
Is that the scope problem, or Lua's GC collects my objects since they
are actually created in the script stack.
Is there a easy way to identify the problem? for example, turn off the
GC, so I can pin-point if the problem is caused GC or not.
Thanks for any comments and helps.
-N