Page 1 of 1

[Mod] mod utilities [modutil]

PostPosted: Sat Jun 08, 2019 11:47
by theFox
A mod containing utilities I often use. The modules are be loaded on demand if another mod uses one of the components.
license: MIT
no dependencies
code: https://github.com/theFox6/modutil
download: https://github.com/theFox6/modutil/archive/master.zip

log
A module for creating shorter logging functions.
The loggers will format the given log message and call minetest.log.
Typically you want to use it as following:
Code: Select all
my_mod.log = modutil.require("log").make_loggers()
my_mod.log.action("loggers loaded")

You can also pass the level of the loggers to the make_loggers function:
Code: Select all
my_mod.log = modutil.require("log").make_loggers("action","warning","error","debug")

If you create your logger after loading the mod you may want to pass the modname using:
Code: Select all
my_mod.log.info = modutil.require("log").make_logger("info","my_mod")

translations
A wrapper that checks if minetest.get_translator is avalible and replaces it if nessecary.
The module returns a fucntion that when called returns the translator. use:
Code: Select all
my_mod.S = modutil.require("translations")()
-- or for after loading
my_mod.S = modutil.require("translations")("my_mod")

check_prefix
A function doing the same as the standard minetest prefix check. It will assume the modname is correct if it called after loading. use:
Code: Select all
local check_prefix = modutil.require("check_prefix")
-- checks if name is in the format "modname:name" or ":modname:name"
-- if modname in "modname:name" is not the currently loaded mod it creates an error
-- returns id in the format "modname:name"
local id = check_prefix(name)

Feel free to suggest more utilities.

Re: [Mod] mod utilities [modutil]

PostPosted: Sun Jun 16, 2019 13:54
by Sokomine
Can you describe what the mod is about and what it does? Hiding all behind spoilers isn't a good idea. I don't use JavaScript often. Thus, the spoiler cannot be unfolded. It's also documented on Github, and that at least is readable. But it'd be a lot nicer if the thread on the forum could be read as well.

Re: [Mod] mod utilities [modutil]

PostPosted: Sun Jun 16, 2019 15:25
by theFox
Sokomine wrote:Hiding all behind spoilers isn't a good idea. I don't use JavaScript often. Thus, the spoiler cannot be unfolded. It's also documented on Github, and that at least is readable. But it'd be a lot nicer if the thread on the forum could be read as well.

Well I've removed the spoiler now. Sorry for the trouble, just thought it'd be better to keep the topic post short...

Re: [Mod] mod utilities [modutil]

PostPosted: Sun Jun 16, 2019 16:23
by Linuxdirk
I once was a fan of “utility mods” but I soon realized that no-one except the author uses them and that they serve no other purpose than outsourcing the code from one of the authors mods into another.

Re: [Mod] mod utilities [modutil]

PostPosted: Wed Jun 19, 2019 13:34
by theFox
Linuxdirk wrote:that they serve no other purpose than outsourcing the code from one of the authors mods into another.

Exactly right, but I'd be happy to add new utilities if you need anything.