lua-users home
lua-l archive

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


Yann Com-Nougué Said :
> Basically RegisterClass() stores a reference to the object that is
> registered.

Oups sorry, that should be..  Basically RegisterClass() stores a COPY to the
object that is registered.

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Yann Com-Nougue
Sent: 9 juin 2004 10:03
To: Lua list
Subject: RE: Type definition within LUA

	We have a mechanism doing this in our app.  Basically
RegisterClass() stores a reference to the object that is registered.  And
when we want to "instanciate" the object we simply clone it.  Clone : We
make a real ( not reference) copy of all the data and a reference copy to
the functions.

	So basically your factory stores a copy of your "lua class".  And
has a creation function.  When the function is called the factory clones the
registered "lua class" and returns the new instance.

	This is a pretty basic creation pattern, but of course I can't
remember it's name :)

	Good luck,
	Yann Com-Nougué

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Dan East
Sent: 9 juin 2004 09:42
To: Lua list
Subject: Type definition within LUA

  Hi.  I wish to allow the user to define classes within LUA that can be
instantiated from the host app (written in C of course).

Something along this line:

myclass={}

function myclass:myfunc()
  --do stuff
end

myclass.n=10

host.RegisterClass(myclass)

  The host application can then create as many instances of that object as
desired within the LUA environment, where each instance's data will be
unique.

  I am currently using lunar to interface my C++ classes with good success,
but I need to allow class-like definitions within LUA as well.
  Thanks.

  Dan East