• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

InitializerUtils

Level 7
Joined
Apr 27, 2011
Messages
272
This is just a simple set of macros to make the initialization process a bit easier.

How to Install.
1. Create a trigger
2. Copy and paste this code afterwards

JASS:
library InitializerUtils
//===========================================================================
    //! textmacro initializer
        private module defaultM
            private static method onInit takes nothing returns nothing
    //! endtextmacro
    
//===========================================================================
    //! textmacro endinitializer
            endmethod
        endmodule
        
        private struct defaultS extends array
            implement defaultM
        endstruct
    //! endtextmacro
    
//===========================================================================
endlibrary

sample usage

JASS:
scope likeascope
//===========================================================================
    //! runtextmacro initializer()
        call BJDebugMsg("Hello World!!!:D")
    //! runtextmacro endinitializer()
    
//===========================================================================
endscope
 
Last edited:
Level 6
Joined
Jun 20, 2011
Messages
249
JASS:
/*

    struct SomeTest
    
        static method Init takes nothing returns nothing
            ...
        endmethod
        
        implement initialize
        
    endstruct
    
*/


library Initialization

    module Initialize

        private static method onInit takes nothing returns nothing
            call Init()
        endmethod

    endmodule
    
    //! textmacro Initialize
        
        private struct EmptyStruct extends array
            implement Initialize
        endstruct
    
    //! endtextmacro
    
endlibrary
 
Level 7
Joined
Dec 3, 2006
Messages
339
Might be just me; but I think this stuff would fit better in the tutorials section. Or maybe we should have a new "prefix" besides "snippet" like "templates" for the vJASS section.

Also I kind of like Dirac's better. The end initialization part of the text macro seems awkward on alain.mark's.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Names are no good.. they need to be passed as parameters. I don't know about you guys, but sometimes I have more than one initializer in a given library (when there is more than one struct). Also the fact that the struct is inside of the textmacro is no good >.>... private members in the module? Private members in the struct?


Really, after you tear this apart and mess with it to allow the user to use however, it'd be easier to just go with the module approach =).
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
JASS:
//! inject main
//initialize block
//! endinject

Doesn't that override all other injections and also override the normal contents of the "main" function? Could get messy.

@Nestharus, if you want multiple inits you can split them into multiple functions or merge them, you don't need more than one initializer per scope.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Doesn't that override all other injections and also override the normal contents of the "main" function? Could get messy.

@Nestharus, if you want multiple inits you can split them into multiple functions or merge them, you don't need more than one initializer per scope.


It does, you have the "//! dovjassinit", but the result will be exactly the same.
Now, ofc you can handle manually all initializers, but it seems way too much, isn't it ?
The inject feature is not meant to be used like that, even if it is possible.

The problem with merging initializers is that you can't always save the private attribut, or you have to make a wrapper.
 
Top