Home » Flash相关 » Haxe » 解锁新技能:将Haxe代码编译成swc库文件

解锁新技能:将Haxe代码编译成swc库文件

有不少的牛逼的算法和神奇魔法,是采用Haxe写的。比如比较知名的ds(全称:AS3 Data Structures For Game Developers)。来自德国的这个lib刚开始是采用AS3写的,后来作者就改用Haxe语言。作者这样迁移语种,是可以理解的。对于这种算法型的代码,还是比较适合用Haxe来写的。因为它可以很方便的编译成其语言(Java,C++,AS3,Python,NodeJS,PHP等)里面有许多非常有用的数据结构,还是比较有用的。

ds

最近,在整理A星算法,从一个老外的Demo里破解了算法的源码,但是算法中引用到ds库中一些数据结构,比如:IntHashTable ,IntHashSet , PriorityQueue等。所以我不得不去找这个库AS3版本。当然结果是,只能找到Haxe版本。

SO,接下来,我们的课题是:如何将Haxe代码编译成swc库文件,以便在As3代码中进行调用。

第一步:安装Haxe

前往官网下载最新版的Haxe ,找到windows已经编译的安装版本 :http://haxe.org/download

像傻瓜一样点击“下一步”,然后“完成”即可。

第二步:安装ds库

打开一个命令行工具(CMD或者powerShell),敲入下面的命令,就可以从远程服务器下载并安装ds库了。

$ haxelib install polygonal-ds

第三步:编写编译参数和命令文件 compile.hxml

其实就是,新建个记事本文件,重命名为compile.hxml . 然后复制一下内容,保存,然后双击运行,然后bin/ds-release.swc就出来了。

-swf-version 10
--macro include("de")
--macro exclude('Includes')
--macro addMetadata('@:native("hx.Hash")', 'Hash')
--macro addMetadata('@:native("hx.List")', 'List')
--macro addMetadata('@:native("hx.IntHash")', 'IntHash')
--macro addMetadata('@:native("hx.IntIter")', 'IntIter')
--macro addMetadata('@:native("hx.Void")', 'Void')
--macro addMetadata('@:native("hx.Xml")', 'Xml')
--macro addMetadata('@:native("hx.ValueType")', 'ValueType')
--macro addMetadata('@:native("hx.StringTools")', 'StringTools')
--macro addMetadata('@:native("hx.StringBuf")', 'StringBuf')
--macro addMetadata('@:native("hx.Std")', 'Std')
--macro addMetadata('@:native("hx.Reflect")', 'Reflect')
--macro addMetadata('@:native("hx.Lambda")', 'Lambda')
--macro addMetadata('@:native("hx.EReg")', 'EReg')
--macro addMetadata('@:native("hx.Dynamic")', 'Dynamic')
--macro addMetadata('@:native("hx.Type")', 'Type')
--macro addMetadata('@:native("hx.Int32")', 'haxe.Int32')
--macro addMetadata('@:native("hx.Int64")', 'haxe.Int64')
--macro addMetadata('@:native("hx.io.Bytes")', 'haxe.io.Bytes')
--macro addMetadata('@:native("hx.io.BytesBuffer")', 'haxe.io.BytesBuffer')
--macro addMetadata('@:native("hx.io.BytesInput")', 'haxe.io.BytesInput')
--macro addMetadata('@:native("hx.io.BytesOutput")', 'haxe.io.BytesOutput')
--macro addMetadata('@:native("hx.io.Eof")', 'haxe.io.Eof')
--macro addMetadata('@:native("hx.io.Error")', 'haxe.io.Error')
--macro addMetadata('@:native("hx.io.Input")', 'haxe.io.Input')
--macro addMetadata('@:native("hx.io.Output")', 'haxe.io.Output')
--no-traces
-lib polygonal-printf
Lambda
--each
-swf bin/ds-release.swc
    分享到: