I noticed something kinda weird about print()
in roblox, or really just something that isnt very intuitive to me.
In lua, stuff like math
or string
are tables that contain functions related to them.
If you do something like print(type(print)
you get a function. Furthermore, how come I can do stuff like this?
print"yo" print[[yo]]
Even though I'm not calling the print function like this, print()
; how does the script know the difference between calling the function with ()
and me just writing the name of the function?
Ive also noticed you can only do it with strings (afaik) so you can only do things like this:
local function epicPrintWrapper(String) print(String) end epicPrintWrapper"Heyy"
That is just how the developer made the syntax. You can call any function with an argument type of string
or table
without it being encased in parentheses. Lua knows the difference because it was explicitly written in its source.
some sugar
function foo(tbl) return tbl[1] * 2 end local x = foo{2} --> 4 function bar(str) return str .. "1" end local y = bar"hello" --> hello1 print"hello " .. "sir" --> compilation error print("hello " .. "sir") -- >> hello sir print"hello sir" -- >> hello sir
Remember that you can only call a function in Lua like this with only 1 required argument, and that you can only do it with string's or table's.