User Manual

JASP is the new preprocessor that extends Jass 2 language of Blizzard with a few comfortable additions. Jass 2 syntax is very multiworded; there already is cJass preprocessor by ADOLF that makes possible the writing of C-like code, that will grealtly shorten and making easier the process of coding. I'm not trying to invent a bicycle: yes, in cJass there are many cool additions but in general, as many men said, it can be simplier. New versions can be downloaded at code.google.com and sourceforge.net.



Table of contents


How to install

Download and unpack the jassnewgenpack5d.exe archive. Then download the most fresh version of preprocessor and move it into JASP folder. That's all.


Single local variable declaration

Local variable declaration on classic Jass 2 goes like that:
function someFunc takes nothing returns nothing
	local timer t = CreateTimer()
endfunction
In cJass this became simplier:
void someFunc()
{
	timer t = CreateTimer(); //without cj_typesEx.j library
}

void someFunc()
{
	timer t = new timer; //with cj_typesEx.j library
}
JASP proposes even more simple variant of declaration:
function someFunc takes nothing returns nothing
	new timer t
endfunction
After parsing this will become:
function someFunc takes nothing returns nothing
	local timer t = CreateTimer()
endfunction

Warning!

The declaration of variables like that is supported only for this types:
timer
group
force
region
trigger
dialog
leaderboard
multiboard
quest
texttag
camerasetup
hashtable

Multiple local variable declaration

JASP proposes to you the multiple local variable declaration. For example, this code:
function someFunc takes nothing returns nothing
	new timer t, group g, force f, hashtable h
endfunction
will transform to this:
function someFunc takes nothing returns nothing
	local timer t = CreateTimer()
	local group g = CreateGroup()
	local force f = CreateForce()
endfunction
But the declaration of local variables of the same type must be like that:
function someFunc takes nothing returns nothing
	new timer t, timer f, timer c
endfunction

Global variable declaration

In vJass global variable declaration was possible only in the separate block:
globals
	hashtable hash = InitHashtable()
endglobals
JASP proposes the single global variable declaration directly in function code. For example, the main block of global variables and our function:
globals
	//WE globals
endglobals

function someFunc takes nothing returns nothing
	global hashtable hash = InitHashtable()
endfunction
after parsing will become that:
globals
	//WE globals
	hashtable hash = InitHashtable()
endglobals

function someFunc takes nothing returns nothing
endfunction
Also there is possible global variable declaration with initialization of their type (as in local variables):
globals
	//WE globals
endglobals

function someFunc takes nothing returns nothing
	new global hashtable hash
endfunction
after parsing:
globals
	//WE globals
	hashtable hash = InitHashtable()
endglobals

function someFunc takes nothing returns nothing
endfunction

Multiple global variable declaration

With the help of JASP you can declare multiple global variables in the function code:
globals
	//WE globals
endglobals

function someFunc takes nothing returns nothing
	new global hashtable hash, force Team, timer Timer
endfunction
after parsing becomes:
globals
	//WE globals
	hashtable hash = InitHashtable()
	force Team = CreateForce()
	timer Timer = CreateTimer()
endglobals

function someFunc takes nothing returns nothing
endfunction

Object destruction

JASP proposes the possibility of easy destruction of this types:
timer
group
force
boolexpr
conditionfunc
defeatcondition
effect
filterfunc
fogmodifier
image
itempool
leaderboard
lightning
multiboard
quest
texttag
timerdialog
trigger
ubersplat
unitpool
dialog
destructable
item
location
rect
region
unit
hashtable
To destroy the object, you must use the short expression free
function someFunc takes nothing returns nothing
	new timer t
	//Function code
	free t
	set t = null
endfunction
After parsing this will become:
function someFunc takes nothing returns nothing
	local timer t = CreateTimer()
	//Function code
	call DestroyTimer(t)
	set t = null
endfunction
Also you can destroy multiple types. So, this:
function someFunc takes nothing returns nothing
	new timer t, group g
	//Function code
	free t, g
	set t = null
	set g = null
endfunction
Will be parsed to:
function someFunc takes nothing returns nothing
	local timer t = CreateTimer()
	local group g = CreateGroup()
	//Function code
	call DestroyTimer(t)
	call DestroyGroup(g)
	set t = null
	set g = null
