Getting argument types from function

I was wondering if its possible to get arg types from a function without calling it.

e.g
local function f(a: string, b: number, t: {})
    print()
end

is there a way to get the types of the arguments (a: string, b: number, t: {}) without calling the function?

1 Like

There isn’t any way (That I’m aware of) to get the type information from a function; What’s your use case?

If you’re planning to reuse type information from a function, you can use typeof to get the type of the function:

local function foo(a: number) : ()
   --...
end

local bar: typeof(foo) = function(...) -- `bar` will have `foo`'s type information
   --...
end

Are you looking for something like this?

function SoMany(...)
	--[[
	to get individual args just use this
	]]
	local arg = table.pack(...)
	print(arg[1].. " string")
	task.spawn(function()
		for _,v in arg do
			print(type(v))
		end
	end)
	print(...)
end
SoMany("text", true, Player.Name, workspace)

image

Using meta-information like that is generally frowned upon, since there’s always a better way of doing it.

What do you need this for?

For a remoteevent, depending on if the data is correct (secured) it will call a function. One of the checks is going to make sure that all the data passed through the remote event to the server has the same arguments as a certain function. I thought It would be possible because we can get the number of args with debug.info, so why not the values?

@HugeCoolboy2007 Interesting, but not what I’m looking for
@weakroblox35 I’m trying to get arguments directly from a function without calling it