@@ -81,6 +81,15 @@ extern "C"
8181 string_assign (v->stringValue , stringValue);
8282 }
8383
84+ /* ! Assigns pointer to the given value. */
85+ void value_assign_pointer (ValueData *v, const void *pointerValue)
86+ {
87+ value_free (v);
88+
89+ v->type = ValueType::Pointer;
90+ v->pointerValue = pointerValue;
91+ }
92+
8493 /* ! Assigns another value to the given value. */
8594 void value_assign_copy (ValueData *v, const libscratchcpp::ValueData *another)
8695 {
@@ -98,6 +107,9 @@ extern "C"
98107 string_assign (v->stringValue , another->stringValue );
99108 v->type = ValueType::String;
100109 }
110+ } else if (another->type == ValueType::Pointer) {
111+ value_free (v);
112+ v->pointerValue = another->pointerValue ;
101113 }
102114
103115 v->type = another->type ;
@@ -183,11 +195,20 @@ extern "C"
183195
184196 case ValueType::String:
185197 return value_checkString (v->stringValue ) == 1 ;
198+
199+ case ValueType::Pointer:
200+ return false ;
186201 }
187202
188203 return false ;
189204 }
190205
206+ /* ! Returns true if the given value is a pointer. */
207+ bool value_isPointer (const ValueData *v)
208+ {
209+ return v->type == ValueType::Pointer;
210+ }
211+
191212 /* ! Returns true if the given value is a boolean. */
192213 bool value_isBool (const libscratchcpp::ValueData *v)
193214 {
@@ -250,6 +271,8 @@ extern "C"
250271 return v->numberValue != 0 && !std::isnan (v->numberValue );
251272 } else if (v->type == ValueType::String) {
252273 return value_stringToBool (v->stringValue );
274+ } else if (v->type == ValueType::Pointer) {
275+ return v->pointerValue ;
253276 } else {
254277 return false ;
255278 }
@@ -285,8 +308,11 @@ extern "C"
285308 string_assign (ret, &FALSE_STR);
286309 return ret;
287310 }
288- } else
289- return string_pool_new ();
311+ } else {
312+ StringPtr *ret = string_pool_new ();
313+ string_assign (ret, &ZERO_STR);
314+ return ret;
315+ }
290316 }
291317
292318 /* ! Writes the UTF-16 representation of the given value to dst. */
@@ -309,6 +335,8 @@ extern "C"
309335 string = v->stringValue ;
310336 else if (v->type == ValueType::Bool)
311337 return v->boolValue ;
338+ else
339+ return 0 ;
312340
313341 if (string->size > 0 && string->data [0 ] == u' #' ) {
314342 // https://github.com/scratchfoundation/scratch-vm/blob/a4f095db5e03e072ba222fe721eeeb543c9b9c15/src/util/color.js#L60-L69
@@ -347,6 +375,15 @@ extern "C"
347375 return rgb (0 , 0 , 0 );
348376 }
349377
378+ /* ! Returns the pointer stored in the given value or nullptr if it isn't a pointer. */
379+ const void *value_toPointer (const ValueData *v)
380+ {
381+ if (v->type == ValueType::Pointer)
382+ return v->pointerValue ;
383+ else
384+ return nullptr ;
385+ }
386+
350387 /* ! Returns true if the given number represents a round integer. */
351388 bool value_doubleIsInt (double v)
352389 {
0 commit comments