Page 1 of 1

engine/ui/Dialog.lua won't superload, but List.lua will.

Posted: Tue Jan 21, 2014 1:08 am
by Marson
I think I've got my head wrapped around superloading, but I'm banging my head against the wall trying to figure out why the init function in engine/ui/Dialog.lua won't superload. I copied the file over to engine/ui/List.lua and that will load fine. To keep it simple for testing this, I used:

Code: Select all

local _M = loadPrevious(...)

local D = require "engine.Dialog"
	
function _M:init(title, w, h, x, y, alpha, font, showup, skin)
	D:simplePopup("FUUUUU!!!", "FUUUUUUUU!!!!!")
end

return _M
With the same code in both Dialog.lua and List.Lua, this is the error thrown:

Code: Select all

Checking addon	tome-marson-ui	:: (as dir)	true	:: (as teaa)	nil	

Binding addon	Marson's UI Modifications	nil	tome-marson-ui-1.1.5
 * with superload
 * with overload
 * with hooks

FROM 	/mod/addons/marson-ui/superload/engine/ui/EquipDoll.lua	loading previous!
FROM 	/mod/addons/marson-ui/superload/engine/ui/List.lua	loading previous!
Using cached font	/data/font/DroidSans.ttf	14
Lua Error: /engine/ui/Dialog.lua:369: attempt to perform arithmetic on field 'h' (a nil value)
	At [C]:-1 __add
	At /engine/ui/Dialog.lua:369 setupUI
	At /engine/dialogs/GameMenu.lua:37 init
	At /engine/class.lua:97 new
	At /mod/class/Game.lua:1808 
	At /engine/KeyBind.lua:263 triggerVirtual
	At /mod/class/uiset/Minimalist.lua:1947 fct
	At /engine/Mouse.lua:52 
The problem isn't the error, which should be there, but the fact that none of the functions in Dialog.lua will superload, while ones in other files will. I put the same code with different text in EquipDoll as well. Both List:init and EquipDoll:init will display the text (before other parts get upset with "nil" variables).

I've also added

Code: Select all

function _M:setupUI(stuff)
	D:simplePopup("FUUUUU!!!U2", "FUUUUUUUU!!!!!U2")
end
to Dialog.lua, but no change. It still shows At /engine/ui/Dialog.lua:369 setupUI. If I superload GameMenu:init(), I'll get At /mod/addons/marson-ui/superload/engine/dialogs/GameMenu.lua:37 init, so other superloads work.

I've also removed almost all other addons, and the ones remaining have nothing in "engine". I'm guessing I'm missing something obvious, but I'm stumped. Any ideas?
TomeFiles.jpg
TomeFiles.jpg (69.78 KiB) Viewed 4192 times

Re: engine/ui/Dialog.lua won't superload, but List.lua will.

Posted: Wed Jan 22, 2014 12:17 am
by Marson
*pulls out remaining hair*

I suppose I should ask if anyone has successfully overloaded or superloaded any functions in engine/ui/Dialog.lua in any addons they've made. I can't see any reason in the code why it would be different, but I'm trying to eliminate possibilities.

Re: engine/ui/Dialog.lua won't superload, but List.lua will.

Posted: Wed Jan 22, 2014 12:26 am
by Marson
The reason I'm in that file to begin with is to enlarge some hard-coded dialog sizes without needing to copy every function that calls one. I'm boosting the font size, and I think I can scale the dialog width based on font size and have that cover most circumstances.

Re: engine/ui/Dialog.lua won't superload, but List.lua will.

Posted: Wed Jan 22, 2014 11:20 pm
by Marson
If anyone else runs into this, I resorted to putting explicit references in hooks/load.lua for the functions I wanted to modify.

Code: Select all

local base_D_init = engine.ui.Dialog.init
function engine.ui.Dialog:init(title, w, h, x, y, alpha, font, showup, skin)
	code, Blah!
	base_D_init(self, title, w, h, x, y, alpha, font, showup, skin)
end
It works, anyway.

Re: engine/ui/Dialog.lua won't superload, but List.lua will.

Posted: Sun May 25, 2014 7:30 pm
by Zireael
I've had to resort to similar shenanigans to debug my module.

The chatbox dialog consistently tries to use simple ui and I can't make it use either the module default or metal - the result is that it throws errors. Help?

Re: engine/ui/Dialog.lua won't superload, but List.lua will.

Posted: Sun May 25, 2014 8:17 pm
by Marson
Putting

package.loaded['engine.ui.Dialog'] = nil

in hooks/load.lua allowed me to overload the file, though it doesn't work for engine.UserChat for whatever reason. I still have to overwrite engine.UserChat:resize() in load.lua.

I'd probably have to look at your specific code to be much help, but just as a stab in the dark...
If you are making new dialog types, are you inheriting engine.ui.Base ?

local Base = require "engine.ui.Base"
module(..., package.seeall, class.inherit(Base))

Re: engine/ui/Dialog.lua won't superload, but List.lua will.

Posted: Mon May 26, 2014 1:11 am
by Doctornull
Thanks to Marson's advice, I've got Nulltweaks being much more ... cooperative.

Here's what I did in hooks/load.lua (at the end):

Code: Select all

package.loaded['mod.class.interface.Combat'] = nil
package.loaded['data.talents.chronomancy.chronomancer'] = nil
package.loaded['data.talents.cursed.shadows'] = nil
package.loaded['data.talents.gifts.moss'] = nil
package.loaded['data.talents.misc.inscriptions'] = nil
package.loaded['data.talents.misc.objects'] = nil
package.loaded['data.talents.spells.aether'] = nil
package.loaded['data.talents.spells.arcane'] = nil
package.loaded['data.talents.techniques.2hweapon'] = nil
package.loaded['data.talents.techniques.combat-training'] = nil
package.loaded['data.talents.techniques.magical-combat'] = nil
package.loaded['data.talents.uber.str'] = nil
package.loaded['data.timed_effects'] = nil

Re: engine/ui/Dialog.lua won't superload, but List.lua will.

Posted: Wed Sep 03, 2014 11:41 am
by Zireael
Judging by Zizzo's code, something similar is going on with Zone.lua. It makes tweaking entity generation difficult.

Re: engine/ui/Dialog.lua won't superload, but List.lua will.

Posted: Thu Sep 04, 2014 3:30 am
by Zizzo
Zireael wrote:Judging by Zizzo's code, something similar is going on with Zone.lua. It makes tweaking entity generation difficult.
...? Am I doing something particularly exotic in Zone.lua?

Anyway, catching up with the thread:
Marson wrote:If anyone else runs into this, I resorted to putting explicit references in hooks/load.lua for the functions I wanted to modify.

Code: Select all

local base_D_init = engine.ui.Dialog.init
function engine.ui.Dialog:init(title, w, h, x, y, alpha, font, showup, skin)
	code, Blah!
	base_D_init(self, title, w, h, x, y, alpha, font, showup, skin)
end
It works, anyway.
That may actually be the semi-official way of doing this sort of thing. Take a look at T4's mod.class.MapEffects, for instance; it gets require()'d in mod/load.lua, apparently for the express purpose of surgically replacing certain functions in engine.Map, basically the same way you're doing above. I'm doing something similar in T2.

...Wait, you're talking about addons, not modules, aren't you? (shrug) Well, the principle's the same, and as you say, it works.