[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: trouble with metatables
- From: Choonster TheMage <choonster.2010@...>
- Date: Sat, 6 Jul 2013 13:09:32 +1000
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.
Attachment:
vector.lua
Description: Binary data