lua-users home
lua-l archive

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

On Thu, Feb 10, 2011 at 10:31 PM, Xavier Wang <> 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)

  function t._1() print '1' end

> 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