mirror of
https://github.com/minetest/minetest.git
synced 2024-08-19 04:54:18 +02:00
Add missing item alias metatables to async environment (#12458)
This commit is contained in:
parent
34f15259fa
commit
fc3460470a
@ -25,11 +25,13 @@ do
|
|||||||
local all = assert(core.transferred_globals)
|
local all = assert(core.transferred_globals)
|
||||||
core.transferred_globals = nil
|
core.transferred_globals = nil
|
||||||
|
|
||||||
-- reassemble other tables
|
|
||||||
all.registered_nodes = {}
|
all.registered_nodes = {}
|
||||||
all.registered_craftitems = {}
|
all.registered_craftitems = {}
|
||||||
all.registered_tools = {}
|
all.registered_tools = {}
|
||||||
for k, v in pairs(all.registered_items) do
|
for k, v in pairs(all.registered_items) do
|
||||||
|
-- Disable further modification
|
||||||
|
setmetatable(v, {__newindex = {}})
|
||||||
|
-- Reassemble the other tables
|
||||||
if v.type == "node" then
|
if v.type == "node" then
|
||||||
all.registered_nodes[k] = v
|
all.registered_nodes[k] = v
|
||||||
elseif v.type == "craftitem" then
|
elseif v.type == "craftitem" then
|
||||||
@ -43,3 +45,15 @@ do
|
|||||||
core[k] = v
|
core[k] = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- For tables that are indexed by item name:
|
||||||
|
-- If table[X] does not exist, default to table[core.registered_aliases[X]]
|
||||||
|
local alias_metatable = {
|
||||||
|
__index = function(t, name)
|
||||||
|
return rawget(t, core.registered_aliases[name])
|
||||||
|
end
|
||||||
|
}
|
||||||
|
setmetatable(core.registered_items, alias_metatable)
|
||||||
|
setmetatable(core.registered_nodes, alias_metatable)
|
||||||
|
setmetatable(core.registered_craftitems, alias_metatable)
|
||||||
|
setmetatable(core.registered_tools, alias_metatable)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
-- Minetest: builtin/misc_register.lua
|
-- Minetest: builtin/register.lua
|
||||||
|
|
||||||
local S = core.get_translator("__builtin")
|
local S = core.get_translator("__builtin")
|
||||||
|
|
||||||
|
@ -123,10 +123,10 @@ local function test_handle_async(cb)
|
|||||||
|
|
||||||
core.handle_async(func, function(...)
|
core.handle_async(func, function(...)
|
||||||
if not deepequal(expect, {...}) then
|
if not deepequal(expect, {...}) then
|
||||||
cb("Values did not equal")
|
return cb("Values did not equal")
|
||||||
end
|
end
|
||||||
if core.get_last_run_mod() ~= expect[1] then
|
if core.get_last_run_mod() ~= expect[1] then
|
||||||
cb("Mod name not tracked correctly")
|
return cb("Mod name not tracked correctly")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Test passing of nil arguments and return values
|
-- Test passing of nil arguments and return values
|
||||||
@ -134,7 +134,7 @@ local function test_handle_async(cb)
|
|||||||
return a, b
|
return a, b
|
||||||
end, function(a, b)
|
end, function(a, b)
|
||||||
if b ~= 123 then
|
if b ~= 123 then
|
||||||
cb("Argument went missing")
|
return cb("Argument went missing")
|
||||||
end
|
end
|
||||||
cb()
|
cb()
|
||||||
end, nil, 123)
|
end, nil, 123)
|
||||||
@ -151,7 +151,7 @@ local function test_userdata_passing2(cb, _, pos)
|
|||||||
return vm_:get_node_at(pos_)
|
return vm_:get_node_at(pos_)
|
||||||
end, function(ret)
|
end, function(ret)
|
||||||
if not deepequal(expect, ret) then
|
if not deepequal(expect, ret) then
|
||||||
cb("Node data mismatch (one-way)")
|
return cb("Node data mismatch (one-way)")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- VManip: test a roundtrip
|
-- VManip: test a roundtrip
|
||||||
@ -159,7 +159,7 @@ local function test_userdata_passing2(cb, _, pos)
|
|||||||
return vm_
|
return vm_
|
||||||
end, function(vm2)
|
end, function(vm2)
|
||||||
if not deepequal(expect, vm2:get_node_at(pos)) then
|
if not deepequal(expect, vm2:get_node_at(pos)) then
|
||||||
cb("Node data mismatch (roundtrip)")
|
return cb("Node data mismatch (roundtrip)")
|
||||||
end
|
end
|
||||||
cb()
|
cb()
|
||||||
end, vm)
|
end, vm)
|
||||||
|
@ -36,6 +36,7 @@ local function await(invoke)
|
|||||||
called_early = {...}
|
called_early = {...}
|
||||||
else
|
else
|
||||||
coroutine.resume(co, ...)
|
coroutine.resume(co, ...)
|
||||||
|
co = nil
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
if called_early ~= true then
|
if called_early ~= true then
|
||||||
|
@ -2,7 +2,7 @@ unittests = {}
|
|||||||
|
|
||||||
core.log("info", "Hello World")
|
core.log("info", "Hello World")
|
||||||
|
|
||||||
function unittests.async_test()
|
local function do_tests()
|
||||||
assert(core == minetest)
|
assert(core == minetest)
|
||||||
-- stuff that should not be here
|
-- stuff that should not be here
|
||||||
assert(not core.get_player_by_name)
|
assert(not core.get_player_by_name)
|
||||||
@ -11,5 +11,15 @@ function unittests.async_test()
|
|||||||
-- stuff that should be here
|
-- stuff that should be here
|
||||||
assert(ItemStack)
|
assert(ItemStack)
|
||||||
assert(core.registered_items[""])
|
assert(core.registered_items[""])
|
||||||
return true
|
-- alias handling
|
||||||
|
assert(core.registered_items["unittests:steel_ingot_alias"].name ==
|
||||||
|
"unittests:steel_ingot")
|
||||||
|
end
|
||||||
|
|
||||||
|
function unittests.async_test()
|
||||||
|
local ok, err = pcall(do_tests)
|
||||||
|
if not ok then
|
||||||
|
core.log("error", err)
|
||||||
|
end
|
||||||
|
return ok
|
||||||
end
|
end
|
||||||
|
@ -24,7 +24,7 @@ local function test_dynamic_media(cb, player)
|
|||||||
to_player = player:get_player_name(),
|
to_player = player:get_player_name(),
|
||||||
}, function(name)
|
}, function(name)
|
||||||
if not call_ok then
|
if not call_ok then
|
||||||
cb("impossible condition")
|
return cb("impossible condition")
|
||||||
end
|
end
|
||||||
cb()
|
cb()
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user