lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


example with table of functions:

local T = {}
function T.func1() print("func1") end
function T.func2() print("func2") end

local fn = { "func1", "func2", "func3" }

for i = 1, 3 do
local func_name = fn[i]
pcall(T[func_name])
end

it is work, but I'm interested in the ability to call a local function:

local function func1() print("local func1") end
local function func2() print("local func2") end

local fn = { "func1", "func2", "func3" }

for i = 1, 3 do
local func_name = fn[i]
pcall(func_name) -- ???
end

of course, I get an error "attempt to call a string value".