• 🏆 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!

Extendor Construct

Status
Not open for further replies.
Level 21
Joined
Mar 27, 2012
Messages
3,232
I've created a code construct that runs after the whole vJASS preprocessor(or before it, but that's not preferable).

Essentially it works like this:
There are blocks that start with //# extendor and end with //# endextendor.
There are also single-line calls that start with //# runextendor.
Each extendor is named.
Each extendor has a priority(0 if undefined)

When the map has been saved, all extendor blocks are combined into chunks based on name(blocks with the same name are combined together).
Then every runextendor line is replaced with the appropriate block.
If necessary, parts of a block are organized based on priorities. Blocks with lower priority numbers are placed first.

So the formats are:
JASS:
//# extendor NAME [PRIORITY]
    //code
    //more code
//# endextendor

//# runextendor NAME

When extendor blocks are compiled, then the leading whitespace+// is removed from code inside the blocks. Commenting code out is necessary because otherwise the vJASS preprocessor would throw errors.
If you want to use comments inside extendors you need to use another //.
Multiline comments are handled entirely by the vJASS preprocessor, so extendors don't even know of their existence.

Possible uses:
*A projectile system where collision handlers do not need to be defined as triggers. Callback efficiency varies, as at some point it is cheaper to run a trigger than to do a bunch of if-then-else cycles for finding out the proper handler.
*A damage handler for a damage detection system such as the one by looking_for_help. Adds priorities with 0 code overhead.
*Coding events with no code overhead.(unit indexers,damage detection systems,ability managers, among other things)

Thinking about this feature further I have concluded that several vJASS features are partially or entirely subtypes of this construct:
*Globals blocks - Place one runextendor line in the globals block of the war3map.j and add to it with extendors. Identical functionality.
*Text macros without arguments - Define blocks of code with extendor blocks and run with runextendor. Functionality is identical.
*Modules without scoping - Same as text macros.
*Libraries(code organization) - A single runextendor line for the whole map with one extendor block per library to add to it. Libraries work better in this case.

Download from pastebin.

Warning. I do not guarantee that this feature is bug-free or that I will fix it if it doesn't work right or that it will work out of the box like it does for me. I am however willing to help in getting it to work and change/add features when I find it appropriate to do so.
Purposefully breaking the feature does not prove a point to me, as this is not a fully foolproof code construct and was never meant to be such.
I am also not responsible in any way if this construct breaks your JNGPE installation, crashes the editor, destroys your map, targets a nuclear bomb at your house, kills your cat or does anything else that you may find undesirable.

EDIT: Current version is a bit buggy. I'm fixing it as soon as I can.
EDIT2: Not buggy. I'm just an idiot at using my own code.
 
Last edited:
Level 26
Joined
Aug 18, 2009
Messages
4,097
Sounds like injection/hooks. I have made something similar

Code:
module Allocation
	static method allocate_mount takes thistype this returns thistype
		injectTarget hook

//! inject Allocation.allocate_mount.hook
	set this.$varName$ = $default$
//! endinject

But I only used it for system-relevant stuff so far. As you can see it is supposed to be done before jasshelper since I wanted to push vjass code.

May I advertize for my new framework? The downside is that your tool needs to be activated by writing somewhere in the code the line

Code:
//! post Extendor args

If you want it after jasshelper, it's

Code:
//! noJasshelper

//! post Jasshelper --debug jasshelper\common.j jasshelper\blizzard.j $MAP$

//! post Extendor $MAP$

also the tool needs to be defined in jasshelper.conf.

The upside is that we do not need a new wehack.lua for more tools/each combination thereof. Also the processed map is a copy of the one you save in the editor, so it's less likely the individual tool destroys stuff permanently + they are allowed to do finalizing tasks like throwing away editor-only data.
 
Level 21
Joined
Mar 27, 2012
Messages
3,232
Actually it would be ideal to have it run after //! import lines, but before any syntactical changes to the code. I think it's not the same as running after JassHelper.
That would allow using the local names of variables even if they are scoped and thus, it would also allow variable renaming if parameters are provided.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Not as standalone but I can forge you something later this day or tomorrow.

edit:

exttools\vjassImport\

line to add to jasshelper.conf [externaltools]:
Code:
"vjassImport","exttools\\vjassImport\\vjassImport.exe"

In jass code write:

Code:
//! noJasshelper

//! post vjassImport $MAP$

//! post Jasshelper --debug jasshelper\common.j jasshelper\blizzard.j $MAP$

preferably in the header. Things are still ugly and insecure.
 

Attachments

  • vjassImport.zip
    794.8 KB · Views: 26
Last edited:
Status
Not open for further replies.
Top