This library provides functions to execute scripts in an extended way, as an alternate mean to call functions.
First you can pass parameters to a script that's going to be executed (int, float string, object location, itemproperty).
Then you can call the script using a fork system (thanks to Yaballa for her subscript pattern).
Finally get the returned value from the calling script (int, float string, object location, itemproperty).
This system has many advantages:
* Makes your code easier to maintain
* Improves script performance
* Permits to override functions
* Increases compatibility between different systems
* Improves module organization
Maintenability
--------------
Let's assume you wrote a function in an include file.
This include file is included by many other scripts that use this function.
If you modify this function, you have to recompile all the scripts that use it.
Instead export the code of this function in an external script, and simply call this script from your function.
The next time you'll modify this function, in fact you'll just modify the called script and compile it.
Performance
-----------
So you've exported the function's code to the external script.
All scripts that use the include file do not include the function's code when compiling.
So it takes less memory when the scripts are loaded.
Function override
------------------
As the function's code is now in an external script file,
it's possible for anybody to customize it without recompiling the scripts that use this function.
You can compare this functionality with what is provided in object-oriented programming languages like Java.
Compatibility with other systems
--------------------------------
When distribute your scripts, follow this process :
Don't include your external script in a hak, instead put it in an erf that will be imported in a module.
Other systems will be able to rewrite your scripts and make them compatible with yours.
Module organization
-------------------
Use the fork script system to group all your external scripts in only one.
It's easier to manage one file than many.
Limitation
----------
You can only pass parameters of the following type :
int
float
string
object
location
itemproperty
Example 1 : "calling_script.nss"
---------
float function CallingFunction(object oObject, int iInteger, itemproperty ipItemProp)
{
// Declare the list of parameters
struct script_param_list paramList;
// Add parameters to the list
paramList = JXScriptAddParameterObject(paramList, oObject);
paramList = JXScriptAddParameterInt(paramList, iInteger);
paramList = JXScriptAddParameterItemProp(paramList, ipItemProp);
// Call the script with the fork system
JXScriptCallFork("called_script", 3000, paramList);
// Get the response from the called script
return JXScriptGetResponseFloat();
}
Example 2 : "called_script.nss"
---------
void main()
{
struct script_param_list paramList = JXScriptGetParameters();
int iOperation = JXScriptGetForkOperation();
switch (iOperation)
{
case 3000 :
// Get the parameters from the list
object oObject = JXScriptGetParameterObject(paramList, 1);
int iInteger = JXScriptGetParameterInt(paramList, 1);
itemproperty ipItemProp = JXScriptGetParameterItemProp(paramList, 1);
// Do whatever you want here, you can even call JXScriptCallFork() once again !
// Set the response of the script
JXScriptSetResponseFloat(12.569);
return;
}
}
Thanks for your feeback !
I don't think I'll spotlight this as it doesn't seem to interest many people. Anyway I don't know how to ask ;-) _________________________ Spellcasting Framework Wild/Dead Magic Zone (Spellcasting Framework add-on)
Posted by Yaballa at 2007-09-12 23:17:33 Voted 10.00 on 09/12/07
This is fantastic and should be proposed as a standard. Ask Maximus to spotlight this :)
You must be Logged In to post comments in this section.
10 - A Masterpiece, Genuinely Groundbreaking 9 - Outstanding, a Must Have 8 - Excellent, Recommended to Anyone 7 - Very Good, Deserves a Look 6 - Good, Qualified Recommendation 5 - Fair, Solid yet Unremarkable 4 - Some Merit, Requires Improvements 3 - Poor Execution, Potential Unrealized 2 - Very Little Appeal 1 - Not Recommended to Anyone