lua-users home
lua-l archive

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


To me, this particular syntax doesn't look like a function call. It looks more like an rvalue.  For what it's worth, I think I would prefer to reserve that syntax for something like wrapping/anonymizing a "method" function. ie:

  local myFunc = self:theirFunc

The above being equivalent to:
  local myFunc = function(...) self:theirFunc(...) end


On Thu, Jun 11, 2015 at 5:26 AM Rodrigo Azevedo <rodrigoams@gmail.com> wrote:
REASONING

There are uncountable examples of "methods" that do not need an argument, for example

led[1]:blink
arm[2].pos[3]:go
z:abs
z:Re
polynomial:diff
etc

PROPOSAL

Raise the "methods" syntactic sugar ":" to a function call without arguments, with the exception of the ubiquitous "self", namely, call "methods" without the common usage of  '(' ')', or '{' '}' or ' " ' ' " '.

PATCH

This patch applies a minimalist update of lparser.c to implement the described behaviour.

For Lua 5.3.0

EXAMPLE USAGE

unpack, istable = table.unpack, function(t) return type(t) == 'table' end

t = {}
t.name = "testing ... "
function t:prt (str) print(self.name .. ((istable(str) and str[1]) or str or "") .. " OK") end

t:prt -- NEW!

t:prt ()
t:prt "string"
t:prt {"table"}

t:prt
("ambiguity")

t:prt
(print("OI"))

print("c'est fini")

--
Rodrigo Azevedo Moreira da Silva