Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Piece of Lua syntax that I don't understand

I'm using a Lua-based product, I'm using their API and there is a bit of syntax in there that I don't understand.

What is this? Is it a function call for Add, and if so what are the input parameters - there's nothing assigning that table to the variable input - no equals sign?

Is it a function definition for Add - that would seem odd, without any implementation and specifying what goes into the input tables?

Is Add a table containing tables? I've never seen a table created with parentheses instead of curly braces?

serviceDefinitions.Add(
    input { name="p1", baseType="NUMBER", description="The first addend of the 
    operation" },
    input { name="p2", baseType="NUMBER", description="The second addend of the operation" },
    output { baseType="NUMBER", description="The sum of the two parameters" },
    description { "Add two numbers" }
)
like image 973
AdamLevineButNotThatAdamLevine Avatar asked Jan 30 '23 20:01

AdamLevineButNotThatAdamLevine


1 Answers

When calling functions where there is only a single argument that is a table or string you can omit the parenthesis. From the manual:

All argument expressions are evaluated before the call. A call of the form f{fields} is syntactic sugar for f({fields}); that is, the argument list is a single new table. A call of the form f'string' (or f"string" or f[[string]]) is syntactic sugar for f('string'); that is, the argument list is a single literal string.

Which means that the following functions calls are valid:

somefunction({1,2,3,4})
somefunction{1,2,3,4}

Or, with strings:

print('hello!')
print 'hello!'
like image 122
Adam Avatar answered Feb 12 '23 06:02

Adam