| 860 | } |
| 861 | |
| 862 | static bool lua_save_data_push_sjson_value(lua_State *L, const char *value, bool &error) |
| 863 | { |
| 864 | const int top = lua_gettop(L); |
| 865 | LuaStack stack(L, INT_MAX); |
| 866 | |
| 867 | switch (sjson::type(value)) { |
| 868 | case JsonValueType::NIL: |
| 869 | stack.push_nil(); |
| 870 | break; |
| 871 | |
| 872 | case JsonValueType::BOOL: { |
| 873 | const bool val = sjson::parse_bool(value); |
| 874 | if (error) { |
| 875 | lua_settop(L, top); |
| 876 | return false; |
| 877 | } |
| 878 | stack.push_bool(val); |
| 879 | return true; |
| 880 | } |
| 881 | |
| 882 | case JsonValueType::NUMBER: { |
| 883 | const f32 val = sjson::parse_float(value); |
| 884 | if (error) { |
| 885 | lua_settop(L, top); |
| 886 | return false; |
| 887 | } |
| 888 | stack.push_float(val); |
| 889 | return true; |
| 890 | } |
| 891 | |
| 892 | case JsonValueType::STRING: { |
| 893 | TempAllocator1024 ta; |
| 894 | DynamicString str(ta); |
| 895 | sjson::parse_string(str, value); |
| 896 | if (error) { |
| 897 | lua_settop(L, top); |
| 898 | return false; |
| 899 | } |
| 900 | stack.push_lstring(str.c_str(), str.length()); |
| 901 | break; |
| 902 | } |
| 903 | |
| 904 | case JsonValueType::ARRAY: |
| 905 | if (!lua_save_data_push_sjson_array(L, value, error)) { |
| 906 | lua_settop(L, top); |
| 907 | return false; |
| 908 | } |
| 909 | return true; |
| 910 | |
| 911 | case JsonValueType::OBJECT: |
| 912 | if (!lua_save_data_push_sjson_object(L, value, error, false)) { |
| 913 | lua_settop(L, top); |
| 914 | return false; |
| 915 | } |
| 916 | return true; |
| 917 | |
| 918 | default: |
| 919 | stack.push_nil(); |
no test coverage detected