Plugin calling function in other installed plugin

I have a few of my own plugins installed, and some of them have generic functions with the same names. I’ve recently been running into the issue that PluginA can call a get_layers(), and end up running the get_layers() function in PluginB, which often causes issues, due to globals being set to ‘nil’, since PluginB wasn’t running.

It’s all a little odd, but basically running PluginA has a chance to run functions from PluginB, just because they share the same name. Does anyone know any good way to mitigate this? Or whether this might be a bug?

I could rename them all, but in theory this could still happen between one of my plugins, and one made by someone else. I suspect changing all my functions to be local would work, but that requires them to be ordered in a very specific way to even work, which is more of a hassle than I want to deal with.

Thanks!

I’ve run into the same problem :frowning:
The plugins were importing shape files but one was the Ultima VII shape format and the other the Ultima VIII shapes, so very similar but just not similar enough (and for two different projects). So I’ve taken the local way to solve it.

Good to know it’s not just me that ran into this! I’ll probably have to painstakingly go through all my plugins and ‘shuffle’ all the neatly organized functions to make them local as well in that case. Pain. :tired_face:

Just wanted to drop my latest solution in here, just in case anyone finds it useful.

I’ve gotten into the habit of assigning a few constant tables at the top of my plugin, and then using these to assign functions into. This way all your functions will be global, but they require a reference to the local variable assigned in this plugin, and therefore cannot be called by other plugins!

It makes the function assignment slightly messier, but solves all the other issues well!

For example:

local extension = {} -- a constant table. Never change it on runtime!

function extension:my_function()
    print('I am a global function, but can only be called by scripts that have a reference to 'extension', and therefore not any scripts outside of this plugin!')
end

-- Just call it like this
extension:my_function()
1 Like