Returning Multiple Values

Perl lets you return things, such as arrays and hashes, to the calling function. To do this from C, you must directly manipulate the Perl argument stack. Specifically, you have to push a lot of stuff onto it.

Suppose that you want to return an array containing the coordinates of each location containing a set bit.

You have the usual function call heading and local variable declaration:

void get_values() {
    int x, y; 
    Inline_Stack_Vars;

But something new has been added. The Inline system uses a number of variables to keep track of what it’s doing with the stack. These are declared by the macro Inline_Stack_Vars. (The variables are sp, items, ax, and mark, so don’t use any of these names in your program.)

The next step ...

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.