How to define a parameters type in a function? (Lua) | Sololearn: Learn to code for FREE!
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.

4th Aug 2022, 8:15 PM
Jeremiah Jahnke
Jeremiah Jahnke - avatar
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.
6th Aug 2022, 3:36 PM
Jeremiah Jahnke
Jeremiah Jahnke - avatar