PDA

View Full Version : Override lua Function



Tielc
May 30th, 2018, 16:31
Is there a way to override a function in lua similar to how you can apply a merge property of join to an xml file?

Basically what I am trying to do is change the way wounds work for an extension. I could go through and create a whole bunch of new controls, properties. etc. But fundamentally, I could change the way ActionDamage.applyDamage() works and probably get 75% of the way there. Then find the remaining controls with their own functions on them.

I know in c# I would do an inherits statement, but that class would be named something completely new, and I would have to change all of my references to its methods wherever they are referenced to the new class / overriden method. I'm just not sure how lua handles this.

Trenloe
May 30th, 2018, 16:45
There are a few posts in the forums on this. Here's one of the recent ones: https://www.fantasygrounds.com/forums/showthread.php?43623-Overriding-CoreRPG-functions

Note: You can only override functions in a global script package (https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Scripting#Global_Script_Packages).

Varsuuk
June 3rd, 2018, 22:50
...
Note: You can only override functions in a global script package (https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Scripting#Global_Script_Packages).

Hey Trenloe,

That reminds me - I was looking at several embedded in control scripts and I felt they did more than I'd want in there (since I am scavanging 5e for some functionality but only layering on CoreRPG, I get to decide on how I steal code/ideas) and was wondering if there was a drawback to creating external versions in global like the example you show, Charmanager, LibraryManager etc (names are a bit off I know)?

Is there a cost to running in global I should avoid or are they embedded in xml simply because it is convenient?

(I also like the side-benefit of actual line number error reporting :) )

Tielc
June 3rd, 2018, 22:53
Hey Trenloe,

That reminds me - I was looking at several embedded in control scripts and I felt they did more than I'd want in there (since I am scavanging 5e for some functionality but only layering on CoreRPG, I get to decide on how I steal code/ideas) and was wondering if there was a drawback to creating external versions in global like the example you show, Charmanager, LibraryManager etc (names are a bit off I know)?

Is there a cost to running in global I should avoid or are they embedded in xml simply because it is convenient?

(I also like the side-benefit of actual line number error reporting :) )

I was curious about this too, as it's a big departure from how I was used to writing code using methods like MVVM and MVP where you're told to separate the code from the UI. Then again, nearly everything we're doing is UI manipulation too.

Trenloe
June 4th, 2018, 03:35
That reminds me - I was looking at several embedded in control scripts and I felt they did more than I'd want in there (since I am scavanging 5e for some functionality but only layering on CoreRPG, I get to decide on how I steal code/ideas) and was wondering if there was a drawback to creating external versions in global like the example you show, Charmanager, LibraryManager etc (names are a bit off I know)?

Is there a cost to running in global I should avoid or are they embedded in xml simply because it is convenient?

(I also like the side-benefit of actual line number error reporting :) )
The difference is where the scripts run and what data space they have access to.

There are three different areas to tie scrips to: windowclass, control and global: https://www.fantasygrounds.com/wiki/index.php/Developer_Guide_-_Rulesets_-_Scripting#Using_Scripts If it is tied to a windowclass or a control, there will be a data space and instance for each window created, or control instance - allowing unique data to be stored and processed (variables, events, handlers) for each window or control.

Global scripts only have 1 data space and aren't linked to a windowclass or control. They provide global functionality in a global data space, outside of being tied to a window or control instance. They are executed and setup (via the onInit function) at the ruleset startup.

Moon Wizard
June 4th, 2018, 07:05
Also, global scripts are loaded into the data space of every object created. That’s how each object has it’s on data space to define variables and functions independently. So, I wouldn’t go too crazy on global scripts, but you should use them when they make sense.

Regards,
JPG