lots of mod info added
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
|
||||
fakelib = {}
|
||||
|
||||
local function check(n, v, a, b)
|
||||
local t = type(v)
|
||||
if t == a or t == b then
|
||||
return v
|
||||
end
|
||||
local info = debug.getinfo(2, "n")
|
||||
local f = info.name or "?"
|
||||
if info.namewhat ~= "method" then
|
||||
-- Offset argument number when called using '.' instead of ':'
|
||||
n = n + 1
|
||||
end
|
||||
error(string.format("bad argument #%i to '%s' (%s expected, got %s)", n, f, a, t), 3)
|
||||
end
|
||||
|
||||
local function secure_table(t, index, id)
|
||||
setmetatable(t, {
|
||||
__index = index,
|
||||
__newindex = {},
|
||||
__metatable = id,
|
||||
})
|
||||
return t
|
||||
end
|
||||
|
||||
local path = core.get_modpath("fakelib")
|
||||
|
||||
for _,file in pairs({"metadata", "inventory", "player"}) do
|
||||
loadfile(path.."/"..file..".lua")(check, secure_table)
|
||||
end
|
||||
|
||||
dofile(path.."/misc.lua")
|
||||
|
||||
-- Override `core.is_player()` so only real players and fakelib's fake players will pass.
|
||||
core.is_player = fakelib.is_player
|
||||
|
||||
-- Tests are not included in releases, so check for them before registering the command.
|
||||
|
||||
local tests = loadfile(path.."/tests.lua")
|
||||
|
||||
if tests and core.is_singleplayer() then
|
||||
core.register_chatcommand("fakelib_test", {
|
||||
description = "Test fakelib's API.",
|
||||
params = "[<run error tests>]",
|
||||
func = function(_, param)
|
||||
local start_time = core.get_us_time()
|
||||
local success = tests(param == "true")
|
||||
local end_time = core.get_us_time()
|
||||
if success then
|
||||
return true, string.format("Testing completed in %i us", end_time - start_time)
|
||||
end
|
||||
return true, "Testing failed. See console for errors."
|
||||
end,
|
||||
})
|
||||
end
|
||||
Reference in New Issue
Block a user