Hi all, this is quiet a silly little trick and its more or less a bit of laziness.
Here is the library, I'm not even going to bother spoilering it, because well there is no code involved.
You can now declare int types. You can then use int in places where integer might be used, and visa versa. But more importantly, you can now attach methods to int. So you might want to go and give yourself a toString method.
You can now treat the int as a first class object, and go myInt.toString()
One caveat, you can no longer use < or > against native integers. You can define < method so that you can compare against other ints, but that won't help you against say 7.This is pretty annoying, but == and <= work. And it isn't hard to switch around usage (shift the target +1 or -1).
Is this useless, probably, but its just a fun little abuse.
Anyway here is just an example code section
This code inlines cleanly::
Here is the library, I'm not even going to bother spoilering it, because well there is no code involved.
JASS:
library int
{
public struct int[]
{
}
}
You can now declare int types. You can then use int in places where integer might be used, and visa versa. But more importantly, you can now attach methods to int. So you might want to go and give yourself a toString method.
You can now treat the int as a first class object, and go myInt.toString()
One caveat, you can no longer use < or > against native integers. You can define < method so that you can compare against other ints, but that won't help you against say 7.This is pretty annoying, but == and <= work. And it isn't hard to switch around usage (shift the target +1 or -1).
Is this useless, probably, but its just a fun little abuse.
Anyway here is just an example code section
This code inlines cleanly::
JASS:
// okay so there are lots of extra parens, but I doubt that hurts anything.
function int__onInit takes nothing returns nothing
local integer x=7
local integer y=6
set x=x + 3
if ( x <= 34 ) then
if ( (((y)) < ((x))) ) then // INLINED!!
call BJDebugMsg((I2S((x)))) // INLINED!!
endif
endif
endfunction