PDA

View Full Version : getRulesetInfo()



dulux-oz
November 23rd, 2014, 06:37
Hi Guys,

Is there a function that performs a getRulesetInfo() similar to the Module.getModuleInfo() and Extension.getExtensionInfo() functions?

Cheers

Moon Wizard
November 25th, 2014, 21:17
No. There hasn't been a need so far.

JPG

dulux-oz
November 26th, 2014, 03:03
No. There hasn't been a need so far.

JPG

How hard would it be to put something like that in (and I know you're busy trying to get the Unity-port done :) )?

Cheers

Moon Wizard
November 26th, 2014, 04:16
It's not super hard, but I tend to shy away from adding functions to the API unless necessary to add new functionality. Every API function adds a new item we need to maintain and track.

What's the purpose? What are you trying to get?

Also, note that the API function you are requesting I s not as simple as it would first appear due to layering.

Regards,
JPG

dulux-oz
November 28th, 2014, 02:48
It's not super hard, but I tend to shy away from adding functions to the API unless necessary to add new functionality. Every API function adds a new item we need to maintain and track.

What's the purpose? What are you trying to get?

Also, note that the API function you are requesting I s not as simple as it would first appear due to layering.

Regards,
JPG

Sorry, I've been distracted with other stuff :)

The purpose would be something along the lines of having an Extension (for eg) being able to tell which Ruleset it was being used with. Then, if a particular Ruleset did something in a particular way, instead of having and maintain a separate Extension that took those particularities into account, you could have one Extension that would implement different code, depending upon the Ruleset.

Cheers

Moon Wizard
November 28th, 2014, 05:03
Interesting thought. It wouldn't help extensions that are mucking around in global scripts probably, but I now understand the use case better.

I wonder if anybody has tried to override a global script function in Lua from a different global script. Hmm, something to try....

JPG

dulux-oz
November 28th, 2014, 05:06
Interesting thought. It wouldn't help extensions that are mucking around in global scripts probably, but I now understand the use case better.

I wonder if anybody has tried to override a global script function in Lua from a different global script. Hmm, something to try....

JPG

Yeah, I have - and I couldn't get it to work - hence the possible solution using a getRulesetInfo() function :)

Cheers

Moon Wizard
November 30th, 2014, 00:45
I'll look into extension override a bit next week to see if I find any fun uses.

Can you use the current DB.getRulesetVersion() function to get what you need for building an extension that changes behavior?

If you are just looking for ruleset version information, this function already returns it.

JPG

dulux-oz
November 30th, 2014, 03:47
I'll look into extension override a bit next week to see if I find any fun uses.

Can you use the current DB.getRulesetVersion() function to get what you need for building an extension that changes behavior?

If you are just looking for ruleset version information, this function already returns it.

JPG

Yeah, I looked at getRulesetVersion(), and while its helpful it doesn't give the Ruleset name, etc.

Thanks John, you're a good friend :)

Cheers

Moon Wizard
December 2nd, 2014, 19:05
I was successfully able to override a global script function using an extension.


Define a new global script in your extension,
Define the function you want to use to replace,
Define an onInit function in the new script with a "<GlobalPackage>.<Function> = <NewFunction>" statement.


Please note that since the order of onInit calls is non-deterministic for global ruleset scripts, you will only be able to consistently replace functions that occur after all onInit calls are made.

Regards,
JPG

dulux-oz
December 2nd, 2014, 20:02
I was successfully able to override a global script function using an extension.


Define a new global script in your extension,
Define the function you want to use to replace,
Define an onInit function in the new script with a "<GlobalPackage>.<Function> = <NewFunction>" statement.


Please note that since the order of onInit calls is non-deterministic for global ruleset scripts, you will only be able to consistently replace functions that occur after all onInit calls are made.

Regards,
JPG

Could you give us an example, please?

Moon Wizard
December 3rd, 2014, 17:33
Attached.

One of the challenges is that any function registered as a callback can not be overwritten, since the original Lua function variable is already registered as the callback and will be maintained. To override functions like that you would need to figure out how to unregister and register your new replacement function variable. You could potentially do this by injecting a new function into the global script to unregister and register new function.

Regards,
JPG

Trenloe
December 13th, 2014, 03:10
Attached.

One of the challenges is that any function registered as a callback can not be overwritten, since the original Lua function variable is already registered as the callback and will be maintained. To override functions like that you would need to figure out how to unregister and register your new replacement function variable. You could potentially do this by injecting a new function into the global script to unregister and register new function.

Regards,
JPG
This is awesome, I'll use this a lot.

Now, next question: is there any way to do something similar for a script attached to a control? For example, campaign\scripts\image.lua attached to the image control in the imagewindow window class? Basically, I'd like to point the onBuildCustomPointer function (not present in control.lua) to a global script package - e.g. Pointer_Toolkit.onBuildCustomPointer. I can't think of a way to do this without modifying image.lua. The idea being not to modify image.lua so that the extension will be less reliant on CoreRPG code changes.

dulux-oz
December 13th, 2014, 03:52
This is awesome, I'll use this a lot.

Now, next question: is there any way to do something similar for a script attached to a control? For example, campaign\scripts\image.lua attached to the image control in the imagewindow window class? Basically, I'd like to point the onBuildCustomPointer function (not present in control.lua) to a global script package - e.g. Pointer_Toolkit.onBuildCustomPointer. I can't think of a way to do this without modifying image.lua. The idea being not to modify image.lua so that the extension will be less reliant on CoreRPG code changes.

Yeah, that's a great idea, I'd like that to (and probably for the same reason) :)

Meanwhile, JPG, have you thought any more about the original request in this Thread?

Cheers