[Question] Now that I've made a table based library, How do I go object orientated?

Hello there! Recently I’ve been trying to learn C++ , finding it very similar to Lua. In my learning process, I’m trying to convert a library I’ve already made into C++. The problem is that I don’t know how to go object orientated.
I’ve made these functions :



> PrintTable( Point3D )...
SetPosition	=	function: 0209ACB0
RotateX	=	function: 02099768
Project	=	function: 02099840
Destroy	=	function: 020DAD30
RotateY	=	function: 0209AF68
RotateZ	=	function: 02097FF8
New	=	function: 0209ABD8


Point3D.New returns userdata of a class I made in C++. Except to perform actions on it I need to do something like this:

[LUA]
MyPoint = Point3D.New( 0 , 0 , 20 )
Point3D.SetPosition( MyPoint , 20 , 20 , 20 )

– Except I would like to do something more like this:

MyPoint = Point3D.New( 0 , 0 , 20 )
MyPoint:SetPosition( 20 , 20 , 20 )
[/LUA]

Would anyone know the way to go? I’ve read some articles I found on google, except there was nothing that really explained why we used which functions …

Thanks in advance.

You need to create a metatable and set this metatable as metatable for all instances of your object.

Could you please elaborate on how one would do this? And if possible , in detailed steps and explaining what each function does?

[editline]11th January 2012[/editline]

Can anyone help please? Though I have found some useful information on it, I’ve found nothing as to how to apply it to what I’m doing, and it’s starting to really annoy me now.

Here’s a working example script from when I was learning this myself

For a good explanation of why it works, see MakeR’s posts in my old question thread :v:

Though, the most comprehensive explanation you could get is here

Happy hunting!

Already resolved.

[editline]12th January 2012[/editline]

Also don’t forget to define __gc otherwise your objects will fuck your ram.