mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Remove dependency on marshal and many other async changes
This makes a number of changes: * Remove the dependency on marshal by using string.dump and loadstring. * Use lua_tolstring rather than having Lua functions pass string lengths to C++. * Move lua_api/l_async_events.* to cpp_api/s_async.*, where it belongs. * Make AsyncWorkerThread a child of ScriptApiBase, this removes some duplicate functionality. * Don't wait for async threads to shut down. (Is this safe? Might result in corruption if the thread is writing to a file.) * Pop more unused items from the stack * Code style fixes * Other misc changes
This commit is contained in:
parent
db4ea4658c
commit
6ab3b4c838
16 changed files with 571 additions and 1262 deletions
|
@ -1,19 +1,21 @@
|
|||
engine.log("info","Initializing Asynchronous environment")
|
||||
engine.log("info", "Initializing Asynchronous environment")
|
||||
local tbl = engine or minetest
|
||||
|
||||
minetest = tbl
|
||||
dofile(SCRIPTDIR .. DIR_DELIM .. "serialize.lua")
|
||||
dofile(SCRIPTDIR .. DIR_DELIM .. "misc_helpers.lua")
|
||||
|
||||
function engine.job_processor(serialized_function, serialized_data)
|
||||
function tbl.job_processor(serialized_func, serialized_param)
|
||||
local func = loadstring(serialized_func)
|
||||
local param = tbl.deserialize(serialized_param)
|
||||
local retval = nil
|
||||
|
||||
local fct = marshal.decode(serialized_function)
|
||||
local params = marshal.decode(serialized_data)
|
||||
local retval = marshal.encode(nil)
|
||||
|
||||
if fct ~= nil and type(fct) == "function" then
|
||||
local result = fct(params)
|
||||
retval = marshal.encode(result)
|
||||
if type(func) == "function" then
|
||||
retval = tbl.serialize(func(param))
|
||||
else
|
||||
engine.log("error","ASYNC WORKER: unable to deserialize function")
|
||||
tbl.log("error", "ASYNC WORKER: Unable to deserialize function")
|
||||
end
|
||||
|
||||
return retval,retval:len()
|
||||
return retval or tbl.serialize(nil)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue