| IGLib 1.7.2 The IGLib base library for development of numerical, technical and business applications.

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
Public Member Functions | Protected Member Functions | Protected Attributes | Properties | Private Attributes | List of all members
IG.Lib.ExpressionEvaluatorJint Class Reference

JavaScript Evaluator with command-line interpreter, based on Jint. More...

Inheritance diagram for IG.Lib.ExpressionEvaluatorJint:
[legend]
Collaboration diagram for IG.Lib.ExpressionEvaluatorJint:
[legend]

## Public Member Functions
| ExpressionEvaluatorJint ()
| Initializes a new JavaScript evaluator. This includes compiling the JavaScript code where evaluation is plugged in. More...
override object | EvalToObject (string code)
| Evaluates JavaScript code and returns result as object. More...
override string | EvalToString (string code)
| Evaluates (interprets) JavaScript code and returns string result of evaluation. Code must be such that result of evaluation can be interpreted as string. More...
override string | Execute (string inputCode)
| Executes the specified code and returns the result. Throws exception if errors occur when interpreting code. After execution, the code is appended to the complete code that has been executed up to this point. More...
Public Member Functions inherited from IG.Lib.ExpressionEvaluatorJs
| ExpressionEvaluatorJs ()
| Initializes a new JavaScript evaluator. This includes compiling the JavaScript code where evaluation is plugged in. More...
override void | RepairCommand (ref string command)
| Repairs the specified command and returns the repaired command string. More...
void | Register ()
| Registers the current object. Subsequent calls (after the first one) have no effect. More...
bool | IsRegistered ()
| Returns true if the current object is registered, false if not. More...
void | Unregister ()
| Unregisters the current object if it is currently registered. Can be performed several times, in this case only the first call may have effect. More...
Public Member Functions inherited from IG.Lib.ExpressionEvaluatorCompiled
| ExpressionEvaluatorCompiled ()
| Initializes ID and calls the main initialization method (which will typically be overridden in every subclass). More...
virtual int | EvalToInteger (string code)
| Evaluates (interprets) JavaScript code and returns integer result of evaluation. Code must be such that result of evaluation can be interpreted as integer. More...
virtual double | EvalToDouble (string code)
| Evaluates (interprets) JavaScript code and returns double result of evaluation. Code must be such that result of evaluation can be interpreted as double. More...
string | GetRepairedCommand (string command)
| Repairs the specified command and returns the repaired command string. More...
virtual string | Compile (string inputDefinitions)
| Recompiles the basic script where evaluatin is plugged in, with added definitions. Throws exceptions if errors occur when compiling code. After execution, user definitions are added to the base script if compilatin is successful, so that they can be used in subsequent evaluations of code. More...
void | Reset ()
| Resets the code evaluator (clears variable definitions, etc.). More...
virtual void | PrintHelpCommandLine ()
| Prints help for the command-line JavaScript interpreter to the standard output. More...
virtual void | PrintDefinitions ()
| Prints all definitions (preinstalled and user defined). More...
virtual void | PrintCompleteCode ()
| Prints the complete code that has been input up to now to the console. More...
virtual void | SaveCompleteCode (string filePath, bool append)
| Prints the complete code inserter up to this moment. More...
virtual void | UserSaveCompleteCode (bool append)
| Saves or appends the complete code evaluated up to now to a file specified by the user. User is promped for the file to which code is saved. More...
virtual void | SaveUserDefinitions (string filePath, bool append)
| Saves or appends to the specified file all valid user definitions added to the evaluator up to this point. More...
virtual void | UserSaveUserDefinitions (bool append)
| Saves or appends the all valid user definitions added to the evaluator up to this point. User is promped for the file to which definitions are saved. More...
virtual void | CommandLine ()
| Command-line utility where user can successively enter JavaScrit expressions or general portions of code, and evaluates them. Displays prompt to instruct the user, and result of operations. More...

