exports
Server
modkit.exports lets one server resource call functions of another. Every resource runs in its own Lua state, so values are copied on the way in and on the way out.
What can cross. nil, booleans, numbers, strings and tables of those, up to 16 levels deep. Functions and userdata can not. A function as a direct argument raises an error, a function inside a table is dropped. Player tables arrive with their methods, because the receiving side rebuilds them from the Steam ID fields.
A resource must be loaded before another one can call it. load lines in server.cfg run top to bottom.
modkit.exports.register
modkit.exports.register(name, fn)
| Parameter | Type | Description |
|---|---|---|
| name | string | export name |
| fn | function | may take and return several values |
-- resource "bank"
local balance = {}
modkit.exports.register("add", function(steamId, amount)
balance[steamId] = (balance[steamId] or 0) + amount
return balance[steamId]
end)
modkit.exports.call
modkit.exports.call(resource, name, ...)
Returns: what the exported function returns.
Raises an error when the resource is not running, the export does not exist, or the exported function fails. The message of the inner error is part of the new one. Use pcall when the other resource is optional.
local total = modkit.exports.call("bank", "add", player.steamId, 50)
modkit.exports..
modkit.exports.bank.add(player.steamId, 50) is the same call in short form. It works for every resource name except register, call and list.
local ok, total = pcall(modkit.exports.bank.add, player.steamId, 50)
modkit.exports.list
modkit.exports.list(resource)
Returns: array of export names, or nil when the resource is not running.