Built-In Functions

Scott Waldron Updated by Scott Waldron

Dino has several built-in functions that can make it easier to create common data structures without resorting to imports from types of the host language.

assert(expr [, onFailure])

Asserts that something is true and causes a failure if it is not. You can pass a failure object as the second argument to give information about the failure.

from MyDbData.SysAdmin import AdminUser;

assert(user is AdminUser, 'Must be admin');
assert(false); // bomb;

An assert function is just a simplified way of doing this.

if not user in AdminUser {
fail 'Must be admin';
}

The only real difference is that the assert function will always throw a ScriptAssertFailedException, with an inner exception as the reason for the failure, whereas a fail statement will be either a simple Exception (in the case of passing a string or other object), or whatever Exception object is constructed. The assert function will also be more consistent about reporting the line and column number where the failure occured.

The assert function always returns null.

eval(expr [, expr]...)

The eval function will evaluate a function with its string name, followed by arguments to that function. Note that in Dino eval only evaluates functions, not other expressions or constant values. Its only purpose is to evaluate a function by its string name.

def evaluateThis(x, y) {
return x + y;
}

var x = eval('evaluateThis', 1, 1); // 2
var func = 'evaluateThis';
var y = eval(func, 2, 2); // 4

Prints each expression to a new line in console output and returns the last expression that was passed to it in its argument list, or null if no arguments were passed.

print(); // just a new line, return null
print(1, 2, 3); // 1, 2, 3 on each line, return 3

list([expr] [,expr]...)

The list function is used to create a list of objects. You can pass any number of expressions to the list function to initialize it with values.

var eras = list();
var nums = list(3, 4, 5);
// create a generic list of String objects
var strs = list[string]('one', 'two');
each s in strs {
print(s);
}

If you do not specify a type parameter for the list, all its elements will be of type object, which may not be what you expect.

var nums = list(1, 2, 3); // list of objects containing 1, 2, 3
nums.Add('hello'); // ok
var betterNums = list[int](1, 2, 3); // list can only contain integers
betterNums.Add('hello'); // error, int list cannot take string value

array([expr] [,expr]...)

The array function is used to create a fixed-size array of objects. You can pass any number of expressions to the array function to initialize it with values. You can also pass an indexed expression to set the size of the array.

var nums = array(3, 4, 5);
// fixed size array with uninitialized values
var bigNums = array[int]()[1000];

dict( [dictLiteral] [, dictLiteral]...)

The dict function is used to create a dictionary (key/value pairs). You can pass dictionary literal values to the function to initialize it with values.

// create an object, object dictionary
var simple = dict();
// just declare the type of the key - value will be type object
var d = dict[string]();
d['one'] = 8;
d['two'] = 'hello';
// declare both the type of key and the type of the value
var d2 = dict[string, int]();
// initialize with values (dictionary literals)
var d3 = dict('one':1, 'two':2);

dynamic()

The dynamic function is used to create a dynamic object, that is, one which can have new properties added to it at runtime.

var dyn = dynamic();
dyn.rex = null;
dyn.foo = 0;
dyn.bar = 'a string value';
print(dyn.bar);
// dynamic properties can also be accessed using index syntax
print(dyn['bar']);
// accessing an unassigned property is an error
print(dyn.notThere); // error

import(expr [,true|false])

While import is a keyword used in the loading of scripts and types, it is also a function that is used to load DLL files from disk. After calling this function, the types from it may be imported.

This function is usually only needed to load custom DLLs from elsewhere in the system, because Dino will generally automatically find types that are in the bin directory of the application that hosts it.

import('C:\\extensions\\dlls\\Jurassic.dll');
from Jurassic.Extinction import KTBoundary;

The import function and type loading may also take place inside of functions, so that the path may be passed as a parameter, for example.

from System.IO import Path;

def init(dllPath) {
var dlls = list[string]('Jurassic', 'Triassic', 'Cretaceous', 'Pleistocene');
each dll in dlls {
import(Path.Combine(dllPath, dll + '.dll'));
}
from Jurassic.Animals import Tyrannosaur as TRex;
}

init('C:\\extensions\\dlls\\');

The import function takes an optional second parameter which is a true/false value that indicates whether the DLL should be reloaded from disk. The default value is false.

import('C:\\extensions\\dlls\\Foo.dll', true);

How did we do?

Blocks and Scopes

Custom Functions (defs)

Contact