This can't work for several reasons:
1) the NCI call signatures don't match the C functions' args:
.store_nci_func( 'const_string', 'ppt' )
should be: 'SIt' (return STRING*, interp & C-cstring args)
.store_nci_func( 'string_to_cstring', 'tpp' )
should be: "tIS" (return C-string, interp & STRING args)
(You could use 'pIt' and 'pIp' signatures too, then the STRING* result of the
'const_string' would be wrapped into a ManagedStruct PMC).
2) print does *not* take c-strings, but STRINGs, therefore:
hello = string_to_cstring( interpreter, greet_string )
print hello
is likely to just segfault.
> -- c
leo
> This can't work for several reasons:
>
> 1) the NCI call signatures don't match the C functions' args:
>
> .store_nci_func( 'const_string', 'ppt' )
>
> should be: 'SIt' (return STRING*, interp & C-cstring args)
>
> .store_nci_func( 'string_to_cstring', 'tpp' )
>
> should be: "tIS" (return C-string, interp & STRING args)
>
> (You could use 'pIt' and 'pIp' signatures too, then the STRING* result of
> the 'const_string' would be wrapped into a ManagedStruct PMC).
I don't see documentation for the S or I parameters anywhere in the NCI PDD.
Is there a better place for them?
> 2) print does *not* take c-strings, but STRINGs, therefore:
>
> hello = string_to_cstring( interpreter, greet_string )
> print hello
>
> is likely to just segfault.
I did oversimplify the code somewhat. Here's what I really want to run.
-- c
src/call_list.txt is probably the best place to look. And a good one to look
into occasionally, I've mixed up 'I' and 'J' - sorry.
> I did oversimplify the code somewhat. Here's what I really want to run.
Without futher looking - you have to replace a lot of 'p's (some structure)
with 'J' (the Interpreter* interp structure). E.g.
.store_nci_func( 'Parrot_readbc', 'ppt' )
=>
.store_nci_func( 'Parrot_readbc', 'pJt' )
You migh also grep for enter_nci_method in src/pmc/*.c - all METHODs in .pmc
are converted to NCI calls in the .c files with appropriate signatures.
> -- c
leo
> Without futher looking - you have to replace a lot of 'p's (some structure)
> with 'J' (the Interpreter* interp structure). E.g.
>
> .store_nci_func( 'Parrot_readbc', 'ppt' )
>
> =>
>
> .store_nci_func( 'Parrot_readbc', 'pJt' )
I'm not convinced; this works just fine from the Perl 5 and Ruby bindings.
Most of that code uses the interpreter returned from Parrot_new(), rather than
the current interpreter. (It only uses the current interpreter as the parent
argument to Parrot_new()).
> You migh also grep for enter_nci_method in src/pmc/*.c - all METHODs in
> .pmc are converted to NCI calls in the .c files with appropriate
> signatures.
That ought to work.
-- c