## Protected Member Functions
override void | InitExpressionEvaluator ()
| Contains initializations for the particular class. More...
Protected Member Functions inherited from IG.Lib.ExpressionEvaluatorJs
override void | InitExpressionEvaluator ()
| Contains initializations for the particular class. More...
Protected Member Functions inherited from IG.Lib.ExpressionEvaluatorCompiled
virtual string | CompileBase ()
| Compiles the base script where evaluation is plugged in, and loads the generated assembly and necessary objects. More...
virtual string | CompileBase (string inputDefinitions)
| Compiles the base script where evaluation is plugged in, and loads the generated assembly and necessary objects. More...
virtual string | ExecuteUser (string command)
| Executes the code, prints results and reports eventual errors. Also appends the code to the complete valid code that has been interpreted up to now. More...
virtual string | CompileUser (string inputDefinitions)
| Compiles the specified new definitions. If compilation is successful, the definitions are added to existing definitinos and user is notified through console. Otherwise, error is reported on console. More...
virtual string | ExecuteUser (ref string inpDefinitions, ref string inpCode)
| Compiles definitions, if any specified, and executes code, if any specified. Eventual results and errors are reported in console. After execution, code and definitions are set to null. More...

## Protected Attributes
string | BaseDefinitionsJint
Protected Attributes inherited from IG.Lib.ExpressionEvaluatorJs
string | _baseDefinitionsJs
string | _baseDefinitionsJsExtended
Protected Attributes inherited from IG.Lib.ExpressionEvaluatorCompiled
int | _outputLevel = DefaultOutputLevel
| Default level of output for some of the interpreters' functionality (e.g. asynchronous command execution). More...
string | _language = "unknown"
string | _packageName = "Evaluator"
string | _className = "EvaluatorClass"
string | _evaluationFunctionName = "Eval"
string | _inputMark = "Calc> "
char | _multiLineCharacter = '\\'
string | _commandLineHead
string | _commandLineStopNote
string | _helpCommandLineHeading
string | _helpCommandLine

## Properties
override string | BaseDefinitions`[get, protected set]`
| A set of pre-defined definitions that can be used in the evaluated code. More...
Jint.Engine | JsEngine`[get]`
| JavaScript execution engine. More...
Properties inherited from IG.Lib.ExpressionEvaluatorJs
override string | BaseDefinitions`[get, protected set]`
| A set of pre-defined definitions that can be used in the evaluated code. More...
override string | ScriptBase`[get]`
| Container for compiled code that evaluates JavaScript expressions. More...
ObjectRegister < ExpressionEvaluatorJs > | ObjectRegister`[get]`
| Gets object register where the current object is registered. More...
static ExpressionEvaluatorJs | Global`[get, protected set]`
| Global JavaScript expression evaluator. Initialized on first use. More...
Properties inherited from IG.Lib.ExpressionEvaluatorCompiled
int | Id`[get]`
| Returns object's Id that is unique within a given type. More...
int | OutputLevel`[get, set]`
| Level of output for some of the interpreter's functionality (e.g. asynchronous command execution). More...
object | Lock`[get]`
| Used for locking internal fields. More...
virtual string | Language`[get, protected set]`
| Programming language in use. More...
virtual string | PackageName`[get, protected set]`
| Name of the JavaScript package in which evaluated code is executed. More...
virtual string | ClassName`[get, protected set]`
| Name of the JavaScript class that is compiled to execute the evaluated code. More...
virtual string | EvaluationFunctionName`[get, protected set]`
| Name of the function used for evaluation of expressions. More...
virtual string | BaseDefinitions`[get, protected set]`
| A set of pre-defined definitions that can be used in the evaluated code. More...
string | CompleteCode`[get, protected set]`
| All valid user code inserted up to this point. Only code that compiled and executed without errors is taken into account. More...
virtual string | UserDefinitions`[get, protected set]`
| A set of definitions inserted by users. More...
virtual string | NewUserDefinitions`[get, set]`
| New user definitions that are added temporarily for testing. More...
virtual string | Definitions`[get]`
| All definitions (pre-defined and user-defined) that can be used in the evaluated code. More...
abstract string | ScriptBase`[get]`
| Container for interpreted code. More...
virtual string | HelpCommandLine`[get]`
| Returns textual help for JavaScript command-line interpreter. More...
Properties inherited from IG.Lib.ILockable
object | Lock`[get]`
Properties inherited from IG.Lib.IIdentifiable
int | Id`[get]`
| Returns unique ID (in the scope of a given type) of the current object. More...
Properties inherited from IG.Lib.IRegisterable< T >
ObjectRegister< T > | ObjectRegister`[get]`
| Gets the object register where the current object can be registered. More...

