Haxe: Replacing NME/Browser (Jeash)

If you are working with HaxeNME, you might have noticed that compiled JS/HTML5 applications do not necessary work same as other platforms. Or don't work at all. Or don't compile because of some uncommon unimplemented method that you've used.
Reasons of such behaviour are even somewhat understandable - process of recreating Flash API on JavaScript+HTML5 isn't exactly an easy task, especially since multiple features do not exist in both of two in the same way or do not exist in second at all, meaning that implementation may require a trick or two to work.
And as code base is accumulating "tricks" by multiple contributors, it does not necessarily remain entirely stable.
For example, if you've decided to clear your BitmapData-based 640x480 buffer via BitmapData.fillRect, you are making a huge mistake - the function is not just doing this pixel-by-pixel, but also via ImageData API.
Overall, this article is dedicated to substituting Browser/Jeash part of NME by your own library in JS compilation.

Continue reading

Vector: Haxe icon

Haxe vector icon

Recently I was searching for at least relatively high-definition icon for Haxe (programming language), and found that there ... just isn't one. The best I could find was icon used on someone's blog, and that had white seams at shape intersections (suggesting anti-aliasing problems).
So I've made one.

The whole icon (after a few manual optimizations) is 1108 bytes, is in SVG format, and seems to meet proportions of original perfectly.
Also sections of icon are made to partially overlap "behind the scenes" to avoid earlier mentioned white seams on shape boundaries.

Download PNG Download SVG

Alternatively, if download links are not working, here's SVG code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"
	width="128px" height="128px"
	viewBox="0 0 128 128" xml:space="preserve">
	<rect fill="#f7941e" width="96" height="96" x="16" y="16"/>
	<polygon fill="#fdb813" points="0,0 4,32 16,64 64,16 32,4"/>
	<polygon fill="#faa61a" points="0,128 32,124 64,112 16,64 4,96"/>
	<polygon fill="#f36f21" points="128,128 124,96 112,64 64,112 96,124"/>
	<polygon fill="#f58220" points="128,0 96,4 64,16 112,64 124,32"/>
	<polygon fill="#ffcb08" points="0,0 64,16 32,0"/>
	<polygon fill="#fff200" points="0,0 0,32 16,64"/>
	<polygon fill="#fff200" points="0,128 16,64 0,96"/>
	<polygon fill="#f4813c" points="0,128 32,128 64,112"/>
	<polygon fill="#f7941e" points="128,128 64,112 96,128"/>
	<polygon fill="#f15922" points="128,128 128,96 112,64"/>
	<polygon fill="#f15922" points="128,0 112,64 128,32"/>
	<polygon fill="#ffcb08" points="128,0 96,0 64,16"/>

Haxe: Neko Server-client communication example (chat)

Recently I've been searching for examples of client-server communication in Haxe, however could not find anything specific. After some search and asking around, I was pointed to sys.net.Socket class, but the actual means of usage remained unclear. It was also confirmed to mirror POSIX socket functionality. Indeed it does that, though, given that Haxe implementation uses exceptions rather than return values, usage remained uneasy.

After some experimenting, I've figured a semi-simple way of using "blocking" sockets.

Continue reading

Love2d: Haxe: Ray-circle intersection test

HaxeNME version. Love2d version works equally to this.
Click and drag different parts for interaction.

By user request on Love2d IRC channel, yesterday I've made this nice function to do intersection/collision check between a ray (for clearance, here, a ray is a infinite line with starting point but no end point) and a circle.
Underlying code is fairly simple, though it does not even require understanding to use the function.
Love2d version takes advantage of multi-return values.
Haxe version has slightly longer code due for more optimal implementation of interface.

Download Haxe .hx
Download Love2d .love

Notepad++: Haxe syntax highlighting

Definition file in action, displaying syntax for function of fancy purpose.

In past few days I've spent some time to update an existing user definition file to UDL2, which was introduced in Notepad++ v6.2.

UDL2 improves possibilities of creating user defined languages slightly, introducing configurable delimiters, non-symbol operators, foldable comments, and other things.