endfunction

Nulling variables

cJass allowed to null the potentially leaking things with flush locals. JASP gives more short variant:
function someFunc takes nothing returns nothing
	new timer t
	//Function code
	free t
	flush t
endfunction
That will, as you can expect, be parsed to this:
function someFunc takes nothing returns nothing
	local timer t = CreateTimer()
	//Function code
	call DestroyTimer(t)
	set t = null
endfunction
And, like the operatiors new 蠼b>free, flush also supports multiple elements:
function someFunc takes nothing returns nothing
	new timer t, group g
	//Function code
	free t, g
	flush t, g
endfunction
This will be parsed to:
function someFunc takes nothing returns nothing
	local timer t = CreateTimer()
	local group g = CreateGroup()
	//Function code
	call DestroyTimer(t)
	call DestroyGroup(g)
	set t = null
	set g = null
endfunction

Loops 'repeat until'

JASP grants an ability to use loops repeat until that are executing until the condition is true:
function someFunc takes nothing returns nothing
	local unit target
	new group g
	call GroupEnumUnitsInRange(g, 1024., 1024., 300., null)
	repeat
		set target = FirstOfGroup(g)
		call KillUnit(target)
		call GroupRemoveUnit(g, target)
	until (target == null)
	free g
	flush g
endfunction
This will be parsed to:
function someFunc takes nothing returns nothing
	local unit target;
	local group g = CreateGroup()
	call GroupEnumUnitsInRange(g, 1024., 1024., 300., null)
	loop
		set target = FirstOfGroup(g)
		call KillUnit(target)
		call GroupRemoveUnit(g, target)
	exitwhen (target == null)
	endloop
	call DestroyGroup(g)
	set g = null
endfunction

Untypified variables

Using JASP you can declare variables without typifying them - this parser will determine the type depending on variable's value. For example:
function someFunc takes nothing returns nothing
	var i = 0
	var b = false
	var r = .15
	var s = "test"
	var i2 = 'Amrf'
endfunction
This will be parsed to this:
function someFunc takes nothing returns nothing
	local integer i = 0
	local boolean b = false
	local real r = .15
	local string s = "test"
	local integer i2 = 'Amrf'
endfunction
Parser can determine the default values of native constants and functions and analyze custom functions and methods (if you're using vJass):
function someFunc takes nothing returns nothing
	var caster = GetTriggerUnit()
	var dummy = CreateUnit(...)
	var state = UNIT_STATE_LIFE
endfunction
This will, as expected, be parsed to that:
function someFunc takes nothing returns nothing
	local unit caster = GetTriggerUnit()
	local unit dummy = CreateUnit(...)
	local integer state = UNIT_STATE_LIFE
endfunction

Also JASP grants an opportunity for user to declare the variable without any value but with the condition that its value will be somewhere in this function. Quite misunderstandable, so I'll give an example:
function someFunc takes nothing returns nothing
	var target
	call GroupEnumUnitsInRange(temp, x, y, 300. null)
	repeat
		set target = FirstOfGroup(temp)
		//Actions
		call GroupRemoveUnit(temp, target)
	until target == null
endfunction
This will, as expected, be parsed to that:
function someFunc takes nothing returns nothing
	local unit target
	call GroupEnumUnitsInRange(temp, x, y, 300. null)
	loop
		set target = FirstOfGroup(temp)
		//Actions
		call GroupRemoveUnit(temp, target)
	exitwhen (target == null)
	endloop
endfunction

Using JASP you can declare many variables with values, parser will convert them to the variables with the type needed (don't work with variables with thevalues equal to functions or methods). Example:
function someFunc takes nothing returns nothing
	var i = 0, r = .15, s = "test", b = false //Do this
	var e = AddSpecialEffect(...), u = CreateUnit(...) //Don't do this
endfunction
If the value of variable will be null it will be typified as handle.

Credits

Simplar aka [DUOS] aka bowser499 - Taught me how to code in Jass, gave useful advices, translated this manual and kept with me in all the situations. If I say in one word, he is my native soul.
SirNikolas - gave a huge amount of useful information and advices. Very good man and a friend of mine :3
Borland Company - for the Borland Delphi 2005 that made the creation of JASP possible.
Shadow Flare - For SFMPQ library.