1 (* Simple test of the API.
2 * Copyright (C) 2003 Merjis Ltd.
3 * $Id: test.ml,v 1.5 2003-10-16 11:03:52 rich Exp $
9 (* Perform a full collection - good way to find bugs in initialization code*)
13 Perl.eval "require 'examples/test.pl'";
15 (* Call some subroutines in [test.pl]. *)
16 let sv = Perl.call ~fn:"return_one" [] in
17 printf "return_one returned %d\n" (Perl.int_of_sv sv); flush stdout;
19 let sv = Perl.call ~fn:"adder" [Perl.sv_of_int 3; Perl.sv_of_int 4] in
20 printf "adder (3, 4) = %d\n" (Perl.int_of_sv sv); flush stdout;
22 let svlist = Perl.call_array ~fn:"return_array" [] in
23 print_string "array returned:";
26 printf " %d" (Perl.int_of_sv sv);
28 printf "\n"; flush stdout;
30 let sv = Perl.sv_of_string "return_one" in
31 let sv = Perl.call ~sv [] in
32 printf "return_one returned %d\n" (Perl.int_of_sv sv); flush stdout;
34 (* Call a Perl closure. *)
35 let sv = Perl.call ~fn:"return_closure" [] in
36 let sv = Perl.call ~sv [Perl.sv_of_int 3; Perl.sv_of_int 4] in
37 printf "closure returned %d\n" (Perl.int_of_sv sv); flush stdout;
39 (* Evaluate a simple expression. *)
41 printf "$a contains %d\n" (Perl.int_of_sv (Perl.get_sv "a")); flush stdout;
43 (* Test calling methods in the "TestClass" class. *)
44 let obj = Perl.call_class_method "TestClass" "new" [] in
45 let sv = Perl.call_method obj "get_foo" [] in
46 printf "TestClass.foo is %d\n" (Perl.int_of_sv sv); flush stdout;
47 Perl.call_method obj "set_foo" [Perl.sv_of_int 2];
48 let sv = Perl.call_method obj "get_foo" [] in
49 printf "TestClass.foo is %d\n" (Perl.int_of_sv sv); flush stdout;
51 (* Destroy the interpreter. *)
52 Perl.destroy (Perl.current_interpreter ());
54 (* Perform a full collection - good way to find GC/allocation bugs. *)