This is designed to help you use structured data within the memory block/array. A group identifier can be composed of letters, numbers, and _, followed by the hash symbol #.
Given a group, e.g. FOO#, each suffix (e.g. FOO#bar) is given a unique index, counting from zero. The plain expression (e.g. just FOO# without a suffix) is replaced by the number of suffices there are defined by that group.
To force an enum to have a particular value, you can include a number in brackets after it, e.g. FOO#bar(5). If there is a conflict in these, the pre-processor throws an error.
Counting
If a group is not counted (e.g. FOO#) at any point in the code, then a warning is produced.
Switchable functions
The JSFX language has no function pointers, but sometimes you want a different function to be called depending on a field in your struct. In that case, you can create a "switchable function group", which generates a function that checks the value and then relays to other functions.
Example
Input:
pointer[MYSTRUCT#INIT_FUNC] = {init_func}some_init; // Create reference to functionfunction some_init(x, y) ( // Perform some init);// Group declaration - placed below all referencesfunction {init_func}(x, y);// Call a function pointer{init_func:pointer[MYSTRUCT#INIT_FUNC]}(1, 2);
Output:
pointer[0] = 1; // Create reference to functionfunction some_init(x, y) ( // Perform some init);// Group declaration - placed below all referencesfunction init_func(function_id, x, y) ( function_id ? ( function_id == 1 ? some_init(x, y) ););;// Call a function pointerinit_func(pointer[0], 1, 2);
Sequence templates
Unrolling loops produces a lot of almost-duplicated code, so we have a syntax for numeric sequences.
Sequences are opened with {#var=start,end} and closed with {#}. start and end are integers. The limits are inclusive, and can be reversed to get a backwards-counting sequence.