process. Compiling and processing string


String will be compiled and executed as code in Parser, within specified scope or current scope. Specified scope can be an object or a class, but not method (this meaning if you process something inside your method, the method`s local varuables will not available inside processed code).

This operator is useful when you need to store fragments of code or your own methods in files with extension other than
.html-and which therefore will not be processed by Parser by default-or in a DB.

options (hash) may be specified:
·$.main[a new name for main method, declared in code in string]  
·$.file[a name of file, from which this string comes from]  
·$.lineno(a line number in file, where this string cames from. may be negative)  
·$.replace(true)-starting from version 3.4.3 the exception occurs in case of loading class if a class with the same name was already loaded. It can be switched off by specifying a new $.replace(true) option.  

Simple examples
PS: you look really good…

Method extra will be added to the current class and you will be able to call it later on.

5… 4… 3… 2… 1… GO!

Method start will be added to user class engine.

Name$name<br />
As the code is executed within the scope of object $running_man, it is able to use the object's field name and output "Jack".

Include operator
The code loads specified file and executes it within the scope of the current object/class when include was called. File option allows us to specify the name of file, where this code were loaded from. In case there would be some error, you would see this "file name".
Note: "scope of current call" does not include any local variables or parameters!

Complex example
It is often convinient to compile a code to some method, which name evaluated dynamically:
# this is source code, note ^^
it is evaluated dynamically, that we need to create the "method1" method 
compiling source code, storing it to new method
later in code it can be called
This example would continue to work even if in $source_code there would be declared several methods, because main option sets the name of main method.

Copyright © 1997–2017 Art. Lebedev Studio | Last updated: 22.10.2013