Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Calling PERL from C code - How to "build" a hash on the PERL stack before calling the function?

by itamarat (Acolyte)
on Jul 07, 2014 at 09:12 UTC ( [id://1092537]=note: print w/replies, xml ) Need Help??


in reply to Re: Calling PERL from C code - How to "build" a hash on the PERL stack before calling the function?
in thread Calling PERL from C code - How to "build" a hash on the PERL stack before calling the function?

Hi,

You have helped a lot! Thank you!

How do I push the HV to the PERL stack?
Currently I use:
XPUSHs(sv_2mortal(newSViv((unsigned int)cbCtx)));

To push integer to the stack. I've searched for 'newSVhv' and it is not present. How should it be done?

Thanks again!

Itamar

  • Comment on Re^2: Calling PERL from C code - How to "build" a hash on the PERL stack before calling the function?

Replies are listed 'Best First'.
Re^3: Calling PERL from C code - How to "build" a hash on the PERL stack before calling the function?
by Corion (Patriarch) on Jul 07, 2014 at 09:16 UTC

    perlcall has a section on Returning a List of Values. If you don't want to flatten the hash into a list of values, consider returning a reference to the hash, by returning newSVrv(HV) (or whatever the magic C incantation would be, according to perlguts.

Re^3: Calling PERL from C code - How to "build" a hash on the PERL stack before calling the function?
by tobyink (Canon) on Jul 07, 2014 at 13:53 UTC

    You can't push an HV onto the stack. Perl functions are only ever passed a list of scalars!

    You can however pass a reference to a hash, which the Perl function can dereference to access the original hash.

    Or you can pass alternating pairs of keys and values onto the stack. In which case, the Perl function can assign @_ to a lexical hash (my %args = @_).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1092537]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2024-04-23 08:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found