やってみる

アウトプットすべく己を導くためのブログ。その試行錯誤すらたれ流す。

RaspberryPi4でHaxeプログラミング

 環境開発+HelloWorld

Haxeとは?

 つまりマルチプラットフォームなゲームが作れる?

情報源

 ビルドするのは超絶に面倒そう。なのでaptで入れる。

インストール

$ apt search haxe
ソート中... 完了
全文検索... 完了  
haxe/stable,stable 1:3.4.7-1 armhf
  multi-target universal programming language

libapache2-mod-neko/stable,stable 2.2.0-2+b2 armhf
  Apache module for running server-side Neko programs

libneko2/stable,stable 2.2.0-2+b2 armhf
  Lightweight virtual machine - shared library

neko/stable,stable 2.2.0-2+b2 armhf
  Lightweight virtual machine - compiler and tools

neko-dev/stable,stable 2.2.0-2+b2 armhf
  Lightweight virtual machine - headers

vim-syntastic/stable,stable 3.9.0-1 all
  Syntax checking hacks for vim

 古いけどあった。これでいいや。

sudo apt install haxe

ログ

パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています                
状態情報を読み取っています... 完了
以下の追加パッケージがインストールされます:
  libapr1 libaprutil1 libmariadb3 libmbedcrypto3 libmbedtls12 libmbedx509-0 libneko2 mariadb-common mysql-common neko
提案パッケージ:
  libapache2-mod-neko neko-dev
以下のパッケージが新たにインストールされます:
  haxe libapr1 libaprutil1 libmariadb3 libmbedcrypto3 libmbedtls12 libmbedx509-0 libneko2 mariadb-common mysql-common neko
アップグレード: 0 個、新規インストール: 11 個、削除: 0 個、保留: 68 個。
4,552 kB のアーカイブを取得する必要があります。
この操作後に追加で 18.9 MB のディスク容量が消費されます。
続行しますか? [Y/n] 

ヘルプ

$ haxe --help
Haxe Compiler 3.4.7 - (C)2005-2017 Haxe Foundation
 Usage : haxe -main <class> [-swf|-js|-neko|-php|-cpp|-cppia|-as3|-cs|-java|-python|-hl|-lua] <output> [options]
 Options :
  -cp <path> : add a directory to find source files
  -js <file> : compile code to JavaScript file
  -lua <file> : compile code to Lua file
  -swf <file> : compile code to Flash SWF file
  -as3 <directory> : generate AS3 code into target directory
  -neko <file> : compile code to Neko Binary
  -php <directory> : generate PHP code into target directory
  -cpp <directory> : generate C++ code into target directory
  -cppia <file> : generate Cppia code into target file
  -cs <directory> : generate C# code into target directory
  -java <directory> : generate Java code into target directory
  -python <file> : generate Python code as target file
  -hl <file> : compile HL code as target file
  -xml <file> : generate XML types description
  -main <class> : select startup class
  -lib <library[:version]> : use a haxelib library
  -D <var[=value]> : define a conditional compilation flag
  -v : turn on verbose mode
  -debug : add debug information to the compiled code
  -dce [std|full|no] : set the dead code elimination mode (default std)
  -swf-version <version> : change the SWF version
  -swf-header <header> : define SWF header (width:height:fps:color)
  -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 <file>[@name] : add a named resource file
  -prompt : prompt on error
  -cmd : run the specified command after successful compilation
  --flash-strict : more type strict flash API
  --no-traces : don't compile trace calls in the program
  --gen-hx-classes : generate hx headers for all input classes
  --next : separate several haxe compilations
  --each : append preceding parameters to all haxe compilations separated by --next
  --display : display code tips
  --no-output : compiles but does not generate any file
  --times : measure compilation times
  --no-inline : disable inlining
  --no-opt : disable code optimizations
  --php-front <filename> : select the name for the php front file
  --php-lib <filename> : select the name for the php lib folder
  --php-prefix <name> : prefix all classes with given name
  --remap <package:target> : remap a package to another one
  --interp : interpret the program using internal macro system
  --macro  : call the given macro before typing anything else
  --eval  : evaluates argument as Haxe module code
  --wait <[host:]port> : wait on the given port for commands to run)
  --connect <[host:]port> : connect on the given port and run commands there)
  --cwd <dir> : set current working directory
  -version : print version and exit
  --help-defines : print help for all compiler specific defines
  --help-metas : print help for all compiler metadatas
  -help  Display this list of options
  --help  Display this list of options

Hello world

vim Main.hx
class Main {
    static public function main(): Void {
        trace("trace こんにちわ世界");
        Sys.println("Sys.println こんにちわ世界");
    }
}
haxe -main Main --interp
Main.hx:3: trace こんにちわ世界
Sys.println こんにちわ世界

 なお、クラス名とファイル名は同じである必要があるっぽい。ファイル名がmain.hxだと以下のようなエラーになった。

Type not found : Main

所感

 functionが冗長。

対象環境

$ uname -a
Linux raspberrypi 4.19.97-v7l+ #1294 SMP Thu Jan 30 13:21:14 GMT 2020 armv7l GNU/Linux