escript 注意点

Erlangスクリプト (=escript) を書く際、結構ハマッたのでメモメモ

escript には main/1 関数が必須

スクリプトを実行する際に、 main/1 関数が呼ばれる。

An Erlang script file must always contain the function main/1. When the script is run, the main/1 will be called with a list of strings representing the arguments given to the script

プリプロセッサディレクティヴは使えない

  • include_lib は例外的に使える。

Pre-processor directives in the script files are ignored, with the exception for the -include_lib directive.

定義済マクロは使えない

モジュール名が無いため、 ?MODULE なんかは escript 内で使えない。

Pre-defined macros (such as ?MODULE) will not work. A script does not have module name, so BIFs such as spawn/3 that require a module name cannot be used. Instead, use a BIF that take a fun, such as spawn/1.