Call a function dynamicly

I am making a chat command registrer and i need to be able to dynamicly call a function. As in call a function like table"func" but i dont think thats working. here’s the code:



Ener_Cmds = {}
Pref = "~"
function RegCmd(text,func,restric)
	local Data = {}
	Data["txt"] = text
	Data["func"] = func
	Data["restricted"] = restric
	PrintTable(Data)
	table.insert(Ener_Cmds,Data)
end
function HandleChat(ply,txt)
	
end
hook.Add("OnPlayerChat","EnerChatHandle",HandleChat)
function TestChat(txt)
	print(txt)
end
RegCmd("test",TestChat,false)


its what to do inside of HandleChat that i really dont know what do to.

[lua]Ener_Cmds = {}
Pref = “~”

local function RegCmd(text, restric, func)
local Data = {}
Data[“txt”] = text
Data[“func”] = func
Data[“restricted”] = restric
table.insert(Ener_Cmds,Data)
end

local function HandleChat(ply,txt)

local str = string.Explode(" ",txt)

for k, v in ipairs(Ener_Cmds) do

    if str[1] == Pref..v.txt then
        table.remove(str,1)
        if v.restricted and not ply:IsAdmin() then return end
        v.func(unpack(str))
        return ""
    end
    
end

end

hook.Add(“PlayerSay”,“EnerChatHandle”,HandleChat)

– Will print everything after the command.
RegCmd(“print”, false, function(…)
print(table.concat({…}," "))
end)

– Helper function for the slap command
local function FindPlayerByName(str)
for k,v in ipairs(player.GetAll()) do
if string.find(v:Nick(),str) then return v end
end
end

– Takes 2 arguments, the player’s name and the amount of damage. Not optimized.
RegCmd(“slap”, true, function(name,damage)
local ply, damage = FindPlayerByName(name), tonumber(damage)
if not ValidEntity(ply) or not damage then return end
ply:TakeDamage(damage)
end)[/lua]
:science:

Tell me if you need anything explained.