The .def file format will look familiar to C/C++ programmers, with minimal differences.
.def files can include other .def files using #include:
#include "../path/file.def"You define a struct with the struct keyword, like you do in C++.
struct SomeStruct
{
float a;
int b;
};Unions are declared similarly, but can only store one of the fields. Unions are a way of having a type which can be one of many other types. For instance, you could have a list of components on an object, where each component was a union of the different component types. That would let you have a list of different types of components on the object. Unions can also be "no object", so can be null.
union SomeUnion
{
float a;
int b;
};Enums are integer values, but they have a human readable label to use instead of a "magic number".
enum Vegetables
{
Carrot,
Zucchini,
Broccoli
};You must set the root type of a table using the #root keyword. The root type must be a struct.
#root SomeStructBoth single line comments, and block comments are supported.
// This is my favorite struct
struct MyStruct
{
float health;
//float mana;
int experience;
/*
float armor;
float attack;
float flamability;
*/
string favoriteSnack;
};
/* Here is an explanation
why this is my
favorite struct.
It just is.*/
Fields can be various types:
- bool - true or false
- integers - uint8, int8, uint16, int16, uint32, int32, uint64, int64
- floats - float, double
- string - text
- enum - integers that have labels
- struct - a different struct
- union - a data type that allows a field to be one of a specific list of types. Can be null.
- link - a link to a table entry. Can be null.
default values can optionally be specified. If no default given, the field is zero initialized.
struct SomeStruct
{
int a = 3;
float b = 1.34f;
int c; // zero initialized
string s = "hello!";
};The only new one here is link. A link can point at entries from this table, or other tables. A link can also be none (null). A link is a templated object which takes the table root type as the parameter.
struct DoubleLink
{
Link<SomeStruct> link1;
Link<Monster> link2;
};Any struct field can be an array. Arrays can either be fixed size or dynamic size. A fixed size array gives the size in brackets, while a dynamic array does not give a size.
struct ArrayStruct
{
// A float3 position
float position[3];
// An unbounded number of fears of specific monsters.
Link<Monster> fears[];
};