lua-users home
lua-l archive

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




2011/2/11 David Manura <dm.lua@math2.org>
On Thu, Feb 10, 2011 at 10:31 PM, Xavier Wang <weasley.wx@gmail.com> wrote:
> but can not write:
> local t = {}
> function t[1]() end

The closest may be

 local t = {}
 setmetatable(t, {__newindex = function(t,k,v)
   local i = k:match'^_(%d+)$'
   rawset(t, i and tonumber(i) or k, v)
 end})

 function t._1() print '1' end
 t[1]()

> so maybe:
> funcname = var [`:' Name]

var there can lead to some confusion:

 function f(x)[1](y) end

because parenthesis are used in multiple ways in Lua (as well as in
math): _expression_ grouping, function calls, and function argument
lists.

is this confusion?
function foo() end is the semantics sugar of foo = function() end
so function f(x)[1](y) end is the semantics sugar of f(x)[1] = function(y) end

if everyone knows this semantics sugar, I don't think this confusion. e.g. Lua can write f{} for function call, so do you think this confusion?

Form() {
    x = 10,
    y = 10,

    Button() {
        text = "OK"
    }
}

but this is valid Lua code. if you know the truth "lua can call function with table directly", this will not confusion you.