summaryrefslogtreecommitdiff
path: root/builtin/async_env.lua
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-04-15 13:41:07 -0400
committerShadowNinja <shadowninja@minetest.net>2014-04-27 16:15:53 -0400
commit6ab3b4c83856b5c8a1a526c0e4dc55babe79d50d (patch)
tree90e64f78dd3ceac12dbb21ac6b045500de0ca603 /builtin/async_env.lua
parentdb4ea4658c58772ee447ff0eff8bb39b692081ec (diff)
downloadminetest-6ab3b4c83856b5c8a1a526c0e4dc55babe79d50d.tar.gz
minetest-6ab3b4c83856b5c8a1a526c0e4dc55babe79d50d.tar.bz2
minetest-6ab3b4c83856b5c8a1a526c0e4dc55babe79d50d.zip
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
Diffstat (limited to 'builtin/async_env.lua')
-rw-r--r--builtin/async_env.lua24
1 files changed, 13 insertions, 11 deletions
diff --git a/builtin/async_env.lua b/builtin/async_env.lua
index afc69219c..cdcb82ee3 100644
--- a/builtin/async_env.lua
+++ b/builtin/async_env.lua
@@ -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
+