PDA

View Full Version : Extensions



Brenn
December 12th, 2009, 18:32
Ok, I know this has probably been covered ad nauseum for you regulars around here, but since I'm off and on again with FG Ruleset work due to RL constraints I'm not current and a search on Extensions is not specific enough.

In the documentation on Extensions, this is stated at the end:



Making extensions usable in an existing ruleset
An important thing to remember is that the general usability of extensions may depend very heavily on the ruleset on top of which it is loaded. For example, the base ruleset might define the elements on the desktop directly, in which case creating an icon on the desktop is not possible, short of redefining the entire icon selection.
Ruleset designers are encouraged to take this aspect into consideration when designing their rulesets, and possibly taking steps to make it easier to implement extensions in areas where they are deemed most useful.


What exactly does this mean? The layout of the desktop in the base is not modifiable by an extension?


Also are there restrictions to db access by an extension?


What I'm most concerned with before I start separating all my existing Reign Specific stuff from the base ORE stuff is what I can't do in an extension.

Griogre
December 18th, 2009, 02:59
Generally speaking, for extentions the biggest restrictions on extentions is they are not dynamic. They load once at the start, over riding and replacing anything in the base ruleset that exists in the extention and can add whatever you want. So they are a one time load on start up and then are done.

What that boilerplate warning was about was depending on how the base ruleset was made you may have a very difficult time changing things. In your case though where I believe you have a core set of rules and just want to hang variants and extra things off of the main rules, extentions should work very well.

tdewitt274
December 18th, 2009, 04:12
So, would it be a better idea to set up your ruleset to call a specific function and then put all your code into other functions? I'm messing with my first ruleset, but I'd like to make sure it's as portable as possible. Of course, there are times when you can't.

For example,
Ruleset


function DoSomething()
ans = SomethingSpecific1()
ans = SomethingSpecific2()
end
function SomethingSpecific1()
code to do what you initially wanted to do
end
function SomethingSpecific2()
code for additional stuff
end


Extention


function DoSomething()
ans = NewSomethingSpecific1()
ans = SomethingSpecific2()
end
function NewSomethingSpecific1()
code to do what you initially wanted to do
end

Griogre
December 18th, 2009, 05:50
Hmmm. There’s no reason really to “functionize” your code just for extension use (though it’s not a bad style for clarity). If the function is rather trivial I would just over ride the DoSomething() function simply because additional functions might be more confusing rather than just adding a few lines to the original DoSomething() to make a new one. Otherwise you might find yourself at the opposite extreme trying to keep track of an ever expanding set of NewSomethingSpecifics().

Note: I’d like your idea on functions a bit better if LUA was compiled and not an interpretive language. However, there is some small overhead to the function calls - particularly if they are in a loop. On the other hand, in a non loop situation extra function calls are probably too trivial to matter.

Foen
December 18th, 2009, 06:59
Something similar is possible using global scripts which 'register' a set of functions. Create a global script in your main ruleset called 'Extender' with a global variable called 'Functions' intialised as an empty table.

The Extender script then has an onInit handler which adds your default functions to the global variable, such as Functions.SomethingSpecific1 = defaultSomethingSpecific1 and Functions.SomethingSpecific2 = defaultSomethingSpecific2.

From your ruleset (wherever) you can now have a function:


function DoSomething()
ans = Extender.Functions.SomethingSpecific1();
ans = Extender.Functions.SomethingSpecific2();
end

This code will execute the default functions.

In an extension (which initialises after the underlying ruleset has initialised) you can have a script which overrides the defaults by setting Extender.Functions.SomethingSpecific1 = newSomethingSpecific1.

The ruleset code from above will now use the over-ridden version of the function without any changes to the ruleset code.

Please note that when assigning a function to a table variable, you must use the function name only (without the brackets and arguments):


function newSomethingSpecific1(arg1, arg2)
...some stuff goes here...
end

function onInit()
Extender.Functions.SomethingSpecific1 = newSomethingSpecific1;
ans = Extender.Functions.SomethingSpecific1(arg1, arg2);
end

Hope that helps!

Foen

Brenn
December 19th, 2009, 04:00
Thanks for that info, Foen. It will save me some time- I was wondering how I was going to handle that in what I'm doing.