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

User avatar
ANAND
Member
 
Posts: 318
Joined: Sun Jan 28, 2018 12:54
Location: India
GitHub: ClobberXD
IRC: ANAND ClobberXD
In-game: ANAND ClobberXD [A-Za-z0-9-_]Tomato

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

by ANAND » 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.

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
Last edited by ANAND on Tue May 07, 2019 00:31, edited 1 time in total.
 

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

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

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

Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

User avatar
ANAND
Member
 
Posts: 318
Joined: Sun Jan 28, 2018 12:54
Location: India
GitHub: ClobberXD
IRC: ANAND ClobberXD
In-game: ANAND ClobberXD [A-Za-z0-9-_]Tomato

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

by ANAND » 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...
 


Return to WIP Mods



Who is online

Users browsing this forum: No registered users and 3 guests