Passing Module Parameter to call Function

Is there some way to target a function using a variable?

e.g.

local number = 42

Then call function M[42] in a required module (ModA) by using the number variable e.g.

reqMod.number()

Really not sure what you mean…

local function doStuff() end local list = {} list[1] = doStuff

-- a different module (lua file), say, codestuff.lua. It doesn't really matter local stuff = {} function stuff.runFast() end stuff[1] = stuff.runFast -- now stuff[1]() and stuff.runFast() are the same return stuff -- a file other than codestuff.lua local myModule = require("codestuff") local fun = 1 myModule[fun]() -- Calls runFast()

Thank You Richard9. I was across the array approach assigned to function names but didn’t know you could state: myModulefun That is the magic call for this problem. Will try that now :slight_smile:

Really not sure what you mean…

local function doStuff() end local list = {} list[1] = doStuff

-- a different module (lua file), say, codestuff.lua. It doesn't really matter local stuff = {} function stuff.runFast() end stuff[1] = stuff.runFast -- now stuff[1]() and stuff.runFast() are the same return stuff -- a file other than codestuff.lua local myModule = require("codestuff") local fun = 1 myModule[fun]() -- Calls runFast()

Thank You Richard9. I was across the array approach assigned to function names but didn’t know you could state: myModulefun That is the magic call for this problem. Will try that now :slight_smile: