Page 1 of 1

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

PostPosted: Sat May 04, 2019 11:19
by ANAND
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.

Parameters

- 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.

Example


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())
end

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




License
Code: MIT

ContentDB: https://content.minetest.net/packages/A ... lbacks_api
Browse code: https://github.com/ClobberXD/callbacks_api
Browse releases: https://github.com/ClobberXD/callbacks_api/releases
Download: https://github.com/ClobberXD/callbacks_ ... master.zip

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
by ANAND
Yes, the first post is indeed incomplete. Thanks for reminding me. ;)

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