"require" in hooks/load.lua destroys superloaded function

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
Nagyhal
Wyrmic
Posts: 282
Joined: Tue Feb 15, 2011 12:01 am

"require" in hooks/load.lua destroys superloaded function

#1 Post by Nagyhal »

This is a compatibility issue I'm wrestling with in the current moment. To clarify this topic's title, a file loaded by "require" in one addon's hooks/load.lua file breaks superloading of the same file in the other addon.

in addon1's hooks/load.lua:

Code: Select all

require "engine.interface.ActorProject"
in addon2's superload/load.lua (my addon, in this case):

Code: Select all

local _M = loadPrevious(...)

local base_project = _M.project

function _M:project(
    --do_something
    return base_project(self, params)
end)

return _M
This occurs when both addons are given the same weighting, or in any case when the file-requiring adding loads before the superloading addon. Of course, it can be fixed by setting the other creator's addon to load after my superloaded function has been defined, but not only is this messy, it doesn't stop similar complications from arising. Other files are very often required by the hooks/load.lua file, and it'll be a continual matter of luck whether my load.lua file happens to reference functions superloaded in an addon that now loads before mine.

What's the best way to handle this? Does something need fixing? Or have I missed something glaringly obvious?

I'll spend some time sifting through the addon-loading code, but don't have time to for the minute. In the meantime, thank you for any clues you can throw my way!

Nagyhal
Wyrmic
Posts: 282
Joined: Tue Feb 15, 2011 12:01 am

Re: "require" in hooks/load.lua destroys superloaded functio

#2 Post by Nagyhal »

I think this relates to a bug mentioned in a previous post by the ever-brilliant Hackem_Muche:

http://forums.te4.org/viewtopic.php?p=161531#p161567

Am I on the right track?

edit: The problem has been investigated and I have proposed a fix! :)

http://forums.te4.org/viewtopic.php?f=4 ... 00#p177400

grayswandir
Uruivellas
Posts: 708
Joined: Wed Apr 30, 2008 5:55 pm

Re: "require" in hooks/load.lua destroys superloaded functio

#3 Post by grayswandir »

I believe this was fixed in 1.2, or there exists a fix, or something? In any case, I found a workaround to the problem for those of us on 1.1.5:

Code: Select all

-- Require the file you need.
local combat = require 'mod.class.interface.Combat'
-- Do whatever you want to it.
combat.grayswandir_test_value = true
-- Mark the file as not having been required.
package.loaded['mod.class.interface.Combat'] = nil
I made a very simple addon composed of just this and it worked really well. Without that last line nulltweaks mastery changes wouldn't show up. With it, they show up and so does grayswandir_test_value.

I also tried sticking that last line at the start of nulltweaks's hooks/load.lua and that worked too. So you can defensively mark all of the files you've superloaded as not having been loaded in your own addons.
Addons: Arcane Blade Tweaks, Fallen Race, Monk Class, Weapons Pack
Currently working on Elementals. It's a big project, so any help would be appreciated. :)

Doctornull
Sher'Tul Godslayer
Posts: 2402
Joined: Tue Jun 18, 2013 10:46 pm
Location: Ambush!

Re: "require" in hooks/load.lua destroys superloaded functio

#4 Post by Doctornull »

grayswandir wrote:I also tried sticking that last line at the start of nulltweaks's hooks/load.lua and that worked too. So you can defensively mark all of the files you've superloaded as not having been loaded in your own addons.
That's awesome. I'll put that in my stuff going forward.
Check out my addons: Nullpack (classes), Null Tweaks (items & talents), and New Gems fork.

Post Reply