Erlang Interfacing

tarcieri edited this page Feb 15, 2011 · 6 revisions
Clone this wiki locally

Reia provides support for embedding within an existing Erlang application and calling Erlang functions directly from Reia code.

Calling Erlang functions from Reia

Reia provides special syntax for calling Erlang functions:

erl.module.function(arg1, arg2, arg3)

The special keyword "erl" is used to signify you want to make a call to native Erlang code. The above code snippet is equivalent to the following Erlang code:

module:function(Arg1, Arg2, Arg3)

A special syntax is available in Reia for calling functions from the "erlang" module:

erl.length([1,2,3]) # returns 3

Embedding Reia in an Erlang application

The reia module defines a set of functions for embedding Reia within your existing Erlang application. The following functions in the reia module can be used for loading and invoking Reia code from within an existing Erlang application:

reia:init() → ok

Initializes the Reia environment within the Erlang VM. Returns an ok atom, or raises an exception if there was a problem locating the Reia distribution. You will need to call this function before invoking any other Reia interfacing functions.

reia:load(Filename) → {ok, ErlModule, ReiaModule} | {error, Error}

Load the given Reia source code file. If successful, returns an ok tuple with the given Erlang and Reia module identifiers. Otherwise, returns an error tuple with the given error identifier.

reia:eval(String) → {value, ReturnValue, NewBinding}

reia:eval(String, Binding) → {value, ReturnValue, NewBinding}

Evalutes the given Reia code, specified as a string. Optionally accepts an input binding (given in the form of a list of key/value tuples, e.g. [{a,1},{b,2},{c,3}], which represents variable "a" being bound to 1, "b", being bound to 2, etc.)

A value tuple is returned upon success. Otherwise, an exception is thrown.

reia:apply(Module, Function, Arguments) → Result

reia:apply(Module, Function, Arguments, Block) → Result

Call the given function of a Reia module, returning the result.

reia:inst(Class, Arguments) → Object

reia:inst(Class, Arguments, Block) → Object

Create a new instance of the given Reia class, passing the given arguments and/or block to the class's initialize method.

reia:invoke(Receiver, Method, Arguments) -→ Result

reia:invoke(Receiver, Method, Arguments, Block) → Result

Invoke the given method on a Reia object (as returned from reia:inst), returning the value from the method when called with the given arguments and/or block.

reia:throw(Class, Message)

reia:throw(Class, Line, Message)

Generates a native Reia exception of the given class and throws it

reia:list_to_string(List) -> #reia_string{}

Create a Reia string from a native Erlang list of characters

reia:binary_to_string(List) -> #reia_string{}

Create a Reia string from a native Erlang binary