lua-users home
lua-l archive

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

On Thu, Dec 24, 2015 at 7:23 PM, Abhijit Nandy <> wrote:
> Is there any reason why the assignment operator cannot be overloaded in Lua?

Because the __newindex metamethod [1] only fires when a _new_ table
index is created - otherwise it would be inefficient if it fired for
every assignment.

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...