This page has been translated automatically.
Programming
Fundamentials
Setting Up Development Environment
UnigineScript
High-Level Systems
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Bounds-Related Classes
Containers
Controls-Related Classes
Engine-Related Classes
GUI-Related Classes
Node-Related Classes
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
Rendering-Related Classes
Utility Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Expression Class (UnigineScript)

This class allows you to execute a given code fragment at run-time. There can be up to 4 arguments of any type passed to the Expression. The setVariable() function sets values of such arguments. For example:

Source code(UnigineScript)
Expression e0 = new Expression("133.0 * 133.0");
if(e0.isCompiled()) {
	log.message("%s\n",typeinfo(e0.run()));
}

Expression e1 = new Expression("
	{
		int a,b,c,d;
		return a + b + c + d;
	}");

e1.setVariable("a",1);
e1.setVariable("b",2);
e1.setVariable("c",3);
e1.setVariable("d",4);

if(e1.isCompiled()) {
	log.message("%d\n",typeinfo(e1.run()));
}

Expression e2 = new Expression("
	{
		string name;
		File file = new File(name,\"rb\");
		int size = file.getSize();
		file.close();
		delete file;
		return size;
	}
");
e2.setVariable("name","test.cpp");
if(e2.isCompiled()) {
		log.message("%s\n",typeinfo(e2.run()));
}
Output
double: 17689
int: 10
int: 1302

Expression Class

Members


Expression (string src, int scope = 0 = 0)

Runs the expression pointed to.

Arguments

  • string src - Source buffer pointer.
  • int scope = 0 - 1 to treat the expression namespace as the global; otherwise, 0 (by default).

int getFunction (string name, int num_args)

Returns the ID of the function from the expression namespace. It can be used to call a function by its ID instead of the name (speeds up the function call; it is almost as fast the direct call).

Arguments

  • string name - Name of the function.
  • int num_args - The number of function arguments.

Return value

Function ID.

string getName ()

Get a name used as a namespace name when calling expression methods.

Return value

Namespace name.

variable getVariable (string name)

Returns ID of the variable from the expression namespace. It can be used to pass a variable by its ID instead of the name. It speeds up passing of the varible and can be used, for example, on mobile devices when the performance is crucial.

Arguments

  • string name - Variable name.

Return value

Variable, if it exists; otherwise, 0.

int isCompiled ()

Returns a value indicating if the given expression has been compiled.

Return value

1 if the expression has been compiled; otherwise, 0.

int isFunction (string name, int num_args)

Checks if a given user-defined function exists in the expression namespace.

Arguments

  • string name - Full name of the target function.
  • int num_args - Number of arguments of the target function.

Return value

1 if the function exists; otherwise, 0.

int isVariable (string name)

Checks if a given user-defined variable exists in the expression namespace.

Arguments

  • string name - Name of the target variable.

Return value

1 if the variable exists; otherwise, 0.

variable run ()

Runs the given expression.

Return value

Argument value.

void setName (string name)

Sets a namespace name for the expression that can be used when calling expression methods.

Arguments

  • string name - Namespace name.

void setVariable (string name, variable value)

Set the value of the variable from the expression namespace by its name.

Arguments

  • string name - Variable name.
  • variable value - Variable value to set.
Last update: 2017-07-03
Build: ()