coavins / mhrise-coavins-dps

A detailed DPS meter for Monster Hunter Rise (PC)
GNU General Public License v3.0
24 stars 11 forks source link

Worth attention: Incompatibility with other mods caused by global functions with the same name #14

Closed GreenComfyTea closed 2 years ago

GreenComfyTea commented 2 years ago

Problem: Functions in lua are global by default if defined like so: function foo(). If some other mod has a global function with the same name, it's definition gets overridden by the mod that was loaded last.

Describe the solution you'd like: Making functions local fixes the issue: local foo = function()

Describe alternatives you've considered: Giving functions unique names like function coavinsDpsFoo()

Additional context: Encountered it when I was implementing load_config() and save_config() in my mods. Changes in MHR Overlay config were calling save_config(), but it was overridden by No More Blinking Icons. so save_config() of No More Blinking Icons mod was called.

coavins commented 2 years ago

Thanks for sharing these details, this task is on the to-do list.

Does this mean then that all local definitions will both (a) not override globals of another mod and (b) not be overridden by globals of another mod, thus protecting both parties at once? This does sound like a very good move.

GreenComfyTea commented 2 years ago

As far as i can tell: (a) yes (b) yes Testing images

But since lua code is interpreted line by line, the declaration of the local function must be higher in the code than any calls of this function.