- Joined
- Mar 19, 2008
- Messages
- 3,141
Hello fellows, here I got a nasty wierd bug and my question is, is there a proper way to avoid it or, what would be even better: clear idea to fix it.
Let's declare a macro which defines library for TYPE, as a default data. It's empty in this example.
We have just declared macro and defined the only default type: integer.
Now, let's declare macro which provides api which is speficic-function dependant. User can define his own method, yet if it does not exist, the next thing that is checked is existence for default library-type. If it does exist, function is declared as a default. The caller should only exist if either user-defined or default-defined method "onFunc" exists. Let's suppose our method is needed for various procedures deeper in the script.
Finally, implement that macro and realise how awkard the problem is:
Question is: why "default" function, which is supposed to be declared only in specific circumstances is treaten in compiled map script as it somehow exists. Whatmore, even though, in example 2, both, user-defined and default method don't exist, static if awaiting "onFunc" existence returns true and thus a compilation error occurs.
Thanks in advance for your time.
Let's declare a macro which defines library for TYPE, as a default data. It's empty in this example.
JASS:
//! textmacro MY_LIB takes TYPE
library $TYPE$MyTest
endlibrary
//! endtextmacro
//! runtextmacro MY_LIB("integer")
Now, let's declare macro which provides api which is speficic-function dependant. User can define his own method, yet if it does not exist, the next thing that is checked is existence for default library-type. If it does exist, function is declared as a default. The caller should only exist if either user-defined or default-defined method "onFunc" exists. Let's suppose our method is needed for various procedures deeper in the script.
JASS:
//! textmacro MY_MACRO takes TYPE
static if not thistype.onFunc.exists then
static if LIBRARY_$TYPE$MyTest then
static method onFunc takes nothing returns nothing
endmethod
endif
endif
static if thistype.onFunc.exists then
static method doFunc takes nothing returns nothing
call onFunc()
endmethod
endif
//! endtextmacro
Finally, implement that macro and realise how awkard the problem is:
JASS:
// Compiles
struct test_obj extends array
//! runtextmacro MY_MACRO("integer")
endstruct
struct test_obj2 extends array
static method onFunc takes nothing returns nothing
endmethod
//! runtextmacro MY_MACRO("real")
endstruct
JASS:
// Does not compile
struct test_obj extends array
//! runtextmacro MY_MACRO("integer")
endstruct
struct test_obj2 extends array
//! runtextmacro MY_MACRO("real")
endstruct
Thanks in advance for your time.