Rename minetest.register_async_metatable to minetest.register_portable_metatable (#14895)

This commit is contained in:
y5nw 2024-08-02 00:13:25 +02:00 committed by GitHub
parent d566b0e280
commit 8bff2f23c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 12 deletions

@ -1,6 +1,6 @@
-- Registered metatables, used by the C++ packer
local known_metatables = {}
function core.register_async_metatable(name, mt)
function core.register_portable_metatable(name, mt)
assert(type(name) == "string", ("attempt to use %s value as metatable name"):format(type(name)))
assert(type(mt) == "table", ("attempt to register a %s value as metatable"):format(type(mt)))
assert(known_metatables[name] == nil or known_metatables[name] == mt,
@ -10,4 +10,10 @@ function core.register_async_metatable(name, mt)
end
core.known_metatables = known_metatables
core.register_async_metatable("__builtin:vector", vector.metatable)
function core.register_async_metatable(...)
core.log("deprecated", "minetest.register_async_metatable is deprecated. " ..
"Use minetest.register_portable_metatable instead.")
return core.register_portable_metatable(...)
end
core.register_portable_metatable("__builtin:vector", vector.metatable)

@ -6715,7 +6715,7 @@ This allows you easy interoperability for delegating work to jobs.
* Register a path to a Lua file to be imported when an async environment
is initialized. You can use this to preload code which you can then call
later using `minetest.handle_async()`.
* `minetest.register_async_metatable(name, mt)`:
* `minetest.register_portable_metatable(name, mt)`:
* Register a metatable that should be preserved when data is transferred
between the main thread and the async environment.
* `name` is a string that identifies the metatable. It is recommended to
@ -6755,7 +6755,7 @@ Functions:
* Standalone helpers such as logging, filesystem, encoding,
hashing or compression APIs
* `minetest.register_async_metatable` (see above)
* `minetest.register_portable_metatable` (see above)
Variables:

@ -167,18 +167,18 @@ local function test_userdata_passing2(cb, _, pos)
end
unittests.register("test_userdata_passing2", test_userdata_passing2, {map=true, async=true})
local function test_async_metatable_override()
assert(pcall(core.register_async_metatable, "__builtin:vector", vector.metatable),
local function test_portable_metatable_override()
assert(pcall(core.register_portable_metatable, "__builtin:vector", vector.metatable),
"Metatable name aliasing throws an error when it should be allowed")
assert(not pcall(core.register_async_metatable, "__builtin:vector", {}),
assert(not pcall(core.register_portable_metatable, "__builtin:vector", {}),
"Illegal metatable overriding allowed")
end
unittests.register("test_async_metatable_override", test_async_metatable_override)
unittests.register("test_portable_metatable_override", test_portable_metatable_override)
local function test_async_metatable_registration(cb)
local function test_portable_metatable_registration(cb)
local custom_metatable = {}
core.register_async_metatable("unittests:custom_metatable", custom_metatable)
core.register_portable_metatable("unittests:custom_metatable", custom_metatable)
core.handle_async(function(x)
-- unittests.custom_metatable is registered in inside_async_env.lua
@ -193,7 +193,7 @@ local function test_async_metatable_registration(cb)
cb()
end, setmetatable({}, custom_metatable))
end
unittests.register("test_async_metatable_registration", test_async_metatable_registration, {async=true})
unittests.register("test_portable_metatable_registration", test_portable_metatable_registration, {async=true})
local function test_vector_preserve(cb)
local vec = vector.new(1, 2, 3)

@ -3,7 +3,7 @@ unittests = {}
core.log("info", "Hello World")
unittests.custom_metatable = {}
core.register_async_metatable("unittests:custom_metatable", unittests.custom_metatable)
core.register_portable_metatable("unittests:custom_metatable", unittests.custom_metatable)
local function do_tests()
assert(core == minetest)