Calling a function without parentheses?

I was trying to learn about Roact, so I installed the module.
One thing that intrigued me was these lines of code:

local robloxReconciler = createReconciler(RobloxRenderer)
local reconcilerCompat = createReconcilerCompat(robloxReconciler)

local Roact = strict {
	Component = require(script.Component),
	createElement = require(script.createElement),
	createFragment = require(script.createFragment),

How is this valid syntax? I’ve never seen this before.

image

1 Like

You can pass tables and strings directly without having to use parentheses on single-argument functions because it was a valid syntax in Lua 5.1.4 and Luau is based on Lua 5.1.4 so it stayed like that. Though it’s better to call it with parentheses to avoid ambiguity:

print"This is valid." --Passes "This is valid." string as the first argument.
print{"This is also valid."} --Passes a table with string "This is also valid." assigned to the 1st numeric key in it.
print("This is valid too.") --Passes "This is valid too." string as the first argument.

--Output
-->This is valid.
-->table: 0x5674bb6559459dc7
-->This is valid too.
1 Like