| 449 | } |
| 450 | |
| 451 | static void lua_dump_table(lua_State *L, int i, StringStream &json) |
| 452 | { |
| 453 | LuaStack stack(L); |
| 454 | |
| 455 | bool comma = false; |
| 456 | int array_index = 1; |
| 457 | |
| 458 | json << "{"; |
| 459 | |
| 460 | stack.push_nil(); |
| 461 | while (stack.next(i) != 0) { |
| 462 | if (comma) |
| 463 | json << ","; |
| 464 | comma = true; |
| 465 | |
| 466 | json << "\""; |
| 467 | if (stack.is_string(-2) && !stack.is_number(-2)) |
| 468 | json << stack.get_string(-2); |
| 469 | else |
| 470 | json << array_index++; |
| 471 | json << "\":"; |
| 472 | |
| 473 | if (stack.is_nil(i + 2)) { |
| 474 | json << "null"; |
| 475 | } else if (stack.is_bool(i + 2)) { |
| 476 | const bool b = stack.get_bool(i + 2); |
| 477 | json << (b ? "true" : "false"); |
| 478 | } else if (stack.is_number(i + 2)) { |
| 479 | json << stack.get_float(i + 2); |
| 480 | } else if (stack.is_string(i + 2)) { |
| 481 | const char *str = stack.get_string(i + 2); |
| 482 | json << "\""; |
| 483 | for (; *str; ++str) { |
| 484 | if (*str == '"' || *str == '\\') |
| 485 | json << '\\'; |
| 486 | json << *str; |
| 487 | } |
| 488 | json << "\""; |
| 489 | } else if (stack.is_vector3(i + 2)) { |
| 490 | const Vector3 v = stack.get_vector3(i + 2); |
| 491 | json << "["; |
| 492 | json << v.x << ","; |
| 493 | json << v.y << ","; |
| 494 | json << v.z; |
| 495 | json << "]"; |
| 496 | } else if (stack.is_quaternion(i + 2)) { |
| 497 | const Quaternion q = stack.get_quaternion(i + 2); |
| 498 | json << "["; |
| 499 | json << q.x << ","; |
| 500 | json << q.y << ","; |
| 501 | json << q.z << ","; |
| 502 | json << q.w; |
| 503 | json << "]"; |
| 504 | } else if (stack.is_matrix4x4(i + 2)) { |
| 505 | const Matrix4x4 m = stack.get_matrix4x4(i + 2); |
| 506 | json << "["; |
| 507 | json << m.x.x << ","; |
| 508 | json << m.x.y << ","; |
no test coverage detected