Lua has a really nice no-parenthesis call syntax that coupled with function closures allow me to write the following
local tag = 1
function test(obj)
return
function(str)
return
function (tbl)
tbl.objtag = tag
tbl.objname = str
return tbl
end
end
end
test (tag) "def"
{
}
test tag "def" --error
{
}
However, if I remove the parenthesis around (tag), it results in a compile error. So why does Lua allow no-parenthesis parameters (i.e. “def”) and not no-parenthesis var (table in this case) parameters?
From Programming in Lua:
My understanding of your above situation is that tag is a local variable (which is neither a literal string nor a table constructor), so
test(tag)always requires parentheses. You don’t need parentheses around"def"becausetest(tag)returns a function which accepts a single string, and that function is immediately applied to"def".