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

Post Reply
User avatar
ANAND
Member
Posts: 332
Joined: Sun Jan 28, 2018 12:54
GitHub: ClobberXD
IRC: ANAND ClobberXD
In-game: ANAND ClobberXD
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.

User avatar
DS-minetest
Member
Posts: 1136
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: DS-minetest
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 DS-minetest » Post

Note that I've recently renamed myself on github and co. to "Desour". (I'm bad at naming things.)
Feel free to call me DS.

User avatar
ANAND
Member
Posts: 332
Joined: Sun Jan 28, 2018 12:54
GitHub: ClobberXD
IRC: ANAND ClobberXD
In-game: ANAND ClobberXD
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...

Post Reply

Who is online

Users browsing this forum: runs, thomz92 and 4 guests