diff --git a/Perl6.xs b/Perl6.xs index aa859c1..db01ee0 100644 --- a/Perl6.xs +++ b/Perl6.xs @@ -9,6 +9,7 @@ #include "Perl6.h" SV *(*call_method_callback)(IV, char *); +SV *(*call_function_callback)(char *); SV *(*eval_code_callback)(char *); MVMInstance *instance; MVMCompUnit *cu; @@ -21,9 +22,10 @@ static void toplevel_initial_invoke(MVMThreadContext *tc, void *data) { MVM_frame_invoke(tc, (MVMStaticFrame *)data, MVM_callsite_get_common(tc, MVM_CALLSITE_ID_NULL_ARGS), NULL, NULL, NULL, -1); } -void init_callbacks(SV *(*eval_p6_code)(char *), SV *(*call_p6_method)(IV, char *)) { +void init_callbacks(SV *(*eval_p6_code)(char *), SV *(*call_p6_method)(IV, char *), SV *(*call_p6_function)(char *)) { eval_code_callback = eval_p6_code; call_method_callback = call_p6_method; + call_function_callback = call_p6_function; } SV *p5_int_to_sv(IV value) { @@ -86,8 +88,6 @@ initialize() MVMThreadContext *tc = instance->main_thread; cu = MVM_cu_map_from_file(tc, filename); - call_method_callback = NULL; - MVMROOT(tc, cu, { /* The call to MVM_string_utf8_decode() may allocate, invalidating the location cu->body.filename */ @@ -143,6 +143,15 @@ run(code) OUTPUT: RETVAL +SV * +call(name) + char *name + CODE: + cur_my_perl = my_perl; + RETVAL = call_function_callback(name); + OUTPUT: + RETVAL + SV * invoke(name) char *name diff --git a/lib/Inline/Perl6Helper.pm6 b/lib/Inline/Perl6Helper.pm6 index 8196b0c..40b2bc9 100644 --- a/lib/Inline/Perl6Helper.pm6 +++ b/lib/Inline/Perl6Helper.pm6 @@ -32,9 +32,14 @@ our $call_method = sub (Int $index, Str $name) returns OpaquePointer { return OpaquePointer; }; +our $call_function = sub (Str $name) returns OpaquePointer { + return p6_to_p5(&::($name)()); +}; + sub init_callbacks( &eval_code (Str --> OpaquePointer), - &call_method (Int, Str --> OpaquePointer) + &call_method (Int, Str --> OpaquePointer), + &call_function (Str --> OpaquePointer), ) is native(@*ARGS[0]) { * }; -init_callbacks($eval_code, $call_method); +init_callbacks($eval_code, $call_method, $call_function); diff --git a/t/04call_function.t b/t/04call_function.t new file mode 100644 index 0000000..171ecac --- /dev/null +++ b/t/04call_function.t @@ -0,0 +1,9 @@ +use Test::More tests => 1; +use Inline::Perl6; + +Inline::Perl6::initialize; +ok(1); +Inline::Perl6::call('exit'); +ok(0); +Inline::Perl6::destroy; +