5

The following gives me an error 'syntax error near 'Person' even though in the faq (http://www.luafaq.org/) it stats: "so it cleverly uses the fact that Lua will accept single function arguments without parentheses if the argument is a string or a table"

function class(cls)
   return cls
end

Person = {}

class Person

print(Person)

What am I missing here? If I change class Person to class "Person" it works, but the faq stats it should work with both strings and tables.

1 Answer 1

6

The parentheses can only be omitted when there is only one argument, and the argument is a string literal or a table constructor.

In your example, syntactically, you can call class 'foo' or class {}, but not class Person, because Person is a variable, not a table constructor.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah interesting. The FAQ didn't say table constructor but just table. That's a bummer. Thanks.
@user441521, the manual says explicitly: args ::= tableconstructor at lua.org/manual/5.2/manual.html#3.4.9 and lua.org/manual/5.3/manual.html#3.4.10.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.