lua-users home
lua-l archive

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


While reading Roberto's excellent book (I've compared it to K & R in some
reviews), the final section of the chapter on object-oriented programming
suggested a potential tweak to the self opcode. What if one defined:

    obj:msg( args )

When obj is a function as being:

    obj( "msg", args )

This would allow one to intermix table-based object with function-based
objects without the caller knowing the difference. (I could also see a case
for passing obj into the function, but it could presumably keep the self
reference in an upvalue.)

The downside is that one could no longer describe obj:msg( args ) as
syntactic sugar for obj.msg( obj, args ) but the compiler treats it as more
than just sugar anyway.

Mark