Run function from function parameter?

Hello, I have an issue that’s quite difficult to explain.

Let’s say I have a function. It’s called vx.AddChatCmd(). I can do vx.AddChatCmd("/hello", hellofunc). I already have a way of detecting the command, I just want to know how to run the function in the function’s second param (in this case, it’s “hellofunc”)

How would I achieve this?

Store the function in a table, and call it from the table.

For example:

local tab = {}
tab[1] = function(...)


– Command creation example with no arguments.

command = {};
command.all = {};

function command.Add( name, func )
if ( command.all[name] ) then return; end;

command.all[name] = func;


function command.execute(name)
if ( not command.all[name] ) then return; end;

command.all[name](); -- this is the part where the stored command function is executed.


you don’t sound too experienced so i don’t want to confuse you with an ellipsis ( the … )

I’m having a hard time understanding what either of these two do lol…
this is my function:

function vx.AddChatCmd( cmdname, func )
	table.insert(cmds, cmdname)

So I have the commands stored in the table. I don’t know where to progress now.


vx = {};
vx.commands = {};

function vx:AddChatCmd( cmdname, onrun)
if ( self.commands[cmdname] ) then return; end;

self.commands[cmdname] = onrun;


function ChatCmds( client, text, public )
for cmd,func in pairs(vx.commands) do
if ( string.Right( text, string.len(text) - 1 ) == cmd) then
print( “Command '” … text … “’ was executed successfully.” );
return true;

vx:AddChatCmd( “help”, function(client)
print( “You (” … client:Nick() … “) have executed the help command!”);

hook.Add( “PlayerSay”, “AllCmds”, ChatCmds );

feel free to add me to steam

-snip- dammit you crafty ninja!

feel free to correct me im kind of faded i forgot to include a command prefix so you could technically just type #help tHelp 7help anything lol