Library

To store a library (could be a script as a library as well)

Constructors

this
this(string name, bool autoImport)

constructor

Members

Functions

addEnum
integer addEnum(Enum enu)

Adds a new enum

addFunction
integer addFunction(Function func)

Adds a new function

addStruct
integer addStruct(Struct str)

Adds a new struct

addVar
integer addVar(Variable var)

Adds a new variable.

execute
NaData execute(uinteger functionId, NaData[] args)

Executes a library function

fromString
string fromString(string libraryString)

Reads this library from a string (reverse of toString)

functionCallArgumentsPushOrder
uinteger[] functionCallArgumentsPushOrder(uinteger functionId)

For use with generateFunctionCallCode. Use this to change what order arguments are pushed to stack before the bytecode for functionCall is generated

generateFunctionCallCode
bool generateFunctionCallCode(QScriptBytecode bytecode, uinteger functionId, CodeGenFlags flags)

Generates bytecode for a function call, or return false

generateVariableCode
bool generateVariableCode(QScriptBytecode bytecode, uinteger variableId, CodeGenFlags flags)

Generates bytecode that will push value of a variable to stack, or return false

getVar
NaData getVar(uinteger varId)
getVarRef
NaData getVarRef(uinteger varId)

Sets value of a variable

hasEnum
bool hasEnum(string name, Enum enu)
bool hasEnum(string name)
hasFunction
integer hasFunction(string name, DataType[] argsType, DataType returnType)
integer hasFunction(string name, DataType[] argsType)
hasFunction
bool hasFunction(string name)
hasStruct
bool hasStruct(string name, Struct str)
bool hasStruct(string name)
hasVar
integer hasVar(string name, DataType type)
hasVar
bool hasVar(string name)
toString
string toString()

Writes this library to a single printable string

Properties

autoImport
bool autoImport [@property getter]

if this library is automatically imported

enums
Enum[] enums [@property getter]

Enums exported by library

functions
Function[] functions [@property getter]

functions exported by library. The index is function ID.

name
string name [@property getter]

library name

structs
Struct[] structs [@property getter]

structs exported by library

vars
Variable[] vars [@property getter]

global variables exported by this library. index is ID

Variables

_autoImport
bool _autoImport;

if this library is automatically imported

_enums
Enum[] _enums;

Enums exported by library

_functions
Function[] _functions;

functions exported by library. The index is function ID.

_name
string _name;

name of library

_structs
Struct[] _structs;

structs exported by library

_vars
Variable[] _vars;

global variables exported by this library. index is ID

Examples

Library dummyLib = new Library("dummyLib",true);
dummyLib.addEnum(Enum("Potatoes",["red","brown"]));
dummyLib.addEnum(Enum("Colors", ["red", "brown"]));
dummyLib.addFunction(Function("main",DataType("void"),[DataType("char[][]")]));
dummyLib.addFunction(Function("add",DataType("int"),[DataType("int"),DataType("int")]));
dummyLib.addVar(Variable("abc",DataType("char[]")));
Library loadedLib = new Library("blabla",false);
loadedLib.fromString(dummyLib.toString);
assert(loadedLib.name == dummyLib.name);
assert(loadedLib._autoImport == dummyLib._autoImport);
assert(loadedLib._functions == dummyLib._functions);
assert(loadedLib._structs == dummyLib._structs);
assert(loadedLib._enums == dummyLib._enums);
assert(loadedLib._vars == dummyLib._vars);

Meta