## Private Attributes
Jint.Engine | _jsEngine = null

## Additional Inherited Members
Static Public Member Functions inherited from IG.Lib.ExpressionEvaluatorJs
static void | ExampleCommandLine ()
| Launches command-line JavaScript interpreter. More...
Public Attributes inherited from IG.Lib.ExpressionEvaluatorJs
string | BaseDefinitionsJsAdditional
Static Public Attributes inherited from IG.Lib.ExpressionEvaluatorCompiled
static int | DefaultOutputLevel = 0
Static Protected Attributes inherited from IG.Lib.ExpressionEvaluatorJs
static ExpressionEvaluatorJs | _evaluatorGlobal = null

## Detailed Description

JavaScript Evaluator with command-line interpreter, based on Jint.

See also: https://github.com/sebastienros/jint/blob/master/README.md

$A Igor Oct15;

## Constructor & Destructor Documentation

IG.Lib.ExpressionEvaluatorJint.ExpressionEvaluatorJint | ( |  | ) |
| inline

Initializes a new JavaScript evaluator. This includes compiling the JavaScript code where evaluation is plugged in.

## Member Function Documentation

override void IG.Lib.ExpressionEvaluatorJint.InitExpressionEvaluator | ( |  | ) |
| inline protected virtual

Contains initializations for the particular class.

This method is called form base class' constructor.

Implements IG.Lib.ExpressionEvaluatorCompiled.

override object IG.Lib.ExpressionEvaluatorJint.EvalToObject | ( | string | code | ) |
| inline virtual

Evaluates JavaScript code and returns result as object.

Parameters

  code | JavaScript code to be evaluated.

Returns
  Object that is result of evaluaton of code.

Reimplemented from IG.Lib.ExpressionEvaluatorCompiled.

override string IG.Lib.ExpressionEvaluatorJint.EvalToString | ( | string | code | ) |
| inline virtual

Evaluates (interprets) JavaScript code and returns string result of evaluation. Code must be such that result of evaluation can be interpreted as string.

Parameters

  code | Code that is evaluated.

Returns

Reimplemented from IG.Lib.ExpressionEvaluatorCompiled.

override string IG.Lib.ExpressionEvaluatorJint.Execute | ( | string | inputCode | ) |
| inline virtual

Executes the specified code and returns the result. Throws exception if errors occur when interpreting code. After execution, the code is appended to the complete code that has been executed up to this point.

Parameters

  inputCode | Code that is exected by the JavaScript interpreter.

Returns
  Result of code execution as string.

Reimplemented from IG.Lib.ExpressionEvaluatorCompiled.

## Member Data Documentation

string IG.Lib.ExpressionEvaluatorJint.BaseDefinitionsJint
| protected

Initial value:
= @"
//Checks if an object is an array or not.
function isarray(obj)
{
//returns true is it is an array
if (JSON.stringify(obj)[0] == '[')
return true;
else
return false;
}
// Returns string representation of the argument.
// String represeentation is obtained by JSON.stringify()
function str(obj) {
return JSON.stringify(obj)
}
"

Jint.Engine IG.Lib.ExpressionEvaluatorJint._jsEngine = null
| private

## Property Documentation

override string IG.Lib.ExpressionEvaluatorJint.BaseDefinitions
| get protected set

A set of pre-defined definitions that can be used in the evaluated code.

Jint.Engine IG.Lib.ExpressionEvaluatorJint.JsEngine
| get private

JavaScript execution engine.

The documentation for this class was generated from the following file:

- igbase/interpreters/ExpressionEvaluatorJint.cs