For the case of Haxe, UDL2 improves detection of symbols, and made it possible to include hexadecimal number declarations, and separate highlighting for regular expressions. A thing that is currently missing out is preprocessor instructions (#if, #else, #end, ...), however, due to nature of these, highlighting is not always needed anyway.


Update: Someone has set up a repository with a more up-to-date version of the UDL file, so you should take a look at that as well.

Alternatively, UDL .xml' contents:

    <UserLang name="Haxe" ext="hx" udlVersion="2.0">
            <Global caseIgnored="no" allowFoldOfComments="yes" forceLineCommentsAtBOL="no" foldCompact="no" />
            <Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
            <Keywords name="Comments" id="0">00// 01 02 03/* 04*/</Keywords>
            <Keywords name="Numbers, additional" id="1"></Keywords>
            <Keywords name="Numbers, prefixes" id="2">0x</Keywords>
            <Keywords name="Numbers, extras with prefixes" id="3">a b c d e f A B C D E F</Keywords>
            <Keywords name="Numbers, suffixes" id="4"></Keywords>
            <Keywords name="Operators1" id="5">&apos; - ! &quot; $ &amp; ( ) , . : ; ? @ [ ] ^ ` | + &lt; = &gt; ~</Keywords>
            <Keywords name="Operators2" id="6"></Keywords>
            <Keywords name="Folders in code1, open" id="7">{</Keywords>
            <Keywords name="Folders in code1, middle" id="8"></Keywords>
            <Keywords name="Folders in code1, close" id="9">}</Keywords>
            <Keywords name="Folders in code2, open" id="10"></Keywords>
            <Keywords name="Folders in code2, middle" id="11"></Keywords>
            <Keywords name="Folders in code2, close" id="12"></Keywords>
            <Keywords name="Folders in comment, open" id="13">//{</Keywords>
            <Keywords name="Folders in comment, middle" id="14"></Keywords>
            <Keywords name="Folders in comment, close" id="15">//}</Keywords>
            <Keywords name="Keywords1" id="16">break callback case catch class continue default do else enum extends for function if implements import in interface new package return switch throw try typedef using var while</Keywords>
            <Keywords name="Keywords2" id="17">null true false</Keywords>
            <Keywords name="Keywords3" id="18">Void Int Float Dynamic Bool UInt Iterator Array List Hash IntHash Date String Xml</Keywords>
            <Keywords name="Keywords4" id="19">dynamic extern inline override private public static untyped cast trace super this arguments</Keywords>
            <Keywords name="Keywords5" id="20"></Keywords>
            <Keywords name="Keywords6" id="21"></Keywords>
            <Keywords name="Keywords7" id="22"></Keywords>
            <Keywords name="Keywords8" id="23"></Keywords>
            <Keywords name="Delimiters" id="24">00&apos; 01\ 02&apos; 03&quot; 04\ 05&quot; 06~/ 07\ 08/ 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
            <WordsStyle name="DEFAULT" styleID="0" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="COMMENTS" styleID="1" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="LINE COMMENTS" styleID="2" fgColor="008000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="NUMBERS" styleID="3" fgColor="FA3232" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS1" styleID="4" fgColor="0000FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS2" styleID="5" fgColor="004080" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS3" styleID="6" fgColor="0080AA" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS4" styleID="7" fgColor="0064FF" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS5" styleID="8" fgColor="FF8040" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS6" styleID="9" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS7" styleID="10" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="KEYWORDS8" styleID="11" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="OPERATORS" styleID="12" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="FOLDER IN CODE1" styleID="13" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="FOLDER IN CODE2" styleID="14" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="FOLDER IN COMMENT" styleID="15" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS1" styleID="16" fgColor="A31515" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS2" styleID="17" fgColor="A31515" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS3" styleID="18" fgColor="7049B6" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS4" styleID="19" fgColor="000080" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS5" styleID="20" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS6" styleID="21" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS7" styleID="22" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
            <WordsStyle name="DELIMITERS8" styleID="23" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />