ULX

Author Topic: Understanding ULib hook priority  (Read 1674 times)

0 Members and 1 Guest are viewing this topic.

Offline Buzzkill

  • Respected Community Member
  • Full Member
  • *****
  • Posts: 176
  • Karma: 59
    • The Hundred Acre Bloodbath
Understanding ULib hook priority
« on: December 19, 2014, 11:01:51 AM »
Hey all.  Trying to understand some results I'm seeing.  I've got two hooks for EntityTakeDamage, one as part of a gibmod addon and another as part of a lua script I'm introducing in /lua/autorun. The autorun hook is being added with a priority of -10. The addon hook is being added without a priority (default of 0).

If I understand correctly, when ULib initializes it queries the current list of hooks and rebuilds them (ulib\shared\hook.lua).  I would expect that the EntityTakeDamage hook from autorun (priority -10) would execute before the addon version.  However, debug statements are showing me that the addon version is running first.

Is the Ulib prioritization of hooks only for hooks within ULX, or should it apply to legacy hooks as well?  Is there something that might prevent the prioritization/sorting of hooks as expected?

Also, any tricks to debugging within hook.lua? It seems that various efforts at printing debug info yield errors.

Thanks!
Mike

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Understanding ULib hook priority
« Reply #1 on: December 19, 2014, 10:06:13 PM »
Buzzkill, I can't help with the debugging like your asking (Megiddo/Stickly are the experts for our code there), but, it's likely your hook.Adds are running before ULib is initialized.
(You might find ULib's debugFunctionCall
Looks like our hook code doesn't verify if a hook already has a priority when it's adding stuff from the 'old' list.
So, if you set that extra parameter before ULib adds the hooks, it sets it to 0 anyway.
I could have sworn we had a hook or function that got called when ULib loaded and was "ready" for other dependencies, so you could do something like hook.Add("ThisHookCalledWhenULibInitialized", your function/code to add more hooks, blah) but I can't find it.
I know we use a variable to test for some stuff "if ULib then ...", but that would be inconvenient in a timer/etc just to start your code/adds.
« Last Edit: December 19, 2014, 10:08:03 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Buzzkill

  • Respected Community Member
  • Full Member
  • *****
  • Posts: 176
  • Karma: 59
    • The Hundred Acre Bloodbath
Re: Understanding ULib hook priority
« Reply #2 on: December 20, 2014, 12:47:44 PM »
Bingo!  That makes perfect sense, and by moving my scripts into ulib/modules I was able to insure that they didn't hook until after Ulib overrode hook management.  Problem solved.  Many thanks!

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Understanding ULib hook priority
« Reply #3 on: December 20, 2014, 01:52:29 PM »
Welcome, and...
BINGO #2. I knew we had something. Not well documented though.
Not very helpful if you're not using ULX and only wanting our ULib library though (hey, uncommon, but could happen).

hook.Add ( ulx.HOOK_ULXDONELOADING, blah, blah )
Can search our repo for that if examples needed. I found it a few times to ensure we had configs loaded 'after' the rest of ulx had loaded, XGUI post init, echo colors, etc.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming