Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Get the name of a function?

Asked by 4 years ago

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
Functions don't have names. They're all anonymous. Do you mean how to get the identifier (variable name, table field name) itself? User#24403 69 — 4y

1 answer

Log in to vote
2
Answered by
Elixcore 1337 Moderation Voter
4 years ago
Edited 4 years ago

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

Ad

Answer this question