next up previous contents index
Next: Adding your function in Up: Adding new internal functions Previous: Reading arguments   Contents   Index

Returning a value

Returning void is easy: just returns FAKE_CELL (which is currently defined as ``(void*)1'', but this might change). To return a value, you have to allocate a cell, reference it once (this is automatically done by all the alloc_*cell functions) and put data into it. Examples:

tree_cell    *retc;

char         *p;

/* return 42 */

retc = alloc_typed_cell(CONST_INT);

retc->x.i_val = 42;

return retc;

/* return "abcd" */

retc = alloc_typed_cell(CONST_DATA);

retc->x.size = 4;

retc->x.str_val = p = emalloc(5);

strcpy(p, "abcd");

return retc;

Michel Arboi 2005-04-29