diff options
-rw-r--r-- | modules/gdscript/gd_functions.cpp | 66 | ||||
-rw-r--r-- | modules/gdscript/gd_functions.h | 2 | ||||
-rw-r--r-- | modules/gdscript/gd_tokenizer.cpp | 2 | ||||
-rw-r--r-- | tools/doc/doc_data.cpp | 8 |
4 files changed, 75 insertions, 3 deletions
diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index 11bb3a859a..e015ddb65e 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -34,6 +34,7 @@ #include "func_ref.h" #include "os/os.h" #include "variant_parser.h" +#include "io/marshalls.h" const char *GDFunctions::get_func_name(Function p_func) { @@ -94,6 +95,8 @@ const char *GDFunctions::get_func_name(Function p_func) { "printraw", "var2str", "str2var", + "var2bytes", + "bytes2var", "range", "load", "inst2dict", @@ -639,6 +642,57 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va } } break; + case VAR_TO_BYTES: { + VALIDATE_ARG_COUNT(1); + + ByteArray barr; + int len; + Error err = encode_variant(*p_args[0],NULL,len); + if (err) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::NIL; + r_ret=Variant(); + return; + } + + barr.resize(len); + { + ByteArray::Write w = barr.write(); + encode_variant(*p_args[0],w.ptr(),len); + + } + r_ret=barr; + } break; + case BYTES_TO_VAR: { + VALIDATE_ARG_COUNT(1); + if (p_args[0]->get_type()!=Variant::RAW_ARRAY) { + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::RAW_ARRAY; + r_ret=Variant(); + return; + } + + ByteArray varr=*p_args[0]; + Variant ret; + { + ByteArray::Read r=varr.read(); + Error err = decode_variant(ret,r.ptr(),varr.size(),NULL); + if (err!=OK) { + ERR_PRINT("Not enough bytes for decoding.."); + r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument=0; + r_error.expected=Variant::RAW_ARRAY; + r_ret=Variant(); + return; + } + + } + + r_ret=ret; + + } break; case GEN_RANGE: { switch(p_arg_count) { @@ -1358,6 +1412,18 @@ MethodInfo GDFunctions::get_info(Function p_func) { mi.return_val.type=Variant::NIL; return mi; } break; + case VAR_TO_BYTES: { + MethodInfo mi("var2bytes",PropertyInfo(Variant::NIL,"var")); + mi.return_val.type=Variant::RAW_ARRAY; + return mi; + + } break; + case BYTES_TO_VAR: { + + MethodInfo mi("bytes2var:Variant",PropertyInfo(Variant::RAW_ARRAY,"bytes")); + mi.return_val.type=Variant::NIL; + return mi; + } break; case GEN_RANGE: { MethodInfo mi("range",PropertyInfo(Variant::NIL,"...")); diff --git a/modules/gdscript/gd_functions.h b/modules/gdscript/gd_functions.h index e6ef8b9ec8..8c88472567 100644 --- a/modules/gdscript/gd_functions.h +++ b/modules/gdscript/gd_functions.h @@ -89,6 +89,8 @@ public: TEXT_PRINTRAW, VAR_TO_STR, STR_TO_VAR, + VAR_TO_BYTES, + BYTES_TO_VAR, GEN_RANGE, RESOURCE_LOAD, INST2DICT, diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index 4280c47edf..377ef06694 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -1046,7 +1046,7 @@ void GDTokenizerText::advance(int p_amount) { ////////////////////////////////////////////////////////////////////////////////////////////////////// -#define BYTECODE_VERSION 9 +#define BYTECODE_VERSION 10 Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> & p_buffer) { diff --git a/tools/doc/doc_data.cpp b/tools/doc/doc_data.cpp index 96fd3f6b68..a039c58ff4 100644 --- a/tools/doc/doc_data.cpp +++ b/tools/doc/doc_data.cpp @@ -584,7 +584,10 @@ void DocData::generate(bool p_basic_types) { md.name=mi.name; if (mi.return_val.name!="") md.return_type=mi.return_val.name; - else + else if (mi.name.find(":")!=-1) { + md.return_type=mi.name.get_slice(":",1); + md.name=mi.name.get_slice(":",0); + } else md.return_type=Variant::get_type_name(mi.return_val.type); for(int i=0;i<mi.arguments.size();i++) { @@ -594,8 +597,9 @@ void DocData::generate(bool p_basic_types) { ArgumentDoc ad; ad.name=pi.name; + if (pi.type==Variant::NIL) - ad.type="var"; + ad.type="Variant"; else ad.type=Variant::get_type_name( pi.type ); |