In World of Warcraft addons, a table is passed as the second vararg:
-- This is often at the top of WoW lua files
local AddonTable = select(2, ...)
Is there a way to do that with regular lua? I’m attempting to write some unit tests with minimal changes to my current code. So far when I just use require, I can use select(1, ...) to get the first parameter to require (the module), but I can’t seem to figure out how to populate the second argument.
Update:
Instead of using require, I can use loadfile to do what I need. When World Of Warcraft loads an addon, it passes the name of the addon and a table that can be populated with your addon’s functions. I can reproduce that functionality with this code:
local addon = loadfile('MyAddon.lua')
local AddonTable = {}
addon('AddonName', AddonTable)
To rephrase your question:
First understand that all that is happening in wow is your lua file is being lua_loadfile’d, then the resulting closure is being executed with 2 parameters on the stack.
This is similar to what require is doing from an outside perspective, but when you think it through it is different.
Require returns the module – that is the equivalent to the WoW table that is the 2nd arguement. The parameter to require (the name of the module) is the equivalent of the first.