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
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

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: ()