Page 1 of 1

[mod] Callbacks API [v0.1][callbacks_api]

PostPosted: Sat May 04, 2019 11:19
callbacks_api is a framework for registering callbacks if the callback registration function exists, else returns gracefully. This mod can be very handy when developing or prototyping new callbacks, either within a mod, or within Minetest itself.

callbacks_api.register_callback(cb_registrar, cb, ...)

Register callback cb (along with optional arguments ...) to cb_registrar, if it exists, or return gracefully.


- cb_registrar [function]: The function that registers the callback.
- cb [function]: The callback itself.
- ... [Comma-separated arguments]: Optional arguments to pass to cb_registrar, along with cb.


Code: Select all
local function callback(player, hpchange)
    minetest.log("action", player:get_player_name() .. "'s HP changed!\n" ..
            "old_hp = " .. player:get_hp() - hpchange .. ",\n" ..
            "new_hp = " .. player:get_hp())

-- cb_registrar = minetest.register_on_player_hpchange
-- cb = callback
-- ... = false
callbacks_api.register_callback(minetest.register_on_player_hpchange, callback, false)

Code: MIT

ContentDB: ... lbacks_api
Browse code:
Browse releases:
Download: ...

Re: [mod] Callbacks API [v0.1][callbacks_api]

PostPosted: Sat May 04, 2019 12:42
by DS-minetest

Re: [mod] Callbacks API [v0.1][callbacks_api]

PostPosted: Mon May 06, 2019 16:17
Yes, the first post is indeed incomplete. Thanks for reminding me. ;)

EDIT: Fixed. This also reminds me to make a topic move request...