Types and Type Info

Types are a first class type in Jai. You can do the things with a type that you would with any other variable. You can get the type of some variable using type_of. The Type from type_of is a Type.

var: Type = int;
print("%\n", var); // prints "int". since var=int.
var = Vec3;
print("%\n", var); // print "Vec3", since var=Vec3.

You can compare types for equality. The type matches another type in cases when int == int, float == float, etc. int != u8.

var: Type = int;
if var == int then {
  print("var = %\n", var);
}

Type_Info is a struct containing all sorts of type information, such as the name of the struct members, the offset of the member in bytes, the type of the members, notes attached to the members, etc.

Vec3 :: struct { x, y, z: float; }

info := type_info(Vec3);
for member : info.members {
  print("%\n", member.name); // prints out x, y, z
}