14 years
edited 8 years
This will tutorial goes over how to create an interface with a module.
When people create interfaces, they typically use function interfaces, interfaces, or if they are cool, plain old triggers. There is a way to create an interface for a struct without having to rely on dynamic code by cleverly using static ifs.
Let's say that when an event occurs in the root struct, like a unit is indexed or a player types a chat message, it calls certain methods within the derived structs. These methods are normally called via stub methods and extension, function interfaces, or plain interfaces, but they can be called by using triggers and static ifs or by a direct method call in some cases (TimerQueue for example).
And a struct
The trigger evaluation is not necessarily needed in all cases as sometimes the events may be run directly within the struct.
When people create interfaces, they typically use function interfaces, interfaces, or if they are cool, plain old triggers. There is a way to create an interface for a struct without having to rely on dynamic code by cleverly using static ifs.
Let's say that when an event occurs in the root struct, like a unit is indexed or a player types a chat message, it calls certain methods within the derived structs. These methods are normally called via stub methods and extension, function interfaces, or plain interfaces, but they can be called by using triggers and static ifs or by a direct method call in some cases (TimerQueue for example).
1 2 struct ParentStruct extends array
3 private static trigger eventTrig = CreateTrigger()
4 private static trigger fireTrig = CreateTrigger()
5 static readonly thistype data = 0
6 7 private static method onEvent takes nothing returns boolean
8 local integer prevData = data
9 set data = 5 //event data
10 call TriggerEvaluate(fireTrig)
11 set data = prevData
12 endmethod13 14 private static method onInit takes nothing returns nothing
15 call TriggerAddCondition(eventTrig, Condition(function thistype.onEvent))
16 endmethod17 18 static method register takes boolexpr bc returns nothing
19 call TriggerAddCondition(fireTrig, bc)
20 endmethod21 endstruct22 23 module Mod24 static if thistype.fire.exists then
25 private static method firerer takes nothing returns boolean
26 call thistype(ParentStruct.data).fire()
27 return false
28 endmethod29 30 private static method onInit takes nothing returns nothing
31 call ParentStruct.register(Condition(function thistype.firerer))
32 endmethod33 endif34 endmodule35
And a struct
1 2 struct Bleh extends array
3 private method fire takes nothing returns nothing
4 endmethod5 6 implement Mod7 endstruct8
The trigger evaluation is not necessarily needed in all cases as sometimes the events may be run directly within the struct.