lua-users home
lua-l archive

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


Argh... sorry Liam, I neglected to read the last sentence, where you recommend reading up about metatables. Actually, I have already read about metatables and metaevents. I think I get the concept, but still not quite fluent about thinking-in-metatables. Hopefully it will come with practice & time.

In my reading I'd found that arithmetic operations on non-number types is not supported, and one needs to resort to metatables. However on trying to see if same applies to table-fields whose value is numeric, I didn't anything specific and assumed that it is permitted.


On Wed, Sep 18, 2013 at 6:12 PM, Jayanth Acharya <jayachar88@gmail.com> wrote:
Thanks for the explanation folks -- understood.  I had almost began thinking (and researching) along the lines of needing to declare metatables to enforce/enable arithmetic operation functionality for the tax table.


On Wed, Sep 18, 2013 at 6:04 PM, liam mail <liam.list@googlemail.com> wrote:
>So, there doesn't seem to be any issue in doing arithmetic with table fields !!
Correct there is not, although this is not what you are doing.

On 18 September 2013 13:18, Jayanth Acharya <jayachar88@gmail.com> wrote:
tax:init(12200, 12)

This is a self call which is sent three parameters not two, the first being the self instance ie a Table.
Your print statement also highlights this when you call print(tax:getIncome(), tax:getRate())
table: 0028CA00    12200


May I suggest you look at using metatables, possibly reading 16.1 in PiL 3rd edition or 4th edition, or maybe a wiki entry[1]