lua-users home
lua-l archive

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


On Apr 11, 2005 7:24 PM, David Given <dg@cowlark.com> wrote:
> On Mon, 2005-04-11 at 18:44 +0900, Nelson Wong wrote:
> [...]
> > 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.
> 
> I do notice one thing:
> 
> [...]
> > MyStage * myStage;
> > Script.run("CreateStage", myStage);
> 
> You're passing an uninitialised pointer in here...

Oops, My bad!
This whole thing actually is a part of contructor.
Assume, GameSystem is a class, and Stage is one of the class member of
this class. I am trying to experience if it is possible to moving
entire constructor content into the scripts, yet the owner is the C++.

> 
> > CreateStage = function(stage)
> >     stage = MyStage:Create();
> 
> ...which you're never modifying (assign a value to 'stage' will just
> modify the value of the local variable. In fact, because you're never
> returning 'stage' from your function, the value will be thrown away from
> the garbage collector when the function exits.)
> 
> What are you expecting to happen? What is a MyStage, and who do you want
> to own it (C++, or Lua)?

Yes, C++ owns all the objects even though they are created in script's
scope! Is that possible.

Again, it might be a bit too much, but I am trying out the extreme
case, where I want Lua script due with all the creation of the stage
objects.

Nelson
> 
> --
> +- David Given --McQ-+ "There is nothing in the world so dangerous ---
> |  dg@cowlark.com    | and I mean *nothing* --- as a children's story that
> | (dg@tao-group.com) | happens to be true." --- Master Li Kao, _The Bridge
> +- www.cowlark.com --+ of Birds_
> 
>