aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2013-12-07 22:03:07 -0500
committerShadowNinja <shadowninja@minetest.net>2013-12-07 22:03:07 -0500
commita0dce51af62e41ddda312b7e877f6a350667a17d (patch)
tree3fe206d3ba561df2a708668a57659bce2904a011 /builtin
parent96f753a108600619f94015bf889a73d97e44ce3a (diff)
downloadminetest-a0dce51af62e41ddda312b7e877f6a350667a17d.tar.gz
minetest-a0dce51af62e41ddda312b7e877f6a350667a17d.tar.bz2
minetest-a0dce51af62e41ddda312b7e877f6a350667a17d.zip
Move script_run_callbacks to Lua
Diffstat (limited to 'builtin')
-rw-r--r--builtin/misc_register.lua39
1 files changed, 39 insertions, 0 deletions
diff --git a/builtin/misc_register.lua b/builtin/misc_register.lua
index 54022a361..249d272eb 100644
--- a/builtin/misc_register.lua
+++ b/builtin/misc_register.lua
@@ -314,6 +314,45 @@ minetest.register_item(":", {
groups = {not_in_creative_inventory=1},
})
+
+function minetest.run_callbacks(callbacks, mode, ...)
+ assert(type(callbacks) == "table")
+ local cb_len = #callbacks
+ if cb_len == 0 then
+ if mode == 2 or mode == 3 then
+ return true
+ elseif mode == 4 or mode == 5 then
+ return false
+ end
+ end
+ local ret = nil
+ for i = 1, cb_len do
+ local cb_ret = callbacks[i](...)
+
+ if mode == 0 and i == 1 then
+ ret = cb_ret
+ elseif mode == 1 and i == cb_len then
+ ret = cb_ret
+ elseif mode == 2 then
+ if not cb_ret or i == 1 then
+ ret = cb_ret
+ end
+ elseif mode == 3 then
+ if cb_ret then
+ return cb_ret
+ end
+ ret = cb_ret
+ elseif mode == 4 then
+ if (cb_ret and not ret) or i == 1 then
+ ret = cb_ret
+ end
+ elseif mode == 5 and cb_ret then
+ return cb_ret
+ end
+ end
+ return ret
+end
+
--
-- Callback registration
--