lua-users home
lua-l archive

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

	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-----
[] 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:


function myclass:myfunc()
  --do stuff



  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

  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.

  Dan East