Minty23185Fresh
October 27th, 2017, 20:33
I am working on an extension for the "master index" Library editors. In my initial explorations I've come across some perplexing behavior that I'm hoping someone might be able to explain (or confirm my interpretation of it).
I'm looking at code existence and scope within multiple extensions operating on the same ruleset code.
The first few lines of the masterindex windowclass definition in the
rulesets\CoreRPG\campaign\campaign_masterindex.xml file are:
(NOTE: I removed a few lines of code from below, just before <script>, because they are not relevant to this discussion)
<windowclass name="masterindex">
<script file="campaign/scripts/masterindex_window.lua" />
<sheetdata>
The rulesets\CoreRPG\campaign\scripts\masterindex_wind ow.lua file contains an onInit() function, and I have placed a Debug.console() statement in it.
Here is the first try of my extension's modification of the windowclass:
<windowclass name="masterindex" merge="join">
<script merge="join">
function onInit()
Debug.console("Ext | campaign_masterindex.xml | masterindex.onInit() | arrived");
end
</script>
</windowclass>
When I brought up the Spells editor it was completely blank, just a basic skeleton of a dialog, leading me to believe that the ruleset's onInit() function is not being called (since my extension's onInit() probably has replaced it).
So, putting my new knowledge of the existence of code layering into practice I tried to access the ruleset onInit() with this modification of my extension's windowclass:
<windowclass name="masterindex" merge="join">
<script merge="join">
function onInit()
Debug.console("Ext | campaign_masterindex.xml | masterindex.onInit() | arrived");
if super.onInit() then
Debug.console("Ext | campaign_masterindex.xml | masterindex.onInit() | calling super.onInit()");
super.onInit()
else
Debug.console("Ext | campaign_masterindex.xml | masterindex.onInit() | no super.onInit()");
end
end
</script>
</windowclass>
NOW FOR THE PERPLEXING PART. Here is the console output when I brought up the Library Spells editor:
Runtime Notice: Host session started
Runtime Notice: s'Ext | campaign_masterindex.xml | masterindex.onInit() | arrived'
Runtime Notice: s'Core | masterindex_window.lua | onInit() | arrived'
Runtime Notice: s'Ext | campaign_masterindex.xml | masterindex.onInit() | no super.onInit()'
My extension's onInit() started. Execution started in the CorePRG ruleset onInit(). When execution came back to my extension's onInit() the if statement's else clause executed to inform me that the Core's onInit() doesn't exist. (Yet it already RAN!!!) BTW, the editor came up fully populated and in functioning order.
I interpret this as follows:
To evaluate the if clause, i.e. the existence of "super.onInit()", lua had to actually "instantiate" it and in the process of doing so executed it. Once the ruleset's .lua script existed it was replaced by my onInit() (and other code?) and so the if evaluated as false.
Does this sound reasonable? Are there other explanations?
I'm looking at code existence and scope within multiple extensions operating on the same ruleset code.
The first few lines of the masterindex windowclass definition in the
rulesets\CoreRPG\campaign\campaign_masterindex.xml file are:
(NOTE: I removed a few lines of code from below, just before <script>, because they are not relevant to this discussion)
<windowclass name="masterindex">
<script file="campaign/scripts/masterindex_window.lua" />
<sheetdata>
The rulesets\CoreRPG\campaign\scripts\masterindex_wind ow.lua file contains an onInit() function, and I have placed a Debug.console() statement in it.
Here is the first try of my extension's modification of the windowclass:
<windowclass name="masterindex" merge="join">
<script merge="join">
function onInit()
Debug.console("Ext | campaign_masterindex.xml | masterindex.onInit() | arrived");
end
</script>
</windowclass>
When I brought up the Spells editor it was completely blank, just a basic skeleton of a dialog, leading me to believe that the ruleset's onInit() function is not being called (since my extension's onInit() probably has replaced it).
So, putting my new knowledge of the existence of code layering into practice I tried to access the ruleset onInit() with this modification of my extension's windowclass:
<windowclass name="masterindex" merge="join">
<script merge="join">
function onInit()
Debug.console("Ext | campaign_masterindex.xml | masterindex.onInit() | arrived");
if super.onInit() then
Debug.console("Ext | campaign_masterindex.xml | masterindex.onInit() | calling super.onInit()");
super.onInit()
else
Debug.console("Ext | campaign_masterindex.xml | masterindex.onInit() | no super.onInit()");
end
end
</script>
</windowclass>
NOW FOR THE PERPLEXING PART. Here is the console output when I brought up the Library Spells editor:
Runtime Notice: Host session started
Runtime Notice: s'Ext | campaign_masterindex.xml | masterindex.onInit() | arrived'
Runtime Notice: s'Core | masterindex_window.lua | onInit() | arrived'
Runtime Notice: s'Ext | campaign_masterindex.xml | masterindex.onInit() | no super.onInit()'
My extension's onInit() started. Execution started in the CorePRG ruleset onInit(). When execution came back to my extension's onInit() the if statement's else clause executed to inform me that the Core's onInit() doesn't exist. (Yet it already RAN!!!) BTW, the editor came up fully populated and in functioning order.
I interpret this as follows:
To evaluate the if clause, i.e. the existence of "super.onInit()", lua had to actually "instantiate" it and in the process of doing so executed it. Once the ruleset's .lua script existed it was replaced by my onInit() (and other code?) and so the if evaluated as false.
Does this sound reasonable? Are there other explanations?