lua-users home
lua-l archive

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


On Sep 29, 2010, at 10:39 PM, Peter Sommerfeld wrote:

> There are no confusing similar concepts. Dot is "get value" and
> colon is "call". Easy to grasp, isn't it?

Yes, yes, just sugar... but still... at first glance... OMG!

local aTable = { dwim = function( self ) print( self ) end }

aTable[ 'dwim' ]( aTable )
aTable:dwim()
aTable.dwim()

> table: 0x1001058e0
> table: 0x1001058e0
> nil

WTF?!? :P

To further confuse matters...

local aTable = setmetatable( {}, { __index = function( self, key ) return function() print( self ) end end } )

aTable.dwim()

> table: 0x1001058e0

To paraphrase
Programming in Lua
Part II. Tables and Objects 
Chapter 12. Data Files and Persistence
http://www.lua.org/pil/12.1.2.html

"Lua gives you the power; you [choose how to hang yourself]" :P