The authors of various libraries cannot know which libraries the final application developer will use in their product. Therefore, using #PB_Event_FirstCustomValue in a library's Enumeration can eventually lead to conflicts and bugs.
It's possible to create a unified library for dynamic event registration, but ultimately, many developers won't use it. Thus, this problem needs to be solved at the compiler level.
At the compiler level, there should be a general rule for dynamically adding events. I suggest implementing a rule something like this: if the code contains an assignment of the constant Enumeration #PB_Event_FirstCustomValue or something like #LibEvent = #PB_Event_FirstCustomValue, then automatically increment #PB_Event_FirstCustomValue by 1.
Code: Select all
; Independent library number 1 from one author
Enumeration #PB_Event_FirstCustomValue ; the first time this combination is called #PB_Event_FirstCustomValue = 65536
#Library1_Event1
#Library1_Event2
#Library1_Event3
EndEnumeration
; The compiler, when encountering the combination Enumeration #PB_Event_FirstCustomValue, here in EndEnumeration, the compiler must set #PB_Event_FirstCustomValue = #PB_Compiler_EnumerationValue
; ...
; Independent library number 2 from the second author
Enumeration Library2_Event #PB_Event_FirstCustomValue
#Library2_Event1
#Library2_Event2
#Library2_Event3
EndEnumeration
; ...
; Independent library number 3 from the third author
Enumeration #PB_Event_FirstCustomValue ; This is the third challenge of this combination and here #PB_Event_FIRSTCURTOMVALUE should be 65542
#Library3_Event1
#Library3_Event2
#Library3_Event3
EndEnumeration
; ...
; Independent library number 4 from another author
#Library4_Event1 = #PB_Event_FirstCustomValue + 1
; The compiler, encountering the equation #MyConst = #PB_Event_FirstCustomValue, must set #PB_Event_FirstCustomValue + 1
When creating a library and using events, we could set a random number for our custom events:
Code: Select all
Enumeration Event #PB_Event_FirstCustomValue + 300000
#MyLib_Event1
#MyLib_Event2
#MyLib_Event3
EndEnumeration