APGen Documentation Previous Topic: Developing with XML Next Topic: Mixing Script Languages Parent Topic: APGen Developer's Guide    APGen Developer's Guide
Using Other Script Languages
See Also:

Active Page Generator ships with two script languages: JScript and VBScript®.  They are both widely used Microsoft™ script languages.  VBScript and JScript are commonly used in ASP and Windows Scripting Host, and they can also both be used in Internet Explorer.  Since VBScript and JScript are well tested, well documented, and widely used, they are reliable, easy to learn, and have excellent tool support.

Two other script languages can be used within APGen: PerlScript and Python.  To enable use of these languages, the appropriate language engines must be downloaded and installed.  Active Scripting engines other than VBScript, JScript, PerlScript, and Python will not work within APGen.

The Active Scripting Engines for Perl and Python can be downloaded from:

The primary advantages of using PerlScript or Python are: They have language features not available in VBScript or JScript; and using PerlScript or Python may leverage existing developer skills and code base.  The disadvantages of using these script languages are that they are less widely used (thus harder to learn, with inferior tool support), and they can be buggier or less developed for use in Active Scripting products.  WebGecko Software does not support issues arising from script engine bugs.

If you find any of this topic to be incorrect or out of date, or if you have other feedback, please contact us at feedback@webgecko.com.

Notes 

Notes on using these scripting engines with PerlScript or Python:

Debugging

Some of the script engines do not support the Active Script Debugging interfaces.  If this is the case, you will not be able to debug APG scripts using those engines with the NT Option Pack Script Debugger or Visual InterDev 6.  We have also seen that the Python script engine supports Active Script Debugging, but a bug in the implementation causes current statement highlighting to be wrong.

Error Reporting

Filenames (of include files) and line numbers are not reported in some scripting engines, because the script engines to not report the context ID for the error.  A related bug is that you may receive both accurate and inaccurate line numbers for the errors.

APGScript.Run()

As of this writing, APGScript.Run() cannot be called more than once when running an APG script containing PerlScript or Python code.  This is because the script engines do not support IActiveScript::Clone()

Here is an example JScript code fragment that runs an APG script twice using APGScript.Run():


var oAPGen = Script.CreateObject("APGen");
var oScript = oAPGen.OpenScript("script.apg");

// Set a script variable
oScript("user") = "wilma";

// The first call to APGScript.Run() will always work
oScript.Run();

// Change the script variable
oScript("user") = "fred";

// The second and later calls to APGScript.Run() will fail
// if the script contains PerlScript or Python code.
oScript.Run();

This code will cause an error the second time APGScript.Run() is called, if script.apg contains PerlScript or Python code.  To execute a PerlScript or Python script multiple times, re-open the script each time you run it:


var oAPGen = Script.CreateObject("APGen");
var oScript = oAPGen.OpenScript("script.apg");

// Set a script variable
oScript("user") = "wilma";

// Call Script.Run the first time
oScript.Run();

// To call Script.Run more than once, re-open the APG script.
oScript = oAPGen.OpenScript("script.apg");

// Set the script variable
// Note that since the script was re-opened, any previous
// script variables are gone.
oScript("user") = "fred";

// Call Script.Run (again)
oScript.Run();

This workaround is not as efficient as the first code fragment, but it works when running APG scripts that contain PerlScript or Python.

Mixing Languages: PerlScript 

For more information on mixing languages, see Mixing Script Languages.

When calling a function or procedure from PerlScript that is implemented in a different language, use the syntax $ScriptingNamespace->[Function]([Params]);, which is the same syntax required for mixing PerlScript with other languages in ASP.  This syntax is not required in VBScript or JScript.  For example:

<%# @LANGUAGE="PerlScript" #%>
<SCRIPT RUNAT=APGen LANGUAGE=VBScript>


Function Square(x)
     Square = x * x
End Function

</SCRIPT>
<SCRIPT RUNAT=APGen LANGUAGE=JScript>


function Cube(x)
     {
     return x*x*x;
     }
    
</SCRIPT>
<%#

## PerlScript Main() function
sub Main
     {
     $x = 7;
    
     ## call the VBScript Square function
     $x_squared = $ScriptingNamespace->Square($x);
#%>X squared: <%# =$x_squared #%>
<%#

     ## call the JScript Cube function
     $x_cubed = $ScriptingNamespace->Cube($x);
#%>X cubed: <%# =$x_cubed #%>
<%#

     }
#%>

This APG script produces the following output:

X squared: 49
X cubed: 343

Another issue when mixing languages with PerlScript is that PerlScript globals are not accessible from other languages.  However, PerlScript subs can be called from other languages.

Mixing Languages: Python 

When calling a function or procedure from Python that is implemented in a different language, use the syntax ScriptingNamespace.[Function]([Params]), which is the same syntax required for mixing Python with other languages in ASP.  This syntax is not required in VBScript or JScript.

Properties

In PerlScript, properties of COM objects are accessed using the $[Object]->{[Property]}; syntax.  An example:

$Log->{Flags} = 4;

Constants

APGen constants (for example the values used for Log.Flags or APGen.StatusDlg) are not available within PerlScript or Python.   Use the numeric values instead.

Run-Time Errors

Run-time errors in Python script may not cause the debugger to run.  Run-time errors in VBScript and JScript cause the debugger to run, as long as the Script.Debug property is set to True.