OOP Madness.

Reaction score
341
This is just an example for people who want to code in a more OOP style.
With the example included, things like this are possbile;

JASS:
scope fail initializer onInit

    private function onInit takes nothing returns nothing
        call Var.String.Print("hey!") // Displays hey!
        call Var.Int(12).toString().Print() // Displays 12
    endfunction

endscope


You can make a wrapper for almost anything.
It's basically just a bunch of pointers.

JASS:
library VariableWrapper initializer onInit

    private struct StringEx
        static method Print takes string s returns nothing
            call BJDebugMsg(s)
        endmethod
    endstruct
    
    private struct IntEx
        static string s
        method Print takes nothing returns nothing
            call BJDebugMsg(IntEx.s)
            set IntEx.s = ""
        endmethod
        method toString takes nothing returns IntEx
            set IntEx.s = I2S(this)
            return 0
        endmethod
    endstruct
    
    struct Var
        static StringEx String
        static method Int takes integer i returns IntEx
            return i
        endmethod
    endstruct

endlibrary


This is not a script submission therefore I am not writing any documentation on this.
It's meant to just show you that it can be done fairly easily and is for the people who enjoy writing in OOP.
Yes it probably has been known for a long time but this was inspired by someone asking about nested structs and I decided that it may not be common knowledge.
 

Jesus4Lyf

Good Idea™
Reaction score
397
I think there's cooler things, like exploiting modules to make modules which plug into a library, and then you can "nest" textmacros but running textmacros in the library module:
JASS:
//! textmacro libmod takes IDENTIFIER
    module $IDENTIFIER$
        endstruct
//! endtextmacro
//! textmacro endlibmod
        scope KKX
            private struct thistype extends array
        endscope
    endmodule
//! endtextmacro
//! textmacro implementlibmod takes IDENTIFIER
    private struct LibModImplement$IDENTIFIER$ extends array
        implement $IDENTIFIER$
    endstruct
//! endtextmacro

library TextmacroTextmacro
    //! textmacro H2I
        function H2I takes handle h returns integer
            return GetHandleId(h)
        endfunction
    //! endtextmacro
    //! runtextmacro libmod("H2I")
        // "Nested" textmacro here:
        //! runtextmacro H2I()
    //! runtextmacro endlibmod()
endlibrary

library MyLibraryWithModules
    //! runtextmacro implementlibmod("H2I")
    function DoH2I takes handle h returns integer
        return H2I(h)
    endfunction
endlibrary

If you think it doesn't compile, think again. :)
 

Lyerae

I keep popping up on this site from time to time.
Reaction score
105
> This was inspired by someone asking about nested structs and I decided that it may not be common knowledge.

Glad I could help? Anyway, it helps me greatly (depending on how it works. I haven't had a chance to test it yet).
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top