mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Add generic IPC mechanism between Lua envs
This commit is contained in:
parent
06907aa99b
commit
f1a436619f
12 changed files with 191 additions and 19 deletions
|
@ -6855,17 +6855,6 @@ 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_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
|
||||
follow the `modname:name` convention for this identifier.
|
||||
* `mt` is the metatable to register.
|
||||
* Note that it is allowed to register the same metatable under multiple
|
||||
names, but it is not allowed to register multiple metatables under the
|
||||
same name.
|
||||
* You must register the metatable in both the main environment
|
||||
and the async environment for this mechanism to work.
|
||||
|
||||
|
||||
### List of APIs available in an async environment
|
||||
|
@ -6895,7 +6884,8 @@ Functions:
|
|||
|
||||
* Standalone helpers such as logging, filesystem, encoding,
|
||||
hashing or compression APIs
|
||||
* `minetest.register_portable_metatable` (see above)
|
||||
* `minetest.register_portable_metatable`
|
||||
* IPC
|
||||
|
||||
Variables:
|
||||
|
||||
|
@ -6973,6 +6963,7 @@ Functions:
|
|||
* `minetest.get_node`, `set_node`, `find_node_near`, `find_nodes_in_area`,
|
||||
`spawn_tree` and similar
|
||||
* these only operate on the current chunk (if inside a callback)
|
||||
* IPC
|
||||
|
||||
Variables:
|
||||
|
||||
|
@ -7050,6 +7041,31 @@ Server
|
|||
this can make transfer of bigger files painless (if set up). Nevertheless
|
||||
it is advised not to use dynamic media for big media files.
|
||||
|
||||
IPC
|
||||
---
|
||||
|
||||
The engine provides a generalized mechanism to enable sharing data between the
|
||||
different Lua environments (main, mapgen and async).
|
||||
It is essentially a shared in-memory key-value store.
|
||||
|
||||
* `minetest.ipc_get(key)`:
|
||||
* Read a value from the shared data area.
|
||||
* `key`: string, should use the `"modname:thing"` convention to avoid conflicts.
|
||||
* returns an arbitrary Lua value, or `nil` if this key does not exist
|
||||
* `minetest.ipc_set(key, value)`:
|
||||
* Write a value to the shared data area.
|
||||
* `key`: as above
|
||||
* `value`: an arbitrary Lua value, cannot be or contain userdata.
|
||||
|
||||
Interacting with the shared data will perform an operation comparable to
|
||||
(de)serialization on each access.
|
||||
For that reason modifying references will not have any effect, as in this example:
|
||||
```lua
|
||||
minetest.ipc_set("test:foo", {})
|
||||
minetest.ipc_get("test:foo").subkey = "value" -- WRONG!
|
||||
minetest.ipc_get("test:foo") -- returns an empty table
|
||||
```
|
||||
|
||||
Bans
|
||||
----
|
||||
|
||||
|
@ -7449,6 +7465,17 @@ Misc.
|
|||
* `minetest.global_exists(name)`
|
||||
* Checks if a global variable has been set, without triggering a warning.
|
||||
|
||||
* `minetest.register_portable_metatable(name, mt)`:
|
||||
* Register a metatable that should be preserved when Lua data is transferred
|
||||
between environments (via IPC or `handle_async`).
|
||||
* `name` is a string that identifies the metatable. It is recommended to
|
||||
follow the `modname:name` convention for this identifier.
|
||||
* `mt` is the metatable to register.
|
||||
* Note that the same metatable can be registered under multiple names,
|
||||
but multiple metatables must not be registered under the same name.
|
||||
* You must register the metatable in both the main environment
|
||||
and the async environment for this mechanism to work.
|
||||
|
||||
Global objects
|
||||
--------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue