lua-users home
lua-l archive

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


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