Get parameter name & type from a function?

How can I get a parameter’s name & type only given the function:

function Test2Engine.Client:GetMoney(player : Player)
    
end

So that I can extract it into a table:

{
    parameter = "player",
    type = "Player"
}

In a live game? I don’t think you can.

In Studio, you can technically do it through the command line by analysing the source of the code script.Source, then translating it into the table.

(By analysing it, I mean you would process the string that is the source code of the script, looking for any time there is the function keyword, then moving to the subsequent opening bracket ( ( ). From there, you would loop through everything between the commas and the final closing bracket ( ) )

What are you trying to achieve?

2 Likes

Just use generic typing instead, which is syntaxed with <T>.

1 Like

Trying to extract that table as the game runs. This is because im using ByteNet Max to send remote functions, but they need specific types. So if i could get the types & parameters, it would reduce data sending by a lot.

Couldn’t you use ClassName (for instances) or typeof (for primitives) to get the argument type?

As for the name of the parameters, that’s impossible without hardcoding, I’m afraid.

All you are given with is a table of functions. Out of that table of functions, how do you get the type of each parameter in each function?

for _, Engine in pairs(Engines) do
            for VarName, ClientVar in pairs(Engine.Client) do
                if type(ClientVar) == "function" then
                    Queries[VarName] = ByteNetMax.defineQuery({
                        request = ByteNetMax.struct({
                            [parameterName] = ByteNetMax.parameterType
                        })
                    })
                end
            end
        end

It isn’t possible to grab the type information (or name) of a parameter for this specific task

That is depressing. This is a limitation of luau?

Not necessarily a ‘limitation’ but just something that was never implemented

1 Like