Structures (ACS) - DavidPH/GDCC GitHub Wiki
GDCC provides structures as an extension for ACS, based on a reduced C syntax. Structures are objects that can hold multiple named members of potentially different data types.
struct SomeStruct
{
// Members are declared like variables.
int i;
// Members of any type can be mixed in structures.
str s;
fixed f;
}
// The struct name becomes a type name, usable where int/str/fixed/bool would be.
SomeStruct MyStructure;
// Functions can receive and return structs.
function SomeStruct StructFunc (SomeStruct st)
{
ss.i = 10;
ss.s = "test";
ss.f = 2.0;
return ss;
}
Script "StructTest" OPEN
{
MyStructure = StructFunc(MyStructure);
// output: 10, test, 2.0
Log(i:MyStructure.i, s:", ", s:MyStructure.s, s:", ", f:MyStructure.f);
}
Structures can hold other structs inside them, as well as arrays. However, the structure itself must be stored in an array to allow accessing array members (unless the index is constant).
struct ArrayTest
{
SomeStruct ss;
int a[5];
}
ArrayTest NotArray;
ArrayTest IsArray[4];
Script "ArrayStructTest" (void)
{
// Fine, index is constant.
NotArray.a[2] = 5;
IsArray[0].[3] = 2;
int i = 4;
// Errors out, index is variable.
// NotArray.a[i] = 2;
// No problem if the struct is stored in an array.
IsArray[1].a[i] = 1;
}
Structures can also be initialized like in C.
SomeStruct InitTest = {5, "structs are nice", 1.0};