Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Get the name of a function?

Hello, im trying to make admin commands but i want to know how to get the name of a function, i don't have any idea to do it, is there a way?, and if there is then how do i do it?

1 comment

1

Functions don't have names. They're all anonymous. Do you mean how to get the identifier (variable name, table field name) itself?

1 answer

✓ Accepted answer

Your best bet is dictionaries.

through dictionaries you can access the index as the function's name.

dic = {}

function dic.say(arg)
	print(arg) 
end

dic.say('hello') --> Output: hello

now that the function is defined you can always index it or iterate through the dictionary to find it.

--indexing

print( dic[say] ) -- prints function

-- iterating

for i,v in next, dic do
	print(i, v) -- i = index (say)  -  v = function
end

This discussion is preserved as it was. New answers, comments, and votes are closed.