`
hereson
  • 浏览: 1426516 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

haxe, haxelib, nekotools 三个命令

    博客分类:
  • haxe
阅读更多
layout title date categories
post
各种命令及参数(包含库管理)
2014-03-30 14:10:10 -0700
haxe

主要描述 haxe, haxelib, nekotools 三个命令, haxe 命令行会经常在 .hxml 文件中用到

haxedoc

haxedoc 命令已经被弃用,而改用了另一个叫haxelib dox, 但是 生成 xml 还是用的 haxe -xml 命令

haxelib

http://lib.haxe.org/

haxelib 用于管理 haxe库, haxelib run libname 可以调用指定库下边的 run.n 文件, 并将当前命令行路径作为最后一个参数传递.

以 haxelib run 运行的命令, 内部的 Sys.getCwd() 将返回 libname 所在的绝对路径,而不是调用的当前路径, 当前路径为 args 最后一个参数

而以 neko run.n 调用的命令 内部的 Sys.getCwd() 将则指向当前路径.

那么问题是如何区分应用是以 haxelib run %libname% 运行的还是以 neko %APP% 运行的??? 似乎没有办法

  • 当一个 haxelib 有 ndll 目录时, haxelib path libname 会有一个 -L 的定义指向这个 ndll 目录.

  • 命令行下只输入 haxelib 将显示一些帮助信息.

  • 命令行, 注: 很多命令是交互式的, 会提示你如何操作

    Haxe Library Manager 3.2.0-rc.1 - (c)2006-2015 Haxe Foundation
      Usage: haxelib [command] [options]
      Basic
        install   : 在线安装指定库, 或 hxml 文件中的所有库
        upgrade   : 在线更新所以已经安装了的库
        update    : 在线更新指定库
        remove    : 移除指定库(从磁盘上删除 haxelib 根目录中的库,但不会删除外部的 dev 库)
        list      : 列出指定库或名称相匹配的库(如果指定参数)
        set       : 设定库的版本, 用于多个版本库的选择, 注意:如果通过 haxelib dev 指定了开发版本, 那么 dev 版本仍优先于指定的版本号
    
        # https://github.com/HaxeFoundation/hxcpp/issues/143
        # haxe 3.2 new 和 delete 已经更名为 newrepo 以及 deleterepo
        new       : 创建新的本地仓库, 将在当前目前创建一个 .haxelib 的目录, 当位于这个目录上时, haxelib 的所有操作将指向这个新建的目录
        delete    : 删除 new 创建的本地仓库(将从磁盘中), 
    
      Information
        search    : 在线搜询名称相关库, 
        info      : 在线列出指定库的详细信息, 全名匹配, 例: haxelib info lime
        user      : 列出指定用户的信息及这个用户提交的所有 haxe 库. 
        config    : 打印 haxelib 仓库所在目录(绝对路径)
        path      : 得到指定库的所在路径(绝对路径), 库的版本信息, 及 ndll 库目录(如果有的话)
        version   : 当前 haxelib 自身版本
        help      : 显示可选列表
    
      Development
        submit    : 提交或更新自已写的 haxe 库到 haxelib 服务器
        register  : 注册 haxelib 新用户
        local     : 离线方式安装库, 压缩包名字随意. 例: haxelib local xxx.zip
        dev       : 设置指定目录为库, 常用于 fork 别人的库 例: haxelib dev openfl fork_openfl_dir
        git       : 连接下载 git 版本库, 需要 git 命令支持
    
      Miscellaneous
        setup     : 设置 haxelib 仓库路径(默认为 haxe 根目录的 lib)
    
        # 估计就是上边的被移除了的 new 和 delete
        newrepo   : [EXPERIMENTAL] create a new local repository
        deleterepo: delete the local repository
    
        selfupdate: 更新 haxelib 自身
        convertxml: 转换 haxelib.xml 文件为 haxelib.json
        run       : 运行指定类库下的 run.n 文件
        proxy     : 设置 Http 代理.
    
      Available switches
        --flat    : do not use --recursive cloning for git
        --always  : answer all questions with yes
        --debug   : run in debug mode
        --never   : answer all questions with no
        --global  : force global repo if a local one exists 
    
    ============== 一些常用命令 ==============
    
    haxelib info lime #在线查询列出关于 lime 库的信息
    
    haxelib list  # 列出本地所有安装包,用`[]` 中适号包含着的为当前所使用版本
    
    haxelib list li   #列出本地包含 li 字符的库有哪些,其一些其它信息
    
    haxelib install haxepunk #在线安装名为 haxepunk 的库
    
    haxelib local some.zip  #安装已经下载到硬盘上的库,通常用为 zip 格式, zip文件名随意
    
    haxelib update stablexui #在线更新名为 stablexui 的库
    
    haxelib upgrade #连网检测所有本地库是否存在更新,并提示是否更新
    
    #下边命令是指定一个库的开发目录
    #当你修改 某一个库的源码时,可以先复制一份到其它目录
    #然后用 haxelib dev 指定使用这个目录的文件作为开发
    haxelib dev libname directory_name 
    
    haxelib dev haxeui G:\dev-haxeui # 以后调用 haxeui 库时将使用 G:\dev-haxeui 下的文件
    # haxelib list haxeui 可以显示 haxeui 信息,是否使用了 dev 
    haxelib dev haxeui #不带目录名 从dev模式中切换回来
    
    haxelib selfupdate # 更新 haxelib 自已
    
    haxelib remove libname #删除库,这个库将会从磁盘移除
    
    haxelib run libname #运行 libname库目录下 编译为neko平台的 run.n 文件     
  • 开发并上传库 见:haxe.org/com/haxelib

一些库通过 haxelib.json 文件的 dependencies 可能指定了依赖库版本,这使得 dev 版本会被认为是旧的版本,因此对于 git 库可能需要以 haxe git 的方式安装.

hxml

hxml 就是将命令行下输入的 haxe 命令的文件形式, 需要注意的是 有一个特殊的叫 extraParams.hxml 的文件, 这个文件一般在一些 haxelib 中可以见到(和 haxelib.json 位于同级目录), 用于当使用 -lib libname 编译时附加一些编译参数. 如果是基于 openfl 的项目库,那么这个特殊文件将是 include.xml

hxml 的内容为 haxe --help 中的命令. 注释用 # 符号.简单示例:

# 这个符号后接的为注释内容 
--macro Sys.println('Begin...')
-cp src
-lib format
-main Main
-js main.js

nekotools

nekotools 是一个安装 haxe 时附带的工具,nekotools 很简单只有二个命令

  • nekotools server 建立一个 web 服务器,可以用于 http 服务,这样可以不再依赖 apache 或 nigix

    nekotools server 不仅仅能将 html 输出到浏览器,还能处理 neko 文件并输出.

    #做网页相关的东西时,很多功能需要以 http 的形式访问才能正常.
    #不带参数快速绑定当前目录到 localhost:2000
    nekotools server
    
    # 绑定 d:\dev 目录到 0.0.0.0:80
    nekotools server -p 80 -h 0.0.0.0 -d d:\dev
  • nekotools boot 将 neko平台的 .n 文件转换成独立的 exe 文件

    转换成的 exe 文件,需要 neko 环境才能运行(安装了haxe), 如果没有, 可以复制 neko 所需要的 dll 文件和 exe 文件放同一目录就行了.

haxe

Haxe Compiler 3.2.0 - (C)2005-2015 Haxe Foundation
 Usage : haxe.exe -main <class> [-swf|-js|-neko|-php|-cpp|-as3] <output> [options]
 Options :

# 添加源码目录, 通常我们习惯将源码放置于 src 目录下, 所以能经常看到 -cp src
-cp <path>      : add a directory to find source files

# 编译代码为 javascript 平台的 .js 文件
-js <file>      : compile code to JavaScript file

# 编译代码为 flash 平台的 .swf 文件
-swf <file>     : compile code to Flash SWF file

# 解析代码为 flash 平台的 .as3 源码, 指定输出目录 
-as3 <directory>    : generate AS3 code into target directory

# 编译代码为 neko 平台的 .n 文件
-neko <file>        : compile code to Neko Binary

# 编译代码为 php 平台的 .php 文件, 指定输出目录
-php <directory>    : generate PHP code into target directory

# 编译代码为 c++ 平台的 .cpp 文件, 指定输出目录, 
# 第一次编译时可能会花上一段时间, Tips: 可以编译成 neko 平台用于快速测试.
-cpp <directory>    : generate C++ code into target directory

# 编译代码为 c# 平台的 .cs 文件, 指定输出目录, 需要安装 hxcs 库
-cs <directory>     : generate C# code into target directory

# 编译代码为 java 平台的 .java 文件, 指定输出目录, 需要安装 hxjava 库
-java <directory>   : generate Java code into target directory

# haxe 3.2 + 编译代码为 python 
-python <file>      : generate Python code as target file

# 导出代码API注释内容为 xml 文件
-xml <file> : generate XML types description

# 指定入口文件
-main <class> : select startup class

# 使用 haxelib, 允许指定库版本
-lib <library[:version]> : use a haxelib library

# 编译定义, 用于定义条件编译参数
-D <var> : define a conditional compilation flag

# 详细显示编译过程  
-v : turn on verbose mode

# debug 模式, 通常会添加一些 debug 信息到编译结果
-debug : add debug information to the compiled code

# 编译时清除没有使用的代码,以减少输出文件体积. 
-dce [std|full|no] : set the dead code elimination mode

# 指定 flash 版本, 例: -swf-version 10.3, 或 -swf-version 11.6
-swf-version <version> : change the SWF version (6 to 10)

# 指定 flash 文件头, 例: -swf-header 800:600:30:FFFFFF
-swf-header <header> : define SWF header (width:height:fps:color)

# 添加 swf 库, 文件通常为 swc 格式
-swf-lib <file> : add the SWF library to the compiled SWF

# 参见英文描述
-swf-lib-extern <file> : use the SWF library for type checking

-java-lib <file> : add an external JAR or class directory library   

-net-lib <file>[@std] : add an external .NET DLL file

-net-std <file> : add a root std .NET DLL search path

-c-arg <arg> : pass option <arg> to the native Java/C# compiler

-x <file> : shortcut for compiling and executing a neko file

# 添加资源文件, 例: -resource path/hello.txt@hello
-resource <file>[@name] : add a named resource file

# 提示错误
-prompt : prompt on error

# 通常放在最后用于编译成功之后执行外部命令, 例: --next -cmd dir
-cmd : run the specified command after successful compilation

# flash平台, 更严格的类型检测
--flash-strict : more type strict flash API

# 编译时忽略所有 trace 语句
--no-traces : do not compile trace calls in the program

# 解析 flash 的 swf/swc 库并自动生成 extern class, 感觉是一个自动写 extern class 的工具, 只能用于 flash.
# 既然 haxe 能直接使用 swc 库, 个人感觉 就已经不需要 extern class 类了.也就是说 --gen-hx-classes 多余了.
# 示例: haxe -swf empty.swf --no-output -swf-lib some.swc --gen-hx-classes
--gen-hx-classes : generate hx headers for all input classes

# 分隔 haxe 编译, hxml 文件中经常能见到
--next      : separate several haxe compilations

# 用于 单个hxml文件(或单条CLI命令)的多目标编译, 在 --each 之前的参数将用于所有 --next
--each

# 这个命令是给 (代码编辑器)IDE 用的, 用于给 IDE 提供 语法智能提示
# http://ncannasse.fr/blog/haxe_completion?lang=en
--display   : display code tips

# 编译但是不输出, 通常用于测试是否能通过编译, 或 导出 API 注释文档(haxe -xml)时用到
--no-output : compiles but does not generate any file

# 显示 编译所花费的时间
--times     : measure compilation times

# 停用 inline 关键字, inline 关键字将被忽略
--no-inline : disable inlining

# 停用代码优化
--no-opt    : disable code optimizations

# 设置主文件名, 默认为: index.php
--php-front <filename>  : select the name for the php front file

# 设置库文件夹名, 文件夹名默认为: lib
--php-lib <filename>    : select the name for the php lib folder

# 为所有类添加字符前缀
--php-prefix <name>     : prefix all classes with given name

# 映射 package 到 target. 相当于 为 target 取一个别名 package. 例: --remap flash:openfl
--remap <package:target> : remap a package to another one

# 使用内部宏系统执行, 当不需要指定输出时,
# 参看下边 --eval 的示例, 如果不加 --interp 将不会有显示..
--interp    : interpret the program using internal macro system

# 调用 macro 命令, 默认为 macro.Compiler 下的 宏(macro)方法, --macro keep("SomeClass")
# 但其实可以是任意方法,例如: --macro Sys.println("Hello World!")
# 或者像这样: haxe -cp src --macro Main.main()
--macro     : call the given macro before typing anything else

# [隐藏]大概是被 --macro 取代了的命令. 是直接运行指定的文件类, 相当于 --macro Main.main()
--run       : 直接运行指定的类, 以 neko 平台.

# 运行代码. https://github.com/HaxeFoundation/haxe/pull/3309
# 就像是 js 里边的 eval("code"), 例如: 可以复制示例粘贴到 CMD中去
# haxe --eval "class Foo{static public function main(){Sys.print('Hello world!');}}" --interp
--eval      : evaluates argument as Haxe module code 

# 绑定当前工作目录到 host:port, 用于缓存编译, 适用于大型项目, 减少编译时间, 参看下边示例
--wait <[host:]port> : wait on the given port for commands to run)

# 连接端口, 使用缓存编译, 如果文件未发生改动, 参看下边示例
--connect <[host:]port> : connect on the given port and run commands there)

# 设置当前工作目录, 这个命令会影响到 缓存编译的 --wait 和 --connect
--cwd <dir> : set current working directory

# 仅仅显示 haxe 当前版本
-version : print version and exit

# 显示 haxe 定义(defines) 清单
--help-defines : print help for all compiler specific defines

# 显示 haxe 元标记(metas) 清单
--help-metas : print help for all compiler metadatas

-help  Display this list of options
--help  Display this list of options

defines

haxe --help-defines. 使用 -D 设定, 一些和上边重叠的不会再描述. 例如 haxe -dce full  haxe -D dce=full 将产生一样的效果.

注意: 如果你想在 条件编译 或 宏代码 中访问这些定义,应该将 减号(-)替换成 下划线(_)

# 在 trace 语句中 打印绝对路径
absolute-path          : Print absolute file path in trace output

# 添加 Scout (aka Monocle) 支持. Since SVN r5429
advanced-telemetry     : Allow the SWF to be measured with Monocle tool

# 代码优化器, 以精简代码,
analyzer               : Use static analyzer for optimization (experimental)

as3                    : Defined when outputing flash9 as3 source code

check-xml-proxy        : Check the used fields of the xml proxy

core-api               : Defined in the core api context

core-api-serialize     : Sets so some generated core api classes be marked 
                         with the Serializable attribute on C#

cppia                  : Generate experimental cpp instruction assembly

dce                    : The current DCE mode

dce-debug              : Show DCE log

debug                  : Activated when compiling with -debug

# 用来给 IDE 提供语法提示用的., 也就是说 #if display #end 之间的内容是提供给 代码编辑器 用来做一些语法智能提示.
display                : Activated during completion

dll-export             : GenCPP experimental linking

dll-import             : GenCPP experimental linking

# 用于导出代码注释为API文档, 为了正确生成文档不会执行任何改动或删除
doc-gen                : Do not perform any removal/change in order to correctly generate documentation

# -D dump=pretty
dump                   : Dump the complete typed AST for internal debugging

dump-dependencies      : Dump the classes dependencies

dump-ignore-var-ids    : Dump files do not contain variable IDs (helps with
                          diff)

erase-generics         : Erase generic classes on C#

# 启用交互式调试的 Flash 内容。它在 SWF 输出中包含调试器标记,并添加额外的调试信息。这也将把 trace 输出重定向到 flashlog.txt, 而不是 swf 中的 Textfiled
fdb                    : Enable full flash debug infos for FDB interactive debugging

file-extension         : Output filename extension for cpp source code

# 更严格的类型检测, 反正加上就是
flash-strict           : More strict typing for flash target

# 示例参看 http://old.haxe.org/doc/flash/preloader
flash-use-stage        : Keep the SWF library initial stage. To be used together with -swf-lib. Place objects found on the stage of the SWF lib. (Not to be used together with -swf-header)

force-lib-check        : Force the compiler to check -net-lib and -java-lib 
                         added classes (internal)

force-native-property  : Tag all properties with :nativeProperty metadata for 
                         3.1 compatibility

format-warning         : Print a warning for each formated string, for 2.x compatibility

gencommon-debug        : GenCommon internal

# 使用 `haxe` 名, 作为 flash 的引导类名, 替换掉默认的 boot_xxx 名, 这项定义将会 自动用于编译成 swc 时
haxe-boot              : Given the name 'haxe' to the flash boot class instead of a generated name

# 显示 haxe 版本, 注意 在条件编译或宏代码中 需要以 haxe_ver 这种格式
haxe-ver               : The current Haxe version value

hxcpp-api-level        : Provided to allow compatibility between hxcpp versions

# 作用于 cpp 平台
include-prefix         : prepend path to generated include files

interp                 : The code is compiled to be run with --interp

java-ver               : <version:5-7> Sets the Java version to be targeted

js-classic             : Don not use a function wrapper and strict mode in JS output

# JS ES5 运行时模式
js-es5                 : Generate JS for ES5-compliant runtimes

js-unflatten           : Generate nested objects for packages and types

# 使用更少的对象属性构建类, 例如: 默认情况下会创建的类有时似于 Main.a.b.c   加这个属性后将为 Main_a_b_c 这样就降低了访问对象的深度
# [注] haxe 3.2 这个已经是默认属性了, 如果想换回以前的默认, 使用 js-unflatten
# js-flatten             : Generate classes to use fewer object property lookups

keep-old-output        : Keep old source files in the output directory (for C#/Java)

loop-unroll-max-cost   : Maximum cost (number of expressions * iterations)
                          before loop unrolling is canceled (default 250)

# 参看 haxe --help 中的 --macro
macro                  : Defined when we compile code in the macro context

macro-times            : Display per-macro timing when used with --times

# 仅仅只生成 .neko 源代码
neko-source            : Output neko source instead of bytecode

neko-v1                : Keep Neko 1.x compatibility

net-target             : <name> Sets the .NET target. Defaults to "net". xbox, micro (Micro Framework), compact (Compact Framework) are some valid values

net-ver                : <version:20-45> Sets the .NET version to be targeted

# 更改 flash 网络沙箱模式,  定义后将为 只访问网络, 默认为只访问本地
network-sandbox        : Use local network sandbox instead of local file access one

# 用于 cpp,java,c# 生成代码但是不编译.
no-compilation         : Disable CPP final compilation

no-copt                : Disable completion optimization (for debug purposes)

no-debug               : Remove all debug macros from cpp output

no-deprecation-warnings: Do not warn if fields annotated with @:deprecated are used

no-flash-override      : Change overrides on some basic classes into HX suffixed methods, flash only

no-inline              : Disable inlining

no-macro-cache         : Disable macro context caching

# 同 --no-opt
no-opt                 : Disable optimizations

no-pattern-matching    : Disable pattern matching

no-root                : GenCS internal

no-simplify            : Disable simplification filter

# 禁用 swf 压缩
no-swf-compress        : Disable SWF output compression

no-traces              : Disable all trace calls

php-prefix             : Compiled with --php-prefix

real-position          : Disables haxe source mapping when targetting C#

replace-files          : GenCommon internal

scriptable             : GenCPP internal

shallow-expose         : Expose types to surrounding scope of Haxe generated closure without writing to window object

source-map-content     : Include the hx sources as part of the JS source map

# haxe 保留定义, 用户不能定义这项. 因为当 -swf 文件扩展名为 swc时, 将自动定义这项
swc                    : Output a SWC instead of a SWF

swf-compress-level     : <level:1-9> Set the amount of compression for the SWF output

swf-debug-password     : Set a password for debugging.

# flash 硬件加速 第 1 级 - 直接
swf-direct-blit        : Use hardware acceleration to blit graphics

# flash 硬件加速 第 2 级 - GPU
swf-gpu                : Use GPU compositing features when drawing graphics

swf-mark               : GenSWF8 internal

# 嵌入元数据 xml文件到 swf,以便搜索引擎检索信息, 示例: -D swf-metadata=data.xml 
# 元数据 xml文件 格式参见 http://www.adobe.com/products/xmp.html
swf-metadata           : =<file> Include contents of <file> as metadata in the swf.

# 示例: http://old.haxe.org/doc/flash/preloader
swf-preloader-frame    : Insert empty first frame in swf

# 编译时将 private 属性将变成 protected 而不是 public
# 实际上 hx 中的 private 仅仅只用于限制 hx 代码, 生成 swf 后, 都为 public
swf-protected          : Compile Haxe private as protected in the SWF instead of public

# 设置 swf 超时时间
swf-script-timeout     : Maximum ActionScript processing time before script stuck dialog box displays (in seconds)

swf-use-doabc          : Use DoAbc swf-tag instead of DoAbcDefine

sys                    : Defined for all system platforms

unity-std-target       : Changes C# source location so that each generated C#
                         source is relative to the Haxe source location. If the 
                        location is outside the current directory, the value set
                        here will be used.

unsafe                 : Allow unsafe code when targeting C#

use-nekoc              : Use nekoc compiler instead of internal one

# 允许在编译时访问注释文档
use-rtti-doc           : Allows access to documentation during compilation

vcproj                 : GenCPP internal

metas

@:abi                : Function ABI/calling convention (cpp only)

@:abstract           : Sets the underlying class implementation as 'abstract' (for cs,java)

# 访问已经声明为 private 的包 类或字段.
@:access             : (Target path)Forces private access to package, type or field

# 允许声明的包访问当前包 类或字段
@:allow              : (Target path)Allows private access from package, type or field

# 优化配置? 文档 # 参数 https://github.com/HaxeFoundation/haxe/blob/development/analyzer.ml 第10行到20行为参数
# e.g: @:analyzer(no_simplification) , 注意没有引号的参数
# no_check 对应 check
# no_const_propagation 对应 const_propagation
# no_local_dce 对应 local_dce
# ignore
# no_simplification
# no_check_has_effect 对应 check_has_effect  
@:analyzer           : Used to configure the static analyzer

@:annotation         : Annotation (@interface) definitions on -java-lib imports will be annotated with this metadata. Has no effect on types compiled by Haxe (java only)

@:arrayAccess        : Allows [] access on an abstract

# 使用宏构建这个类的子类, 而非当前类
@:autoBuild          : (Build macro call)Extends @:build metadata to all extending and implementing classes

# 当在 Haxe 中声明了一个类(不是extern类)已经存在于 SWF 库, 将会报错. 用这个标记可以覆盖掉 SWF 库的声明.
@:bind               : Override Swf class declaration (flash only).

# 示例: @:bitmap("myfile.png|jpg|gif") class MyBitmapData extends flash.display.BitmapData {}
@:bitmap             : (Bitmap file path)Embeds given bitmap data into the class (must extend flash.display.BitmapData) (flash only)

@:bridgeProperties   : Creates native property bridges for all Haxe properties
                       in this class. (cs only)

# 使用宏构建这个类或枚举
@:build              : (Build macro call)Builds a class or enum from a macro

@:buildXml           :  (cpp only)

# 就是允许调用, 主要用于修复: https://github.com/HaxeFoundation/haxe/issues/3218
@:callable           : Abstract forwards call to its underlying type(since haxe 3.2)

@:classCode          : Used to inject platform-native code into a class (for cs,java)

# 用于 abstract 类型的运算符重载交换, 这个标签应该用于 static 属性的重载才会生效. 参见 @:op 
@:commutative        : Declares an abstract operator as commutative

@:compilerGenerated  : Marks a field as generated by the compiler. Should not be used by the end user (for cs,java)

# 标识该类为核心类, 被定义为核心的类将会与标准库中(std目录)声明的抽像核心类进行核对. 也就是说 必须实现抽像核心类所有字段.不可以添加字段
# coreApi 的类一般定义在各包的 _std 目录下.
@:coreApi            : Identifies this class as a core api class (forces Api check)

# 定义 abstract 核心类型 - 用于包装各平台底层数类型. 对于标记为 coreType 的 abstract 类型,是不需要定义原类型的
@:coreType           : Identifies an abstract as core type so that it requires no implementation

@:cppFileCode        : Code to be injected into generated cpp file (cpp only)

@:cppInclude         : File to be included in generated cpp file (cpp only)

@:cppNamespaceCode   :  (cpp only)

@:dce                : Forces dead code elimination even when not -dce full is specified

@:debug              : Forces debug information to be generated into the Swf even without -debug (flash only)

@:decl               :  (cpp only)

@:defParam           : ?

@:delegate           : Automatically added by -net-lib on delegates (cs only)

@:depend             :  (cpp only)

# 如果一个字段或类, 被添加这个标记, 编译器将在编译时输出警告信息
@:deprecated         : Automatically added by -java-lib on class fields annotated with @Deprecated annotation. Has no effect on types compiled by Haxe.(java only)

@:event              : Automatically added by -net-lib on events. Has no effect on types compiled by Haxe. (cs only)

# JS 将类导出到 window对象 下, 如果 window 未定义,则导出到 export对象(nodejs) 下
@:expose             : (?Name=Class path)Makes the class available on the window object (js only)

# 表明这个字段为 外部字段, 比如添加语法提示时可以用  
@:extern             : Marks the field as extern so it is not generated

# 作用于 enum, 参看 页尾的示例. 个人感觉 haxe 3.1 之后, 由于 enum 的改动,这个元标记似乎被弃用
@:fakeEnum           : (Type name)Treat enum as collection of values of the specified type

# 以二进制的形式嵌入 文件 到 swf 内, 例: @:file("a.dat") class MyByteArray extends flash.utils.ByteArray{}
@:file               : (File path)Includes a given binary file into the target Swf and associates it with the class (must extend flash.utils.ByteArray) (flash only)

# 防止类被扩展(extends)
@:final              : Prevents a class from being extended

# 嵌入字体文件. 仅支持 ttf 字体文件, 例: @:font("font/ceri0553.ttf", "a-zA-Z0-9~!@#$%^&*()_+=-][}{.,;\":><") class MyFont extends Font { }
@:font               : (TTF path,Range String)Embeds the given TrueType font into the class (must extend flash.text.Font)

# 用于 abstract 类型 - http://haxe.org/manual/types-abstract-forward.html
@:forward            : (List of field names)Forwards field access to underlying type

# 用于 abstract 类型 - http://haxe.org/manual/types-abstract-enum.html
@:enum               : By adding the :enum metadata to an abstract definition, that abstract can be used to define finite value sets:

# 用于定义 abstract 类, 这个方法必须为 static
@:from               : Specifies that the field of the abstract is a cast operation from the type identified in the function

@:functionCode       :  (cpp only)

@:functionTailCode   :  (cpp only)

# **常用**.当 new T()时, 需要添加这个标记  用于替换掉需要接口 haxe.rtti.Generic类,用于声明泛型类. (since 3.0.
@:generic            : Marks a class or class field as generic so each type parameter combination generates its own type/field

# http://haxe.org/manual/macro-generic-build.html
# 和 haxe.macro.MacroType 一样,参看 https://github.com/HaxeFoundation/haxe/commit/b7d9572cde3cab4629f4854103bcd56f3603d515
# 注意: 宏函数所返回的类型没有智能提示,你应该构建其它的类型,而不是修改带有 meta 的类.
@:genericBuild       : Builds instances of a type using the specified macro

# 参看 @:setter
@:getter             : (Class field name)Generates a native getter function on the given field (flash only)

@:hack               : Allows extending classes marked as @:final

@:headerClassCode    : Code to be injected into the generated class, in the header (cpp only))

@:headerCode         : Code to be injected into the generated header file (cpp only)

@:headerInclude      : File to be included in generated header file (cpp only)

@:headerNamespaceCode: (cpp only)

@:hxGen              : Annotates that an extern class was generated by Haxe (for cs,java)

# 如果 特性存在,则不会被 dce 清除
@:ifFeature          : (Feature name)Causes a field to be kept by DCE if the given feature is part of the compilation

@:include            :  (cpp only)

@:initPackage        : 用于 js 平台的 extern class, 用于将 包名 初使为 Object, 或者也可以使用 @:native 来更改输出的类名.

@:internal           : Generates the annotated field/class with 'internal' access (for cs,java)

# 如果你使用了这个标记, 通常是你的 getter,setter 写得不合规范化。因此学习正确的 getter/setter 方式.
@:isVar              : Forces a physical field to be generated for properties that otherwise would not require one

@:javaCanonical      : (Output type package,Output type name)Used by the Java
                        target to annotate the canonical path of the type (java only)

# nodejs 的 extern class 经常有 @:native("(require('fs'))"), 由于这样导出的代码不美观, haxe 3.2 将会有新的
# 例: @:jsRequire("fs") , 或加载子项 @:jsRequire("http", "Server") 相当于 js 的 require("http").Server
@:jsRequire 标记      : Generate javascript module require expression for given extern (js only)

# 防止被 dce 清除, 如果在一个 类 上使用, 将影响所有字段, 如果用于字段, 则仅影响当前字段.
@:keep               : Causes a field or type to be kept by DCE

# 即使类的所有字段都被 dce 清除,或本身就是一个空类, 都会保留这个空类
@:keepInit           : Causes a class to be kept by DCE even if all its field are removed

@:keepSub            : Extends @:keep metadata to all implementing and extending classes

@:macro              : (deprecated)

@:mergeBlock         : Merge the annotated block into the current scope

# 生成相应的 Flash 元数据, 例: @:meta(Event(name="test",type="Foo"))
@:meta               : Internally used to mark a class field as being the metadata field. (flash only)

@:multiType          : (Relevant type parameters)Specifies that an abstract chooses its this-type from its @:to functions

# 重写输出类或枚举的包名, 例: @:native("my.real.Cls"). 使它更容易绑定到 extern 类, 可能有不一样的名称.
# 示例 @:native("global") extern class Node {}, 这样在 Haxe 这边调用 Node 而其实输出端调用的是 global
# 但是这个在写字段用于成员字段时, @:native("a.b") 将变为 ["a.b"] 这种形式(只在JS中测试过)
@:native             : (Output type path)Rewrites the path of a class or enum during generation

@:nativeChildren     : Annotates that all children from a type should be
                       treated as if it were an extern definition - platform
                       native (for cs,java)

@:nativeGen          : Annotates that a type should be treated as if it were an extern definition - platform native (for cs,java)

@:nativeProperty     : Use native properties which will execute even with dynamic usage (cpp only)

# 作用是 代码编辑器(IDE) 将不会对这个字段产生智能提示. 好像只能作于于字段
@:noCompletion       : Prevents the compiler from suggesting completion on this field

# 即使有加编译参数 -debug,也不生成 debug 信息到 swf文件,仅适用于 flash
@:noDebug            : Does not generate debug information into the Swf even if -debug is set (flash only)

# 防止被文档生成器添加
@:noDoc              : Prevents a type from being included in documentation generation

# 防止静态字段,被 * 符号导入, 例 import some.*;
@:noImportGlobal     : Prevents a static field from being imported with import Class.*

@:noPrivateAccess    : Disallow private access to anything for the annotated expression

# 如果找到其第一个类型, 跨目标允许模块可以被访问. 例:如果目标为 flash, 那么就不可以访问 cpp 包下的类, 
# 另一个方法可以做同样的行为 如: --macro allowPackage("sys")
# 但是调用 --macro 很容易引起冲突
@:noPackageRestrict  : Allows a module to be accessed across all targets if found on its first type

@:noStack            :  (cpp only)

@:noUsing            : Prevents a field from being used with 'using'

@:nonVirtual         : Declares function to be non-virtual in cpp (cpp only)

# 声明 abstract 类型不接受 null 值
@:notNull            : Declares an abstract type as not accepting null values

@:ns                 : Internally used by the Swf generator to handle namespaces (flash only)

# abstract 操作符重载- http://haxe.org/manual/types-abstract-operator-overloading.html
@:op                 : (The operation)Declares an abstract field as being an operator overload

# 当使用 typedef 定义 结构时, 添加在字段(field) 前表示为 可选字段
# 一种类似于写 形参 方法可以替换掉这个元标记 
@:optional           : Marks the field of a structure as optional

# 函数重载, 用于 extern class, 允许同一个方法有不同参数.
@:overload           : (Function specification (no expression))Allows the field to be called with different argument types

# Example: var val = @:privateAccess instance.privateFiled
@:privateAccess      : Allow private access to anything for the annotated expression

@:property           : Marks a property field to be compiled as a native C# property (cs only)

@:protected          : Marks a class field as being protected

@:public             : Marks a class field as being public

# 将类的所有字段声明为 public, 这样就可以避免给每一个字段都添加 public (since 3.0)
@:publicFields       : Forces all class fields of inheriting classes to be public

@:pythonImport       : Generates python import statement for extern classes (python only)

@:readOnly           : Generates a field with the 'readonly' native keyword (cs only)

# 加上这个元标记使得 interface 只存在于编译阶段, 生成结果不会包含 interface 相关的代码
@:remove             : Causes an interface to be removed from all implementing classes before generation

# 宏条件, 需要满足条件才能访问这个类的所有字段.
# 第一个参数 和接在 #if 或 #elseif 之后的条件标识符一样.
# 第二个参数 为可选, 当不满足条件而自定义的提示信息
# 例: @:require(nodejs) 或 @:require(nodejs, "require haxelib nodejs")
@:require            : (Compiler flag [,"custom error message"]) Allows access to a field only if the specified compiler flag is set

# 编译器添加 rtti 信息, 可以通过 haxe.rtti.Rtti.getRtti 检索这些信息 
@:rtti               : Adds runtime type informations (since 3.2)

@:runtime            : ?

# 表明 abstract 类型为运行时类型, 通常用于包装各平台底层类型
@:runtimeValue       : Marks an abstract as being a runtime value

# 调用自身 见 javascript 页面
@:selfCall           : Translates method calls into calling object directly (js only)

# 当 override flash 的类字段时. 注意 重写 flash 的 setter 时, 返回为 Void. 例: @:setter(endian) function set_endian(endian:String):Void{}
@:setter             : (Class field name)Generates a native getter function on the given field (flash only)

# 嵌入声音文件到 swf 文件中去. 例: @:sound("file.wav|mp3") class MySound extends flash.media.Sound{}
@:sound              : (File path)Includes a given .wav or .mp3 file into the target Swf and associates it with the class (must extend flash.media.Sound) (flash only)

@:sourceFile         : Source code filename for external class (cpp only)

@:strict             : Used to declare a native C# attribute or a native Java
                        metadata. Is type checked (for cs,java)

@:struct             : Marks a class definition as a struct. (cs only)

@:structAccess       : Marks an extern class as using struct access('.') not
                        pointer('->') (cpp only)

@:suppressWarnings   : Adds a SuppressWarnings annotation for the generated Java class (java only)

@:throws             : (Type as String)Adds a 'throws' declaration to the generated function. (java only)

# 用于定义 abstract 类
@:to                 : Specifies that the field of the abstract is a cast operation to the type identified in the function

@:transient          : Adds the 'transient' flag to the class field (java only)

@:unbound            : Compiler internal to denote unbounded global variable

@:unifyMinDynamic    : Allows a collection of types to unify to Dynamic

@:unreflective       :  (cpp only)

@:unsafe             : Declares a class, or a method with the C#'s 'unsafe' flag (cs only)

@:usage              : ?

@:void               : use Cpp native `void` return type(cpp only)

@:volatile           : (for cs,java)

其它

缓存编译

用于绑定目录到指定端口,缓存编译, 这样使得每次编译时不会重新解析所有

### --wait 和 --connect 示例
### -v 将会显示详情,如哪些文件缓存还是编绎了,一般情况不需要添加 -v
# 服务绑定6000端口,用于缓存编译结果
haxe -v --wait 6000

另外打开一个新的 CMD 窗口:

# 连接缓存编译, --times 可以显示编译所花的时间
haxe --times --connect 6000 build.hxml

# 如果为 openfl 项目, 编译时则可以像下边:
lime build flash --connect 6000 --times

实际上 flashdevelop 可以在 工具-> 设置-> HaxeContext 里设置, 将 Completion Mode 改为 CompletionServer 就行了, 这样偶尔会出错, 如果出错,更新(touch)下出错的文件就 ok 了.

一些简单的示例

//@:fakeEnum(Int) 示例

#if (haxe_ver > 3.100)

@:enum abstract KeyLocation(Int) {

    var STANDARD = 0;
    var LEFT = 1;
    var RIGHT = 2;
    var NUM_PAD = 3;

}

#else

@:fakeEnum(Int) enum KeyLocation {
    // fakeEnum 似乎没有办法 设置类似于 start 值
    STANDARD;
    LEFT;
    NUM_PAD;
    RIGHT;

}
#end

// openfl 的源码 能大量的见到 @:fakeEnum(String) .
// 不知道为什么 去掉 @:fakeEnum(String) 生成的结果也是一样的. (haxe 3.1)
// 结论是: @:fakeEnum 可以不再使用, 如果需要使用 @:enum abstract 就行了.
@:fakeEnum(String) extern enum Endian {
    BIG_ENDIAN;
    LITTLE_ENDIAN;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics