To pop a string from the stack, get its length and push the result to the stack :
tst1.c

#include <hpgcc49.h>
#include <hpstack.h>

int main (void)
{
int ret;

// Pops a string from the stack
char *str = NULL;

if ((ret = hps_pop_str (&str)) == HPS_OK)
{
// Gets the string length
int len = strlen (str);

// Pushes it to the stack
if ((ret = hps_push_int (len)) != HPS_OK)
{
(void) hps_push_str (hps_error (ret));
}

// Frees the memory
free (str);
}
else
{
(void) hps_push_str (hps_error (ret));
}

return (0);
}

->



To get the 3d element of a list which is at the second level of the stack, and push it onto the stack :
tst2.c

#include <hpgcc49.h>
#include <hpstack.h>

int main (void)
{
int ret;

// Picks a list at the second level of the stack
list_t *lst;

if ((ret = hps_pick_list (2, &lst)) == HPS_OK)
{
// Gets the 3d element
hpobj_t *obj;

if ((ret = hps_list_get (lst, 3, &obj)) == HPS_OK)
{
// Pushes it onto the stack
ret = hps_push (obj);
(void) hps_obj_destroy (&obj);
}

// Frees the allocated objects
(void) hps_list_destroy (&lst);
}

if (ret != HPS_OK)
{
hps_push_str (hps_error (ret));
}

return (0);
}

->



To get the element [2, 4] of an array which is at the top of the stack, and push it onto the stack, and in case of error push the error message onto the stack :
tst3.c

#include <hpgcc49.h>
#include <hpstack.h>

int main (void)
{
int ret; // Return code for called functions

// Picks an array at the top of the stack
array_t *array;

if ((ret = hps_pick_array (1, &array)) == HPS_OK)
{
// Gets the element [2, 4]
hpobj_t *obj;

if ((ret = hps_array_get (array, &obj, 2, 2, 4)) == HPS_OK)
{
// Pushes it onto the stack
ret = hps_push (obj);
(void) hps_obj_destroy (&obj);
}
else
{
ret = hps_push_str (hps_error (ret));
}

// Frees the allocated objects
hps_array_destroy (&array);
}
if (ret != HPS_OK)
{
hps_push_str (hps_error (ret));
}

return (0);
}


->

->