← Cookbook Interop Intermediate · Pooka 0.5.0

Call Pooka from Erlang

Pass a UTF-8 binary from Erlang to a Pooka function and get a greeting back.

You will use

  • A Pooka module with a public function
  • pooka build --target prod to compile it
  • The Erlang shell with the compiled apps on its code path

The whole program

src/main.pooka
module main

import pooka/io

greet(name: String) -> String {
  "Hello, " + name + "!"
}

main() {
  io.println(greet("Ada"))
}

Build the package

pooka new greeting
cd greeting

Replace src/main.pooka with the program above, then build and launch Erlang from the project directory.

pooka build --target prod
ERL_LIBS="$PWD/build/prod/erlang" erl

Call the function

1> 'pooka@greeting@main':greet(<<"Ada">>).
<<"Hello, Ada!">>
2> q().
ok

The generated module name includes the Pooka package (greeting) and module (main). Quote the full name so Erlang reads it as an atom. Pooka uses UTF-8 binaries for String, so the argument uses Erlang's <<"…">> syntax.

The interop guide lists the BEAM representations for more Pooka types, including classes, enums, and results.