PDA

View Full Version : Retreiving Extension Info



dulux-oz
August 29th, 2014, 07:48
Hi Guys,

Just a quick one - is there a way (ie a function) to get a list of Extensions that are loaded, and/or the details about the Extension(s) (eg Version Number, Author, etc)?

Cheers

Ikael
August 29th, 2014, 08:03
Hi Guys,

Just a quick one - is there a way (ie a function) to get a list of Extensions that are loaded, and/or the details about the Extension(s) (eg Version Number, Author, etc)?

Cheers

I have also been requesting this, but the answer is no, not at the moment. The only way to gather this information is to make ruleset support some sort of "register yourself" functionality and each extension would invoke it when they are loaded in.

dulux-oz
August 29th, 2014, 08:38
OK, well, if it doesn't exist then I'll write something - and I have.

Feel free to use the following code in your Extensions - I suggest putting the code into an LUA file (say, "lsExtensionManager.lua") and then put this line:


<script name="ExtensionManager" file="lsExtensionmanager.lua"/>

into your extension.xml file.



aExtensions = {}

function registerExtension(sExtensionName,sAuthor,sVersion)
aExtensions[sExtensionName] = {};
if sAuthor then
aExtensions[sExtensionName]["author"] = sAuthor;
end
if nVersion then
aExtensions[sExtensionName]["version"] = sVersion;
end
end

function unregisterExtension()
if aExtensions then
aExtensions[sExtensionName] = nil;
end
end

function isExtensionLoaded(sExtensionName)
for kKey,vValue in pairs(aExtensions) do
if kKey == sExtensionName then
return true;
end
end
return false;
end

function getExtensionAuthor(sExtensionName)
if aExtensions[sExtensionName] then
return aExtensions[sExtensionName]["author"]
end
return nil;
end

function getExtensionVersion(sExtensionName)
if aExtensions[sExtensionName] then
return aExtensions[sExtensionName]["version"]
end
return nil;
end


If anyone wants or writes any other functions, post them to this thread so we can all "enjoy" them :)

Might I also STRONGLY recommend that SW add this code (or something similar) into the CoreRPG Ruleset - please.

Note: I haven't tested this yet - I wrote it "on the fly" - so if you spot a typo/bug/etc please let us know - thanks.

Cheers

Ikael
August 29th, 2014, 10:43
OK, well, if it doesn't exist then I'll write something - and I have.

Feel free to use the following code in your Extensions - I suggest putting the code into an LUA file (say, "lsExtensionManager.lua") and then put this line:


<script name="ExtensionManager" file="lsExtensionmanager.lua"/>

into your extension.xml file.



aExtensions = {}

function registerExtension(sExtensionName,sAuthor,nVersion)
aExtensions[sExtensionName] = {};
if sAuthor then
aExtensions[sExtensionName]["author"] = sAuthor;
end
if nVersion then
aExtensions[sExtensionName]["version"] = nVersion;
end
end

function unregisterExtension()
if aExtensions then
aExtensions[sExtensionName] = nil;
end
end

function isExtensionLoaded(sExtensionName)
for kKey,vValue in pairs(aExtensions) do
if kKey == sExtensionName then
return true;
end
end
return false;
end

function getExtensionAuthor(sExtensionName)
if aExtensions[sExtensionName] then
return aExtensions[sExtensionName]["author"]
end
return nil;
end

function getExtensionVersion(sExtensionName)
if aExtensions[sExtensionName] then
return aExtensions[sExtensionName]["version"]
end
return nil;
end


If anyone wants or writes any other functions, post them to this thread so we can all "enjoy" them :)

Might I also STRONGLY recommend that SW add this code (or something similar) into the CoreRPG Ruleset - please.

Note: I haven't tested this yet - I wrote it "on the fly" - so if you spot a typo/bug/etc please let us know - thanks.

Cheers

Few notes: can you really "unregister" extension? I mean if you have loaded it in, that means that it's there to stay :)
version number would better be string, because you could have something like 1.2-build2 -- depending version naming style, which may differ in projects.

dulux-oz
August 29th, 2014, 15:10
Few notes: can you really "unregister" extension? I mean if you have loaded it in, that means that it's there to stay :)

I was waiting for someone to point that out - yes, you are right, but I put it in because every other register[something] function has a corresponding unregister[something] function - I was being (anally) complete.


version number would better be string, because you could have something like 1.2-build2 -- depending version naming style, which may differ in projects.

Good call - changes made in the relevant post.

Cheers

Trenloe
August 29th, 2014, 15:52
Note: I haven't tested this yet - I wrote it "on the fly" - so if you spot a typo/bug/etc please let us know - thanks.
Posting untested code! How could you??? ;-)

Nice idea. The main issue, which I'm sure you're aware of, is relying on developers putting this in their extension. Or, we're you thinking it would be more of use to an individual who developed more than one extension themselves - checking for specific extensions and versions to see if they are compatible?

