Skip to content
Permalink
Browse files

Add array_set function (#1750)

Add array_set function with GM function signature which can later be used to inline the script by-reference array accessor. Also update the var array tests to cover the new function.
  • Loading branch information...
9Morello authored and RobertBColton committed Jun 16, 2019
1 parent 7593150 commit ed696c743a117d9648353268cff6b2dac5fbb842
@@ -218,6 +218,12 @@ gtest_assert_eq(user_array_same[1], 24);
gtest_assert_eq(user_array_same[2], 24);
gtest_assert_eq(user_array_same[3], 347);
gtest_assert_eq(user_array_same[4], 555);
array_set(user_array_smaller, 1, "Giorno Giovanna");
array_set(user_array_smaller, 25, 10);
array_set(user_array_smaller, 50, "Doppio");
gtest_assert_eq(user_array_smaller[1], "Giorno Giovanna");
gtest_assert_eq(user_array_smaller[25], 10);
gtest_assert_eq(user_array_smaller[50], "Doppio");

// Simple 2D array tests
var user_array_2d = array_create_2d(3, 5, 256);
@@ -47,6 +47,7 @@ void array_copy(var& dest, size_t dest_index, const var& src, size_t src_index,
int array_length_1d(const var& v) { return v.array_len(); }
int array_length_2d(const var& v, int n) { return v.array_len(n); }
int array_height_2d(const var& v) { return v.array_height(); }
void array_set(var& v, int pos, variant value) { v[pos] = value; }
bool is_array(const var& v) {
//There is no way (currently) to downsize an array from >1 element, so this might not be accurate.
return (v.array_height() > 1) || (v.array_len() > 1);
@@ -38,6 +38,7 @@ void array_copy(var& dest, size_t dest_index, const var& src, size_t src_index,
int array_length_1d(const var& v);
int array_length_2d(const var& v, int n);
int array_height_2d(const var& v);
void array_set(var& v, int pos, variant value);
bool is_array(const var& v);
} //namespace enigma_user

0 comments on commit ed696c7

Please sign in to comment.
You can’t perform that action at this time.