lua-users home
lua-l archive

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

Doug Rogers wrote:

I've been thinking, which isn't a good sign...

On another thread I mentioned that I liked the colon notation and wished that it could be applied to all types; ...
For now I just want to discuss it.

I think it would be nice to extend the use of '.' and ':' to all types. ... I was thinking that each non-table, non-nil type - 'number', 'string', 'thread', 'boolean' - would have its own table with a metatable attached with __index set to that table. This would allow the VM to easily (and quickly) push the table associated with the type onto the stack before attempting to index a non-table type. 'nil' would still result in an error.
I like the idea, and I'm wondering what others think. Am I the only one who loves the colon notation and wishes that it applied to all the built-in types?

sorry, but nonononononono
one of the things i like about lua is it's first-class objects.
a number is a number. if i want an object, it can be a table.
(how would the lua chip/pda/arm people like every number to have a metatable ?)

as for the colon syntax
a:func(...) <=> a.func(a,...) is a simple enough syntax for me.
the main advantage is that you can say
without a local var.

as i see it, the simplest way to generalise the colon operator would be to define
a:func(...) => (a.func or func)(a,...)

put that way, it looks a bit ugly;
i could live with that... but i don't need it,
 and i don't want to contemplate the core changes required.