Value Local Arrays (SDK)
Sometimes, the number of new locals to be protected is unknown at compile time. To handle this, you can use the following macros that create protected arrays of values. One form creates the array on the stack using _alloca() and so is useful inside one function call, the other puts the array in the heap and so can be used across functions.
In both cases, you also need to declare a Value** variable to hold the pointer to the array.
Stack-resident
value_local_array(pointer_var, count); // allocate
pop_value_local_array(pointer_var); // dismiss
Heap-resident
value_temp_array(pointer_var, count); // allocate
realloc_value_temp_array(pointer_var, count, old_count); // grow
pop_value_temp_array(pointer_var); //dismiss
For example,
Value** items;
...
value_local_array(items, n);
...
for (int i = 0; i < n; i++)
items[i] = Float::intern(data[i]);
...
pop_value_local_array(items);
...