lua-users home
lua-l archive

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

Rici Lake wrote:
Now, suppose I actually want to invoke an object method, instead of calling a function? I could do that with an explicit wrapper:

  table.foreach(tab, function(k, v) return obj:method(k, v) end)

but that would get tedious, so I would want to refactor it:

function table.foreachmeth(obj, tab, method)
  for k, v in pairs(tab) do
    local rv = obj[method](obj, k, v)
    if rv then return rv end

Right. But if Lua understood that obj[method] was a member function, it could push it implicitly always. And that would get rid of the ':' vs '.' issue as well. You always use '.' and the runtime decides which functions are object methods and which are static. This might require some additional syntax at the point of function declaration, but that should not be too hard.

Anyway, never satisfied :-)

chris marrin                ,""$,          b`    $                             ,,.
                        mP     b'                            , 1$'
        ,.`           ,b`    ,`                              :$$'
     ,|`             mP    ,`                                       ,mm
   ,b"              b"   ,`            ,mm      m$$    ,m         ,`P$$
  m$`             ,b`  .` ,mm        ,'|$P   ,|"1$`  ,b$P       ,`  :$1
 b$`             ,$: :,`` |$$      ,`   $$` ,|` ,$$,,`"$$     .`    :$|
b$|            _m$`,:`    :$1   ,`     ,$Pm|`    `    :$$,..;"'     |$:
P$b,      _;b$$b$1"       |$$ ,`      ,$$"             ``'          $$
 ```"```'"    `"`         `""`        ""`                          ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'