Added for classes. Can be easily extended to structs with just some copy-paste work, but I can't be bothered - ZScript structs are so janky and full of bugs that I'd say they're not that useful in 99% of the cases where you'd want to use a struct.
Example code:
Code: Select all
version "4.2"
class TestActor1 : Actor {
int foo;
mixin ItBeAMixin;
int bar;
override void Tick () {
foo++;
bar = EnumConst_C;
Console.Printf ("foo: %d, margarine: %d, bar: %d, actorPtr: %d", foo, ICantBelieveItsNotButter, bar, !!actorPtr);
}
}
class TestActor2 : Actor {
int foo;
int bar;
mixin ItBeAMixin;
default {
+TestActor2.FLAGGY
}
states {
Spawn:
BAL1 A 1;
loop;
}
override void PostBeginPlay () {
Super.PostBeginPlay ();
bar = 1;
actorPtr = self;
}
override void Tick () {
foo = EnumConst_B;
bar *= 2;
Console.Printf ("foo: %d, margarine: %d, bar: %d, actorPtr: %d", foo, ICantBelieveItsNotButter, bar, !!actorPtr);
}
}
mixin class ItBeAMixin {
enum ItsAnEnum {
EnumConst_A,
EnumConst_B,
EnumConst_C,
};
Actor actorPtr;
int ICantBelieveItsNotButter;
flagdef FLAGGY: ICantBelieveItsNotButter, 0;
default {
+SOLID
+ISMONSTER
// Can't set FLAGGY here, as it'll have the class' identifier and we can't know that in advance.
}
states {
Spawn:
TROO A 1;
loop;
}
}
Graf Zahl wrote:What do you want to do with mixins in functions? Those are ten times more complicated than structs or classes.
Mixins could be useful for functions too. For example, if you have a long loop that's the same in two different functions, but can't be moved to a third function for some reason.
Graf Zahl wrote:You also cannot initialize class members in the class body, there is no backing implementation for that. Keep it simple at first, if you want too much at once it won't end well.
Hm? As the comments in the example code say, that would be a syntax error if used for anything other than a "mixin function" block.
By the way... Wow. There's a TON of places to change if you want to add new tokens to the parser. I feel like stuff like that should be documented somewhere...