summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-01-08 22:40:00 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-01-08 22:40:00 -0300
commit62273e51a252287d1c60228e8a8e8939ecaa73c6 (patch)
treefd39af99bc9cc1e71a623a0efda3222c3633134d /core
parentfdc3380cf6e0d17b19bbf9458f641fd948aa2ffc (diff)
downloadredot-engine-62273e51a252287d1c60228e8a8e8939ecaa73c6.tar.gz
Moved JSON functions to built-in to_json, parse_json, validate_json
Diffstat (limited to 'core')
-rw-r--r--core/dictionary.cpp22
-rw-r--r--core/dictionary.h3
-rw-r--r--core/io/json.cpp19
-rw-r--r--core/io/json.h4
-rw-r--r--core/variant_call.cpp16
5 files changed, 21 insertions, 43 deletions
diff --git a/core/dictionary.cpp b/core/dictionary.cpp
index 94bb0b6e8c..d5d29ca0fc 100644
--- a/core/dictionary.cpp
+++ b/core/dictionary.cpp
@@ -29,7 +29,6 @@
#include "dictionary.h"
#include "safe_refcount.h"
#include "variant.h"
-#include "io/json.h"
struct _DictionaryVariantHash {
@@ -277,22 +276,6 @@ const Variant* Dictionary::next(const Variant* p_key) const {
return _p->variant_map.next(p_key);
}
-
-Error Dictionary::parse_json(const String& p_json) {
-
- String errstr;
- int errline=0;
- if (p_json != ""){
- Error err = JSON::parse(p_json,*this,errstr,errline);
- if (err!=OK) {
- ERR_EXPLAIN("Error parsing JSON: "+errstr+" at line: "+itos(errline));
- ERR_FAIL_COND_V(err!=OK,err);
- }
- }
-
- return OK;
-}
-
Dictionary Dictionary::copy() const {
Dictionary n(is_shared());
@@ -307,11 +290,6 @@ Dictionary Dictionary::copy() const {
return n;
}
-String Dictionary::to_json() const {
-
- return JSON::print(*this);
-}
-
void Dictionary::operator=(const Dictionary& p_dictionary) {
diff --git a/core/dictionary.h b/core/dictionary.h
index d074db8588..9fab653470 100644
--- a/core/dictionary.h
+++ b/core/dictionary.h
@@ -63,9 +63,6 @@ public:
void clear();
- Error parse_json(const String& p_json);
- String to_json() const;
-
bool is_shared() const;
bool has(const Variant& p_key) const;
diff --git a/core/io/json.cpp b/core/io/json.cpp
index f42155bc94..3280f94750 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -92,9 +92,9 @@ String JSON::_print_var(const Variant& p_var) {
}
-String JSON::print(const Dictionary& p_dict) {
+String JSON::print(const Variant& p_var) {
- return _print_var(p_dict);
+ return _print_var(p_var);
}
@@ -450,27 +450,24 @@ Error JSON::_parse_object(Dictionary &object,const CharType *p_str,int &index, i
}
-Error JSON::parse(const String& p_json,Dictionary& r_ret,String &r_err_str,int &r_err_line) {
+Error JSON::parse(const String& p_json, Variant &r_ret, String &r_err_str, int &r_err_line) {
const CharType *str = p_json.ptr();
int idx = 0;
int len = p_json.length();
Token token;
- int line=0;
+ r_err_line=0;
String aux_key;
- Error err = _get_token(str,idx,len,token,line,r_err_str);
+ Error err = _get_token(str,idx,len,token,r_err_line,r_err_str);
if (err)
return err;
- if (token.type!=TK_CURLY_BRACKET_OPEN) {
+ err = _parse_value(r_ret,token,str,idx,len,r_err_line,r_err_str);
- r_err_str="Expected '{'";
- return ERR_PARSE_ERROR;
- }
-
- return _parse_object(r_ret,str,idx,len,r_err_line,r_err_str);
+ return err;
+
}
diff --git a/core/io/json.h b/core/io/json.h
index 52fcac145d..97457d223e 100644
--- a/core/io/json.h
+++ b/core/io/json.h
@@ -74,8 +74,8 @@ class JSON {
static Error _parse_object(Dictionary &object,const CharType *p_str,int &index, int p_len,int &line,String &r_err_str);
public:
- static String print(const Dictionary& p_dict);
- static Error parse(const String& p_json,Dictionary& r_ret,String &r_err_str,int &r_err_line);
+ static String print(const Variant &p_var);
+ static Error parse(const String& p_json,Variant& r_ret,String &r_err_str,int &r_err_line);
};
#endif // JSON_H
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index a54737faf8..5c9e8e9248 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -32,6 +32,7 @@
#include "core_string_names.h"
#include "script_language.h"
+
typedef void (*VariantFunc)(Variant& r_ret,Variant& p_self,const Variant** p_args);
typedef void (*VariantConstructFunc)(Variant& r_ret,const Variant** p_args);
@@ -146,6 +147,15 @@ struct _VariantCall {
};
// void addfunc(Variant::Type p_type, const StringName& p_name,VariantFunc p_func);
+
+ static void make_func_return_variant(Variant::Type p_type,const StringName& p_name) {
+
+#ifdef DEBUG_ENABLED
+ type_funcs[p_type].functions[p_name].returns=true;
+#endif
+ }
+
+
static void addfunc(Variant::Type p_type, Variant::Type p_return,const StringName& p_name,VariantFunc p_func, const Vector<Variant>& p_defaultarg,const Arg& p_argtype1=Arg(),const Arg& p_argtype2=Arg(),const Arg& p_argtype3=Arg(),const Arg& p_argtype4=Arg(),const Arg& p_argtype5=Arg()) {
FuncData funcdata;
@@ -455,8 +465,6 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM0R(Dictionary,hash);
VCALL_LOCALMEM0R(Dictionary,keys);
VCALL_LOCALMEM0R(Dictionary,values);
- VCALL_LOCALMEM1R(Dictionary,parse_json);
- VCALL_LOCALMEM0R(Dictionary,to_json);
VCALL_LOCALMEM2(Array,set);
VCALL_LOCALMEM1R(Array,get);
@@ -1436,6 +1444,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC0(STRING,RAW_ARRAY,String,to_utf8,varray());
+
ADDFUNC0(VECTOR2,VECTOR2,Vector2,normalized,varray());
ADDFUNC0(VECTOR2,REAL,Vector2,length,varray());
ADDFUNC0(VECTOR2,REAL,Vector2,angle,varray());
@@ -1556,9 +1565,6 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC0(DICTIONARY,ARRAY,Dictionary,keys,varray());
ADDFUNC0(DICTIONARY,ARRAY,Dictionary,values,varray());
- ADDFUNC1(DICTIONARY,INT,Dictionary,parse_json,STRING,"json",varray());
- ADDFUNC0(DICTIONARY,STRING,Dictionary,to_json,varray());
-
ADDFUNC0(ARRAY,INT,Array,size,varray());
ADDFUNC0(ARRAY,BOOL,Array,empty,varray());
ADDFUNC0(ARRAY,NIL,Array,clear,varray());