I'm trying to make a modular mod which works like this:
A central mod, called Busy Bots, acts as a controller for other plug-in modules which contain jobs, like cutting trees, laying concrete, upgrading buildings, etc, that would be performed by construction bots in the radii of roboports. The central module would care for the logistics network, ensuring there are always free construction bots, balancing the load between the client modules, etc. All the interaction between those modules would be performed through interfaces.
So, I have interface.lua in Busy Bots, which reads:
Code: Select all
remote.add_interface("busy-bots",
{
-- Registers a job to be worked by Busy Bots
-- @param job - a table with these key/values:
---- @key name - @value the name of the interface for calling back the job being registered.
---- That interface must implement a function "doJob" with this contract:
------ @param worker - a table with the format {roboport = roboport,
------ name = string}, roboport is guaranteed to be
------ a roboport Entity with "roboport" in its name
------ (no Factorissimo buildings, no Recharging
------ stations, etc)
------ @param amount - an allowance of how many construction jobs it
------ can order
------ @return a count of how many jobs it actually performed
------
------ doJob is responsible for not ordering more construction jobs
------ than its allowed amount.
---- @key prior - @value a number for this job's priority. The lowest the number, the
-- most robots will be allowed to perform this job
registerJob = function(job)
global.Registry.registerJob(job)
end
}
)
Code: Select all
function Registry.registerJob (job)
if not global.jobs_[job] then
-- register the job, etc
end
end
The problem is, when the client calls
Code: Select all
global.job = {name="Concreteer", prior=10}
remote.call("busy-bots", "registerJob", global.job)
Code: Select all
Error while running the on_init:
Error when running interface function busy-bots.registerJob: __CpeBusyBots__/registry.lua:26: attempt to index upvalue '_ENV' (a nil value)
stack traceback:
__CpeConcreteer__/concreteer.lua:179: in function 'load'
__CpeConcreteer__/control.lua:7: in function <__CpeConcreteer__/control.lua:7>
I'm not explicitly referring _ENV anywhere in my code.
Any clues about what am I doing wrong?
As for background, I'm a programmer with more than 20 years in the job, with large experience with Java but very little with Lua. I'm using Factorio modding as a learning tool for Lua.