Function that takes in multiple different types of arguments

It’s a little hard to describe so I will give an example

The BrickColor.new function takes in a string, number, 3 rgb number values, or a Color3. The Lua typechecking changes the name, autofill and docstring of the function depending on the type of input you give it.

Example:
When parsing a number type:

When parsing a string type:

When parsing 3 number types:

When parsing a Color3 type:

I also noticed that on the popup it has a 1 to 4 selection where you can choose between these different syntaxes of the same function.

I think another function with the same quirk is the CFrame.new function

How can I replicate this behavior with a function of my own?

1 Like

export type myEpicFunctionColor3 = (color: Color3) -> BrickColor
export type myEpicFunctionRGB = (r: number, g: number, b: number) -> BrickColor
export type myEpicFunctionString = (name: string) -> BrickColor

export type myEpicFunctionFinal = myEpicFunctionColor3 & myEpicFunctionRGB & myEpicFunctionString

local f: myEpicFunctionFinal

something like that?

8 Likes

Exactly like that! How about the docstrings? Or is that only for Roblox builtins?

You can use ScriptEditorService for documentation. But that requires you to make a plugin that scans the code for it

1 Like

What omega said, I do not know about docstrings for VSCode though.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.