Passing a table without parentheses in Lua gives an error

The following gives the error near’Person” grammatical error, even in the faq (http://www.luafaq.org/) its statistics: “So it is clever Use the fact that Lua will accept a single function parameter without parentheses, if the parameter is a string or a table”

function class(cls)
return cls
end

Person = {}

class Person

print(Person)

I am here What did you miss? If I change the class Person to the class “Person” it works, but faq statistics it should work for strings and tables.

< div class="answer"> When there is only one parameter, you can only omit the parentheses, and the parameter is a string literal or a table constructor.

In your example, syntactically speaking, you The class’foo’ or class () can be called, but the class Person cannot be called, because Person is a variable, not a table constructor.

The’Person’ is given below The error near the’syntax error, even in the faq (http://www.luafaq.org/) its statistics: “So it cleverly uses the fact that Lua will accept a single function parameter but no parentheses, if the parameter is String or table”

function class(cls)
return cls
end

Person = {}

class Person

print(Person)

What am I missing here? If I change the class Person to the class “Person” it works, but faq statistics should apply to strings and tables.

When there is only one parameter, Only the parentheses can be omitted, and the parameters are string literals or table constructors.

In your example, syntactically speaking, you can call class’foo’ or class (), but The class Person cannot be called because Person is a variable, not a table constructor.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3255 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.