lua-users home
lua-l archive

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


Jamie,

Yeah, I posted my last message before I recieved your explanation.

The reason I suggested a wrapper class, is just that I find it easier
if all the functions and data are wrapped up together in a nice class.
Just personal preference. The examples in the book use structs to
store user data.

But anyway, thank you again, I get it now I think.

Ryan.

On Tue, 6 Jul 2004 19:38:54 +0100, Jamie Webb <j@jmawebb.cjb.net> wrote:
> On Tue, Jul 06, 2004 at 11:26:37AM -0700, William Roper wrote:
> > Ok, I think I've got it now.
> >
> > I need to create a wrapper class that will be the userdata.
> > Inside the wrapper class will at least contain a pointer to my
> > instanced class and a function wrapper for each function I need to
> > call in the instanced class from Lua.
> 
> You could do that, but you don't actually need to create a wrapper
> class. Just the wrapper functions. If you look at the example code I
> posted earlier, I'm just storing a pointer directly in the userdata.
> 
> > Then after I create my instanced class, the factory needs to call a
> > function that creates the new userdata, then sets the user datas
> > pointer to instanced class.
> 
> Yes.
> 
> > I also create a metatable for the userdata that has the methods I need
> > to call on my instanced class and point them to the wrapper functions
> > for each of those.
> 
> Yes. Note that you only need to create the metatable for each class
> once, and then you use the same metatable for each instance of that
> class.
> 
> -- Jamie Webb
>