|
On 16.03.2018 11:11, Duane Leslie
wrote:
Just.On 16 Mar 2018, at 17:54, Thomas Jericke <tjericke@indel.ch> wrote: The problem I see, is that you don't get raw equality with any userdata implementation of tuples. So I cannot use them as table keys.This can be solved using interning as is often done with strings, it just makes the constructor function more difficult and requires a `__gc` metamethod. Well I see how this can work, but then, this is nothing that could not be done with Lua 5.3 and tables. I am actually struggling a little how I would implement a copy-on-edit. The __newindex metamethod gets the userdata and the field name and the new value as parameters. The userdata is passed as a reference, but if I am not completely wrong I cannot edit the original reference, I just get a copy of the reference which is then placed on the stack. If Lua wanted to support this, it would need to be possible that the __newindex method returns a value that replaces the original reference.I haven't tried this so I might be wrong here.Also they are passed by reference and not by value. That can be confusing once you edit a value in that tuple.The passing method doesn't matter if the tuple is immutable (or copy-on-edit) so this isn't an issue. Regards, Duane. Anyway the resort to immutable will work for sure. -- Thomas |