lua-users home
lua-l archive

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


Well I knew it was something silly. Thank you, I've been trying to figure this out for hours. 


On Fri, Jul 5, 2013 at 11:09 PM, Choonster TheMage <choonster.2010@gmail.com> wrote:
On 6 July 2013 12:49, Matt Eisan <mattjeisan@gmail.com> wrote:
>
> Hello, I'm trying to create 3D vector object to try to get the hang of how metatables and pseudo-classes work. I figured it would be simple enough. However, I cannot figure out why this code is not working, (I'm probably doing something really silly wrong, but hey, that's how you learn.)
>
> Thanks in advance for any help.

You put the `new` and `setX` methods in the VECTOR table, but the
vector __index metamethod (which you've set as a table of default x, y
and z values) completely ignores this table.

Either put the methods in the same table as the defaults and set that
as the __index metamethod or use a function to return the appropriate
method or default value.

I've attached a working version of your script.