[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Assignment in C++ like DSL
- From: steve donovan <steve.j.donovan@...>
- Date: Thu, 24 Dec 2015 20:32:25 +0200
On Thu, Dec 24, 2015 at 7:23 PM, Abhijit Nandy <email@example.com> wrote:
> Is there any reason why the assignment operator cannot be overloaded in Lua?
Because the __newindex metamethod  only fires when a _new_ table
index is created - otherwise it would be inefficient if it fired for
However, you _can_ do int.m = 3 ! 'int' is a table with a __newindex
- it will be called with the table itself ('self') and the key ('m').
As long as you don't actually store 'm' in that table, the metamethod
will fire each time. You can make it do anything you like...