Right now, defining functions as parameters for a method in Luau requires them to have a specific signature. While optimal for type checking and enforcement, this has been mildly irritating for the select cases where a function of any signature can be passed into something.
Right now, I have to do this:
function DoSomething(func: any) assert(typeof(func) == "function", "Invalid type for parameter 'func' (Expected function, got " .. typeof(func) .. ")") end
In this feature proposition, I ask for a new replacement to this behavior:
function DoSomething(func: delegate) -- func must be just a function in general. Its signature does not matter. end
Use cases for this behavior most commonly arise in libraries featuring custom callbacks where the parameters and return types are user defined as they are registered, and where the user is also the one invoking those callbacks with their own input parameters and/or return type(s).
I want to use the term
delegate so that issues with using a Lua keyword in certain contexts where it would normally be unusable don’t arise.