dulux-oz
August 29th, 2014, 17:24
Nice idea. The main issue, which I'm sure you're aware of, is relying on developers putting this in their extension. Or, we're you thinking it would be more of use to an individual who developed more than one extension themselves - checking for specific extensions and versions to see if they are compatible?

Actually a little of both - my own Extensions may have extra/different features when each is loaded with others of my Extensions (which prompted me in the first place) but it would also be good if we, as the developer community, took the trouble to help each other out by using this in our Extensions.

That's one reason I'm asking SW to add it in to FG and/or CoreRPG - or even make the registration automatic as part of the Extension loading code (which exists inside FG) - but even if they decide not too (and I really really hope they do) if we could all use it it would help us all out.

Just my $0.03 worth (inflation, you know).

Cheers

Trenloe
August 29th, 2014, 17:57
Just my $0.03 worth (inflation, you know).
What?!? You'll be up to the value of a real-life-real-money coin soon! :o

Trenloe
August 29th, 2014, 18:50
Perhaps add a slash handler to output all registered extension names and versions to the chat window? /extensionlist maybe?

darrenan
August 29th, 2014, 21:38
Considering it already outputs the list of extensions at startup, I would expect the slash command to be a pretty trivial addition.

Trenloe
August 29th, 2014, 21:59
Considering it already outputs the list of extensions at startup...
Just as an FYI - FG doesn't do that automatically, it relies on the developer of each extension to write code in their extension to output to the chat window on startup. Hence why dulux_oz is suggesting this code to register and retrieve extension info as there is nothing in FG at the moment to return the extensions loaded.

Of course, it still relies on an extension developer coding a registerExtension command in their extension startup code. Catch-22!

As a further FYI to people reading this thread - the Savage Worlds developers do something very similar to this with their /ver chat command that outputs the name and version of the loaded SW ruleset and extensions.

dulux-oz
August 30th, 2014, 09:36
Perhaps add a slash handler to output all registered extension names and versions to the chat window? /extensionlist maybe?

Nice idea - I'll have a look at the Savage Worlds Code and see what I can come up with.

Cheers

dulux-oz
September 5th, 2014, 07:39
Here's another function devs can add to their Rulesets now that Moon has added the Extension.getExtensions() and Extension.getExtensionInfo() functions to the Extensions package


function fpIsExtensionLoaded(sExtensionName)
for nIndex,sName in pairs(Extension.getExtensions()) do
if sName == sExtensionName then
return true;
break;
end
return false
end

Note that this will only work with FGv3.0.8+ - maybe Moon will add this to the Extensions package as well.

Cheers

Ikael
September 5th, 2014, 07:46
I was also playing slightly with v3.0.8 Extension package and come up this:



for _, sExt in pairs(Extension.getExtensions()) do
local t = Extension.getExtensionInfo(sExt)
local sName = ""
if t.name ~= "" then sName = "[" .. t.name .."]:" end
local sDesc = ""
if t.description ~= "" then sDesc = t.description end
local sVersion = ""
if t.version ~= "" then sVersion = "(version " .. t.version ..")" end
local sAuthor = ""
if t.author ~= "" then sAuthor = "by " .. t.author end
local sText = ""
for _, s in pairs({sName, sDesc, sVersion, sAuthor}) do
if s ~= "" then
if #sText > 0 then sText = sText .. " " end
sText = sText .. s end end
Comm.addChatMessage({ font = "emotefont", text = sText })
end

Note that Extension package was not documented that time so I made wild guesses how would it work and ended up with this result

Note: In case of Savage Worlds we are probably not going to use this as primary extension listing/showing because of one feature lacking: Extension properties does not support icon. In Savage Worlds ruleset when you load extension it's nice to see themed icon showing in the chat line next to extension description. Now extension properties does not contain that information, maybe that could be added there :)?

dulux-oz
September 18th, 2014, 09:25
Hey Ikael, did you actually get your piece of code to work - because I can't.

Its not throwing up any errors, its just not printing out any Extension details.

Cheers

Ikael
September 18th, 2014, 09:42
Hey Ikael, did you actually get your piece of code to work - because I can't.

Its not throwing up any errors, its just not printing out any Extension details.

Cheers

Are you using latest 3.0.8 version which introduces the Extension package?

This piece of code is already included in current SW4 version as backup plan if developers are lazy to register launch messages for their extensions

dulux-oz
September 18th, 2014, 09:46
Are you using latest 3.0.8 version which introduces the Extension package?

This piece of code is already included in current SW4 version as backup plan if developers are lazy to register launch messages for their extensions

Yes, of course - but you're right and smart to ask.

I'm still playing around with it - the Extension package seems to return both strings and tables... hmmmm....

dulux-oz
September 18th, 2014, 10:12
OK, got it sorted - will be posting some detailed documentation soon

Cheers