Runtime Type Information (RTTI)

No matter if your language is statically or dynamically typed, you can always access RTTI in Neko. RTTI is powerful because you can decide which behavior to adopt depending on some value at runtime. The most common application of this is to print some debugging information. Another one is introspection : the ability to look inside an object, read its fields, and call its methods.

The builtin $typeof returns an integer specifying the type of a value according to the following table :

TypeConstantValue
null$tnull0
int$tint1
float$tfloat2
bool$tbool3
string$tstring4
object$tobject5
array$tarray6
function$tfunction7
abstract$tabstract8

Example :

$typeof(3); // 1
$typeof($array(1,2)); // 6
$typeof(null) == $tnull; // true

You can use the builtins for Objects, Strings, Functions, and Arrays to manipulate them at runtime.

© 2019 Haxe Foundation | Contribute to this page