Thread: Extension Question
-
November 27th, 2016, 21:13 #1
Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,096
Extension Question
It has been a while since I wrote an extension, and I just need to check because I cannot locate it in the developer documentation:
If I override a manager routine in my extension lua include file, that code will replace the code in the manager, right? And there is no way to invoke the original code (using super or some such) if I just want to intercept the call, check some parameters, and pass control back to the original unless it meets some very specific parameter criteria, right?
-
November 28th, 2016, 00:38 #2
Yeap, unlike with the XML templates, lua functions cannot be "supered" from an Extension back to a Ruleset - the whole lua file needs to be reproduced (with appropriate changes) in the Extension
Does that answer you question?
CheersDulux-Oz
√(-1) 2^3 Σ Π
...And it was Delicious!
Alpha-Geek
ICT Professional
GMing Since 1982
NSW, Australia, UTC +10
LinkedIn Profile: www.linkedin.com/in/mjblack
Watch our games on Twitch: www.twitch.tv/dulux_oz
Support Me on Patreon: www.patreon.com/duluxoz
Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz
-
November 28th, 2016, 04:50 #3
Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,096
That's what I thought, Dulux, but if you need to replace a routine in a manager (in this case, the Table.Manager), do I need to replace each routine in there, or just the ones I need to replace? Since a manager is accessed through Table.xxxx, where xxxx is the name of the routine, how do I even replace it? My guess is that I have to override the entire Manager declaration in my xml so that "Manager" refers to my file and not the original file. So, I think I have to redirect the Table manager in my own xml declaration and duplicate the entire Table.Manager file just to change a couple of lines within one routine. Can you confirm?
-
November 28th, 2016, 05:36 #4
Yes, that's pretty much what you have to do.
I suspect that's one reason why there are so many small (<50 lines) lua files - so that they can be "swapped out" easier than if there was only a few big ones.Dulux-Oz
√(-1) 2^3 Σ Π
...And it was Delicious!
Alpha-Geek
ICT Professional
GMing Since 1982
NSW, Australia, UTC +10
LinkedIn Profile: www.linkedin.com/in/mjblack
Watch our games on Twitch: www.twitch.tv/dulux_oz
Support Me on Patreon: www.patreon.com/duluxoz
Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz
-
November 28th, 2016, 05:46 #5
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,541
Actually, I think that there have been a few extensions that have successfully replaced individual functions within a ruleset. As long as the functions are not defined as local (which none are), then you should be able to replace them. The only caveat is that you still need to be watchful of code updates in the base code, and cross-extension clashes.
Code:function onInit() TableManager.performRoll = newPerformRoll; end function newPerformRoll(...) ... end
JPG
-
November 28th, 2016, 05:59 #6
Now that's an interesting idea - and it'll cut down on the code-size as well - hmmmmm?!
That's for that MoonDulux-Oz
√(-1) 2^3 Σ Π
...And it was Delicious!
Alpha-Geek
ICT Professional
GMing Since 1982
NSW, Australia, UTC +10
LinkedIn Profile: www.linkedin.com/in/mjblack
Watch our games on Twitch: www.twitch.tv/dulux_oz
Support Me on Patreon: www.patreon.com/duluxoz
Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz
-
November 28th, 2016, 11:37 #7
Archangel
- Join Date
- Apr 2008
- Location
- Virginia Beach
- Posts
- 3,096
Thanks, MW. It really doesn't make much difference, because you still have to be mindful if you copy the whole file. In fact, it may be less likely that one routine is affected in a change than anything in a whole file. That override trick you mentioned: I never would have come up with that without your input. Muchas gracias, my friend!
-
November 28th, 2016, 13:44 #8
- Join Date
- Jun 2013
- Location
- Isanti, MN
- Posts
- 2,922
If you just need a wrapper around the original code, save off the current routine and call it. This emulates a call to a base class function. This way you'll get changes in the underlying code as well...
Code:function onInit() originalRoll = TableManager.performRoll; TableManager.performRoll = newPerformRoll; end function newPerformRoll(...) ... originalRoll(...); ... end
-
November 28th, 2016, 13:55 #9
You realize now I've got to go back through all my code and redo it all, don't you?!
Dulux-Oz
√(-1) 2^3 Σ Π
...And it was Delicious!
Alpha-Geek
ICT Professional
GMing Since 1982
NSW, Australia, UTC +10
LinkedIn Profile: www.linkedin.com/in/mjblack
Watch our games on Twitch: www.twitch.tv/dulux_oz
Support Me on Patreon: www.patreon.com/duluxoz
Past Games, etc, on my YouTube Channel: www.youtube.com/c/duluxoz
-
November 28th, 2016, 15:42 #10
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks