New course! Every coder should learn Generative AI!
Try a free lesson+ 1
How to define a parameters type in a function? (Lua)
Hi, I'm recently trying to make a module for my Lua script, and I was curious on how to define a functions parameter type for example function test(Param1: string, Param2: function) print(Param1) Param2() end test("string", function () print("Callback function") end) I want the function to only be able to run a parameter that is a string and not an int and run a parameter that is a function which indicates the callback. Code example above.
1 Answer
+ 2
Alright, so I've came up with a solution I'm just gonna add block comments inside of the function
For example:
function test(Param1 --[[string]], Param2 --[[function]])
print(Param1)
Param2()
end
test("string", function()
print("string")
end)
Comments don't do much, but this is just giving my function some details so I know which is a function and which is a string.
It's not a permanent solution, but it's okay.