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" }
)
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 forf({fields})
; that is, the argument list is a single new table. A call of the formf'string'
(orf"string"
orf[[string]])
is syntactic sugar forf('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!'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With