lua-users home
lua-l archive

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


2016-04-20 7:20 GMT+02:00 云风 Cloud Wu <cloudwu@gmail.com>:
> We know v:name(args)  is syntactic sugar for v.name(v,args) .
>
> Could we make this syntactic sugar more flexible ? like this :
>
> v:x.name(args) -> v.x.name(v, args)
>
> Maybe it will be more useful especially when v is an userdata with complex
> structures.
>
> v.x can be a type object rather than a value belongs to v ( v1.x == v2.x
> when the type of v1 is the same with v2)

We already have

v.x:name(args) -> v.x.name(v,x, args)

so to complete the punctuation group there should also be

v:x:name(args) -> v.x.name(v,v.x,args).

But why stop at only two? One can assign a meaning to using any
number of colons, i.e.

v:x.y:z(args) -> v.x.y.z(v,v.x.y,args).

The simple rule being: using `:` instead of `.` inserts the partially indexed
object as an argument.