[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: metamethods for assignment and type conversion
- From: Adrien de Croy <adrien@...>
- Date: Thu, 09 Aug 2007 17:28:26 +1200
It could be considered radical maybe for tables.
for userdata and lightuserdata, it makes perfect sense to use the same
syntax to copy one userdata to another one the same as you would a
string value, rather than a function to do it.
keep in mind this would be controlled by the existence or not of the
__assign metamethod. Presumably whoever would use this would do so
Looks like I don't actually need __assign (yet) for my application, as
all the things i am assigning belong to a parent table, so I get the
same effect with a __newindex on the parent.
but it doesn't really make that much sense that lua exposes all the
other operators except assignment.
I've already coded part of the __cast metamethod. It's working very
well, I'm able to automatically convert tables into strings with a
Actually I'd be happy to forgoe all this if the table concept was
extended instead to have a single unindexed value which would be used if
there was no index made.
e.g. a la windows registry. You can set the value of a key, as well as
members in a key. It's the unnamed index/default value.
Aaron Brown wrote:
Adrien de Croy wrote:
this would also then allow lua script like
function dosomething(object1, object2)
object2.somemember = "hello";
object1 = object2; -- deep copy in host via __assign
-- metamethod rather than table reference
I think this is a bad idea, because it's a radical change to
Lua's semantics, in which an assignment whose left-hand side
is a variable name always mutates the variable, never the
value contained in it. An __assign metamethod would change
that and also block regular assignment.
Better to do something like:
deepcopy(src, dest) -- Mutates dest into a deep copy of src.
A new home for Mom, no cleanup required. All starts here.
Adrien de Croy - WinGate Proxy Server - http://www.wingate.com