Usually, I start my mods with code looking like that :
Code: Select all
mymod = {}
mymod.name = minetest.get_current_modname()
mymod.path = minetest.get_modpath(mymod.name)
dofile(mymod.path.."/functions.lua")
...
In functions.lua, I have to prefix mod wide functions with mymod.
Tired of always changing the name of the mod and searching a solution to make it possible to include same helper lua file in several mods, I ended up writing this:
Code: Select all
local mod = {}
_G[minetest.get_current_modname()] = mod
mod.name = minetest.get_current_modname()
mod.path = minetest.get_modpath(mod.name)
dofile(mod.path.."/functions.lua")
...
Code: Select all
local mod = _G[minetest.get_current_modname()]
It looks a good solution for portability but I'm not sure about the drawbacks (creating a global var named like mod, without any controls).
What do you think about that ?