Compiler - The oScript class to compile itself
Lets do a short overview on the oScript Class Compiler.
The Compiler package consists of functions, datatypes, and constants that are used by the Content server itself to compile, manipulate, and examine Script values and their corresponding OScript source code. This includes the ability to compile OScript source into a Script value, which can then be executed, as well as a variety of functions for internal use only (to support the Content Server SDK = CSIDE).
With the exception of Compiler.Compile(), these functions are not intended for general use by a Content Server application developer and should only be used with extremely careful consideration, if at all. Elements labelled Internal Use Only below may have their interface changed without notice. Special the breakpoint functions may have been changed in CSIDE.
Although its possible to get a String via a Weblingo and compile this String and use it as compiled Script, you should not do this due to security of your system.
SourceRef - Some of these functions refer to something called a sourceRef. A SourceRef is a String value which defines where the script source originated. This is used internally by the Content Server debugger to correspond compiled scripts with their sources, which may be text files or OSpace object features. By convention only, a SourceRef has the form :. For example, the SourceRef String "fle:d:\myfile,lxe" has a resource_type of file. The following SourceRef resource types should be considered reserved: file, weblingo, object, oppfile.
Class attributes
E_CompilationErrors
Indicates errors during compilation.
kLogConversionInfo
Internal use only
kStripSource
Internal use only
Class methods
ClearBreaks( Script theScript )
Clears all breakpoints in the specified script.
Compile( Dynamic sourceValue, [String sourceRef] )
Compiles OScript source into a Script value.
If compilation errors or warnings occur, they will be displayed in the Debug Window or logfile. If only warnings are present, then a Script value will still be returned by this function, although the warnings will appear in the Debug Window or logfile. See Compiler.CompileGeneral() for a more powerful way to detect compilation errors.
Here is an example of using Compiler.Compile() to compile a simple piece of OScript:
领英推荐
String mySource = "function void myFunc( String myParam );echo( 'Param: ', myParam );end"
Script s = Compiler.Compile( mySource )
s( "Hello Reiner" )
Param: Hello Reiner
CompileGeneral( Dynamic sourceValue, [String sourceRef], [Integer compilationFlags] )
Compiles OScript and returns a List of errors.
The following example shows how errors can be extracted:
String mySource = "function void myFunc( String myParam );echo( 'Parameter: ', myBuggyParam );end"
List tuple = Compiler.CompileGeneral( mySource )
if IsError( tuple[ 1 ] )
String s
for s in tuple[ 2 ]
echo( "Error before breakup: /", s, "/" )
List errTuple = Str.Elements( s, Str.Eol() )
echo( "...Severity: ", errTuple[ 1 ] )
echo( "...Text: ", errTuple[ 2 ] )
echo( "...Range: ", errTuple[ 3 ] )
end
end
and the Optput is
Error before breakup: /Error
The name 'myBuggyParam' is not known at this point. Please check your spelling and compile again.
[1.60:1.72]/
...Severity: Error
...Text: The name 'myBuggyParam' is not known at this point. Please check your spelling and compile again.
...Range: [1.60:1.72]
GetBreakOnEntry( Script theScript )
Returns TRUE if the given Script value contains a breakpoint on its first executable line, FALSE otherwise.
MakeScript( String source, [String sourceRef] )
Creates a Script value that contains source, but no compiled binary code.
Prototype( Script theScript )
SetBreakOnEntry( Script theScript, Boolean setBreak )
Sets or clears the initial breakpoint of a script.
Source( Script theScript )
Extract the source code (if any) from a Script value.
SourceRef( Script theScript )
Extract the SourceRef (if any) from a script.