static */
| 368 | }; |
| 369 | |
| 370 | /* static */ bool ScriptInstance::SaveObject(HSQUIRRELVM vm, SQInteger index, int max_depth, bool test) |
| 371 | { |
| 372 | if (max_depth == 0) { |
| 373 | ScriptLog::Error("Savedata can only be nested to 25 deep. No data saved."); // SQUIRREL_MAX_DEPTH = 25 |
| 374 | return false; |
| 375 | } |
| 376 | |
| 377 | switch (sq_gettype(vm, index)) { |
| 378 | case OT_INTEGER: { |
| 379 | if (!test) { |
| 380 | _script_sl_byte = SQSL_INT; |
| 381 | SlObject(nullptr, _script_byte); |
| 382 | } |
| 383 | SQInteger res; |
| 384 | sq_getinteger(vm, index, &res); |
| 385 | if (!test) { |
| 386 | int64_t value = (int64_t)res; |
| 387 | SlCopy(&value, 1, SLE_INT64); |
| 388 | } |
| 389 | return true; |
| 390 | } |
| 391 | |
| 392 | case OT_STRING: { |
| 393 | if (!test) { |
| 394 | _script_sl_byte = SQSL_STRING; |
| 395 | SlObject(nullptr, _script_byte); |
| 396 | } |
| 397 | std::string_view view; |
| 398 | sq_getstring(vm, index, view); |
| 399 | size_t len = view.size() + 1; |
| 400 | if (len >= 255) { |
| 401 | ScriptLog::Error("Maximum string length is 254 chars. No data saved."); |
| 402 | return false; |
| 403 | } |
| 404 | if (!test) { |
| 405 | _script_sl_byte = (uint8_t)len; |
| 406 | SlObject(nullptr, _script_byte); |
| 407 | SlCopy(const_cast<char *>(view.data()), len, SLE_CHAR); |
| 408 | } |
| 409 | return true; |
| 410 | } |
| 411 | |
| 412 | case OT_ARRAY: { |
| 413 | if (!test) { |
| 414 | _script_sl_byte = SQSL_ARRAY; |
| 415 | SlObject(nullptr, _script_byte); |
| 416 | } |
| 417 | sq_pushnull(vm); |
| 418 | while (SQ_SUCCEEDED(sq_next(vm, index - 1))) { |
| 419 | /* Store the value */ |
| 420 | bool res = SaveObject(vm, -1, max_depth - 1, test); |
| 421 | sq_pop(vm, 2); |
| 422 | if (!res) { |
| 423 | sq_pop(vm, 1); |
| 424 | return false; |
| 425 | } |
| 426 | } |
| 427 | sq_pop(vm, 1); |
nothing calls this directly
no test coverage detected