diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-11-28 01:11:17 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-11-29 19:13:56 +0200 |
commit | 30648d1cc987b25ccd2e09e18ee483a6b92e5ec1 (patch) | |
tree | d252b0a2e4dc6fb80edba7f2fc5062004322a371 /data | |
parent | 842eb5da280b09e046531dd03fe9b9b20752ad12 (diff) | |
download | minetest-30648d1cc987b25ccd2e09e18ee483a6b92e5ec1.tar.gz minetest-30648d1cc987b25ccd2e09e18ee483a6b92e5ec1.tar.bz2 minetest-30648d1cc987b25ccd2e09e18ee483a6b92e5ec1.zip |
Implement callback registration in Lua instead of C
Diffstat (limited to 'data')
-rw-r--r-- | data/builtin.lua | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/data/builtin.lua b/data/builtin.lua index b1abeb364..a32761921 100644 --- a/data/builtin.lua +++ b/data/builtin.lua @@ -151,11 +151,24 @@ minetest.register_node("ignore", { -- Chat message processing -- -minetest.registered_on_chat_messages = {} +function make_registration() + local t = {} + local registerfunc = function(func) table.insert(t, func) end + return t, registerfunc +end + +minetest.registered_on_chat_messages, minetest.register_on_chat_message = make_registration() +minetest.registered_globalsteps, minetest.register_globalstep = make_registration() +minetest.registered_on_placenodes, minetest.register_on_placenode = make_registration() +minetest.registered_on_dignodes, minetest.register_on_dignode = make_registration() +minetest.registered_on_punchnodes, minetest.register_on_punchnode = make_registration() +minetest.registered_on_generateds, minetest.register_on_generated = make_registration() +minetest.registered_on_newplayers, minetest.register_on_newplayer = make_registration() +minetest.registered_on_respawnplayers, minetest.register_on_respawnplayer = make_registration() minetest.on_chat_message = function(name, message) for i,func in ipairs(minetest.registered_on_chat_messages) do - ate = func(name, message) + local ate = func(name, message) if ate then return true end @@ -163,8 +176,4 @@ minetest.on_chat_message = function(name, message) return false end -minetest.register_on_chat_message = function(func) - table.insert(minetest.registered_on_chat_messages, func) -end - -- END |