lua-users home
lua-l archive

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

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;"CreateStage", myStage);

in Lua Script,
CreateStage = function(stage)
    stage = MyStage:Create();
    enemy1 = Enemy:Create(Enemy::MALE);
    enemy2 = Enemy:Create(Enemy::FEMALE);
    building1 = Building:Create();

remark, I have all the binding functions for all those C++ classes and methods.

Problem is, all the objects are GONE, after calling "
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.