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

Post Reply
User avatar
ANAND
Member
Posts: 335
Joined: Sun Jan 28, 2018 12:54
GitHub: magnetar47
IRC: MAGNETAR ANAND
In-game: ANAND and all names with Tomato
Location: India
Contact:

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

by ANAND » Post

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)
Dependencies: None

License
Code: MIT

ContentDB: https://content.minetest.net/packages/A ... lbacks_api
Browse releases: https://github.com/ClobberXD/callbacks_api/releases
Browse code: https://github.com/ClobberXD/callbacks_api
Download latest: https://github.com/ClobberXD/callbacks_ ... master.zip
Last edited by ANAND on Mon Oct 28, 2019 11:21, edited 2 times in total.
My Mods

cdb_NXKPOcRlgUGdMyf8uLoUQvnMGIfuaHmp

User avatar
Desour
Member
Posts: 1578
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

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

by Desour » Post

he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

User avatar
ANAND
Member
Posts: 335
Joined: Sun Jan 28, 2018 12:54
GitHub: magnetar47
IRC: MAGNETAR ANAND
In-game: ANAND and all names with Tomato
Location: India
Contact:

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

by ANAND » Post

Yes, the first post is indeed incomplete. Thanks for reminding me. ;)

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

cdb_NXKPOcRlgUGdMyf8uLoUQvnMGIfuaHmp

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests