diff options
Diffstat (limited to 'modules/gdscript')
-rw-r--r-- | modules/gdscript/gd_compiler.cpp | 3 | ||||
-rw-r--r-- | modules/gdscript/gd_functions.cpp | 66 | ||||
-rw-r--r-- | modules/gdscript/gd_functions.h | 2 | ||||
-rw-r--r-- | modules/gdscript/gd_parser.cpp | 7 | ||||
-rw-r--r-- | modules/gdscript/gd_script.cpp | 51 | ||||
-rw-r--r-- | modules/gdscript/gd_script.h | 2 | ||||
-rw-r--r-- | modules/gdscript/gd_tokenizer.cpp | 5 | ||||
-rw-r--r-- | modules/gdscript/gd_tokenizer.h | 1 |
8 files changed, 118 insertions, 19 deletions
diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp index 6180c668ef..53519030fc 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gd_compiler.cpp @@ -1253,6 +1253,7 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode * StringName func_name; if (p_func) { + if (p_func->default_values.size()) { codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_TO_DEF_ARGUMENT); @@ -1346,7 +1347,7 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode * if (defarg_addr.size()) { gdfunc->default_arguments=defarg_addr; - gdfunc->_default_arg_count=defarg_addr.size(); + gdfunc->_default_arg_count=defarg_addr.size()-1; gdfunc->_default_arg_ptr=&gdfunc->default_arguments[0]; } else { gdfunc->_default_arg_count=0; 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_parser.cpp b/modules/gdscript/gd_parser.cpp index 73264b0a12..c4175e048d 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gd_parser.cpp @@ -267,6 +267,13 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_ constant->value=tokenizer->get_token_constant(); tokenizer->advance(); expr=constant; + } else if (tokenizer->get_token()==GDTokenizer::TK_CONST_PI) { + + //constant defined by tokenizer + ConstantNode *constant = alloc_node<ConstantNode>(); + constant->value=Math_PI; + tokenizer->advance(); + expr=constant; } else if (tokenizer->get_token()==GDTokenizer::TK_PR_PRELOAD) { //constant defined by tokenizer diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 9b9b0e4b8c..d753a9f167 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -33,17 +33,6 @@ #include "os/file_access.h" #include "io/file_access_encrypted.h" -/* TODO: - - *populate globals - *do checks as close to debugger as possible (but don't do debugger) - *const check plz - *check arguments and default arguments in GDFunction - -get property list in instance? - *missing opcodes - -const checks - -make thread safe - */ @@ -232,6 +221,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a r_err.error=Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; r_err.argument=_argument_count; + return Variant(); } else if (p_argcount < _argument_count - _default_arg_count) { @@ -1603,6 +1593,28 @@ void GDScript::_update_placeholder(PlaceHolderScriptInstance *p_placeholder) { }*/ #endif + +bool GDScript::get_property_default_value(const StringName& p_property, Variant &r_value) const { + +#ifdef TOOLS_ENABLED + + //for (const Map<StringName,Variant>::Element *I=member_default_values.front();I;I=I->next()) { + // print_line("\t"+String(String(I->key())+":"+String(I->get()))); + //} + const Map<StringName,Variant>::Element *E=member_default_values_cache.find(p_property); + if (E) { + r_value=E->get(); + return true; + } + + if (base_cache.is_valid()) { + return base_cache->get_property_default_value(p_property,r_value); + } +#endif + return false; + +} + ScriptInstance* GDScript::instance_create(Object *p_this) { @@ -1740,16 +1752,21 @@ bool GDScript::_update_exports() { } } - Ref<GDScript> bf = ResourceLoader::load(path); + if (path!=get_path()) { + + Ref<GDScript> bf = ResourceLoader::load(path); - if (bf.is_valid()) { + if (bf.is_valid()) { - //print_line("parent is: "+bf->get_path()); - base_cache=bf; - bf->inheriters_cache.insert(get_instance_ID()); + //print_line("parent is: "+bf->get_path()); + base_cache=bf; + bf->inheriters_cache.insert(get_instance_ID()); - //bf->_update_exports(p_instances,true,false); + //bf->_update_exports(p_instances,true,false); + } + } else { + ERR_PRINT(("Path extending itself in "+path).utf8().get_data()); } } diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h index 173997a1fe..cf8f762a86 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gd_script.h @@ -352,6 +352,8 @@ public: Vector<uint8_t> get_as_byte_code() const; + bool get_property_default_value(const StringName& p_property,Variant& r_value) const; + virtual ScriptLanguage *get_language() const; GDScript(); diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp index bebdef83aa..377ef06694 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gd_tokenizer.cpp @@ -111,6 +111,7 @@ const char* GDTokenizer::token_names[TK_MAX]={ "'?'", "':'", "'\\n'", +"PI", "Error", "EOF", "Cursor"}; @@ -260,6 +261,7 @@ void GDTokenizerText::_advance() { } INCPOS(1); + line++; while(GETCHAR(0)==' ' || GETCHAR(0)=='\t') { INCPOS(1); @@ -877,6 +879,7 @@ void GDTokenizerText::_advance() { {TK_CF_RETURN,"return"}, {TK_CF_PASS,"pass"}, {TK_SELF,"self"}, + {TK_CONST_PI,"PI"}, {TK_ERROR,NULL} }; @@ -1043,7 +1046,7 @@ void GDTokenizerText::advance(int p_amount) { ////////////////////////////////////////////////////////////////////////////////////////////////////// -#define BYTECODE_VERSION 8 +#define BYTECODE_VERSION 10 Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> & p_buffer) { diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h index bbd1ec5b72..aaff573090 100644 --- a/modules/gdscript/gd_tokenizer.h +++ b/modules/gdscript/gd_tokenizer.h @@ -119,6 +119,7 @@ public: TK_QUESTION_MARK, TK_COLON, TK_NEWLINE, + TK_CONST_PI, TK_ERROR, TK_EOF, TK_CURSOR, //used for code completion |