Create Variant built-in functions.

-Moved Expression to use this, removed its own.
-Eventually GDScript/VisualScript/GDNative need to be moved to this.
-Given the JSON functions were hacked-in, removed them and created a new JSONParser class
-Made sure these functions appear properly in documentation, since they will be removed from GDScript
This commit is contained in:
reduz
2020-11-10 18:31:33 -03:00
parent a80ec80b57
commit 5288ff538d
12 changed files with 1574 additions and 822 deletions

View File

@@ -455,3 +455,35 @@ Error JSON::parse(const String &p_json, Variant &r_ret, String &r_err_str, int &
return err;
}
Error JSONParser::parse_string(const String &p_json_string) {
return JSON::parse(p_json_string, data, err_text, err_line);
}
String JSONParser::get_error_text() const {
return err_text;
}
int JSONParser::get_error_line() const {
return err_line;
}
Variant JSONParser::get_data() const {
return data;
}
Error JSONParser::decode_data(const Variant &p_data, const String &p_indent, bool p_sort_keys) {
string = JSON::print(p_data, p_indent, p_sort_keys);
data = p_data;
return OK;
}
String JSONParser::get_string() const {
return string;
}
void JSONParser::_bind_methods() {
ClassDB::bind_method(D_METHOD("parse_string", "json_string"), &JSONParser::parse_string);
ClassDB::bind_method(D_METHOD("get_error_text"), &JSONParser::get_error_text);
ClassDB::bind_method(D_METHOD("get_error_line"), &JSONParser::get_error_line);
ClassDB::bind_method(D_METHOD("get_data"), &JSONParser::get_data);
ClassDB::bind_method(D_METHOD("decode_data", "data", "indent", "sort_keys"), &JSONParser::decode_data, DEFVAL(""), DEFVAL(true));
ClassDB::bind_method(D_METHOD("get_string"), &JSONParser::get_string);
}