I appreciate the reply! I don't think that's exactly what I'm looking for, but it might be close. Let me give an example.
Say I have a core file with some arbitrary function I may want to call from the chat box with a slash command.
Core.lua
Lua Code:
local _, ns = ...
local ns.Core = {}
function ns.Core.DoSomething(x, y)
print(x * y)
end
Say I also have a debug file with a function the slash command "/addon test" points to, as well as a function to dynamically call another function by providing the url/arguments for said function.
Debug.lua
Lua Code:
local _, ns = ...
local ns.Debug = {}
function ns.Debug.Test(...)
-- url is a string representing the location of the function to call - e.g. "ns.Core.DoSomething"
-- args is a table containing the function's arguments' in order - e.g. { 2, 3 }
url, args = ...
callFunc(url, args)
end
local function callFunc(url, args)
-- Traverse the pairs in each table in the url until you reach the end (the function field)
local funcVar = getFuncVar(url)
-- Call the function
funcVar(args[1], args[2], args[3], ...)
end
In game, I would just type "/addon test ns.core.dosomething ..." and depending on what is actually placed where the "..." appears, the function would either be called if it has all the arguments it needs or the call would be skipped and an error message would be printed to chat.
Line 15 in Debug.lua is where I'd like this check to be. In a standard Lua environment, there is a global called
debug that lets you do this (calling
debug.getinfo(funcVar).nparams would give me exactly what I need), but WoW's custom Lua implementation doesn't include this global.
One last thing, I have all the functionality of this already implemented except the ability to dynamically retrieve the number of arguments a function requires. I can call any of my addon's functions directly from the chat box right now, but if I don't pass the correct number of arguments, it throws an error.