Browse files

Implement reia:eval/1, reia:apply/3, and reia:apply/4

reia:eval/1 accepts a string with a default empty binding. It's a simple string eval.

reia:apply/3 provides standard Erlang-style Module-Function-Argument (MFA) style function application.

reia:apply/4 provides MFA function application, but also takes a block.
  • Loading branch information...
1 parent 584be60 commit 2120362be8e1cbe1882c93195a43dfd546a0e336 Tony Arcieri committed Feb 14, 2011
Showing with 16 additions and 3 deletions.
  1. +16 −3 src/core/reia.erl
View
19 src/core/reia.erl
@@ -10,7 +10,8 @@
init/0,
load/1,
parse/1,
- eval/2,
+ eval/1, eval/2,
+ apply/3, apply/4,
inst/2, inst/3,
invoke/3, invoke/4,
throw/2, throw/3,
@@ -41,6 +42,8 @@ parse(String) ->
reia_compiler:parse(String).
% Evaluate the given string of Reia source code
+eval(String) ->
+ eval(String, []).
eval(String, Binding) ->
reia_eval:exprs(parse(String), Binding).
@@ -57,8 +60,18 @@ inst(Class, Arguments, Block) ->
Object = #reia_object{class=Class, ivars=dict:new()},
Class:call({Object, initialize, Arguments}, Block)
end.
-
-% Invoke the given method on the given object
+
+% Call a function within a Reia module
+apply(Module, Function, Arguments) -> apply(Module, Function, Arguments, nil).
+apply(Module, Function, Arguments, Block) ->
+ Arguments2 = if
+ is_tuple(Arguments) -> Arguments;
+ is_list(Arguments) -> list_to_tuple(Arguments);
+ true -> throw({error, "invalid type for arguments"})
+ end,
+ Module:Function(Arguments2, Block).
+
+% Invoke a method on the given object
invoke(Receiver, Method, Arguments) -> invoke(Receiver, Method, Arguments, nil).
invoke(Receiver, Method, Arguments, Block) ->
Arguments2 = if

0 comments on commit 2120362

Please sign in to comment.