From b2ce682f6ed9493423be257a5b2e87126692a94f Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 25 Feb 2014 09:31:47 -0300 Subject: -scripts are converted to bytecode on export -fix bug in doc where touchscreen events were not documented --- modules/gdscript/gd_script.cpp | 79 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 10 deletions(-) (limited to 'modules/gdscript/gd_script.cpp') diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 5679e1e066..29857e6be6 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -1416,7 +1416,7 @@ Error GDScript::reload() { String basedir=path; if (basedir=="") - basedir==get_path(); + basedir=get_path(); if (basedir!="") basedir=basedir.get_base_dir(); @@ -1560,6 +1560,49 @@ void GDScript::_bind_methods() { } + + +Error GDScript::load_byte_code(const String& p_path) { + + Vector bytecode = FileAccess::get_file_as_array(p_path); + ERR_FAIL_COND_V(bytecode.size()==0,ERR_PARSE_ERROR); + path=p_path; + + String basedir=path; + + if (basedir=="") + basedir=get_path(); + + if (basedir!="") + basedir=basedir.get_base_dir(); + + valid=false; + GDParser parser; + Error err = parser.parse_bytecode(bytecode,basedir); + if (err) { + _err_print_error("GDScript::load_byte_code",path.empty()?"built-in":(const char*)path.utf8().get_data(),parser.get_error_line(),("Parse Error: "+parser.get_error()).utf8().get_data()); + ERR_FAIL_V(ERR_PARSE_ERROR); + } + + GDCompiler compiler; + err = compiler.compile(&parser,this); + + if (err) { + _err_print_error("GDScript::load_byte_code",path.empty()?"built-in":(const char*)path.utf8().get_data(),compiler.get_error_line(),("Compile Error: "+compiler.get_error()).utf8().get_data()); + ERR_FAIL_V(ERR_COMPILATION_FAILED); + } + + valid=true; + + for(Map >::Element *E=subclasses.front();E;E=E->next()) { + + _set_subclass_path(E->get(),path); + } + + return OK; +} + + Error GDScript::load_source_code(const String& p_path) { @@ -2153,24 +2196,39 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path,const String& p_orig Ref scriptres(script); - Error err = script->load_source_code(p_path); + if (p_path.ends_with(".gdc")) { - if (err!=OK) { + script->set_script_path(p_original_path); // script needs this. + script->set_path(p_original_path); + Error err = script->load_byte_code(p_path); - ERR_FAIL_COND_V(err!=OK, RES()); - } - script->set_script_path(p_original_path); // script needs this. - script->set_path(p_original_path); - //script->set_name(p_path.get_file()); + if (err!=OK) { + + ERR_FAIL_COND_V(err!=OK, RES()); + } + + } else { + Error err = script->load_source_code(p_path); - script->reload(); + if (err!=OK) { + + ERR_FAIL_COND_V(err!=OK, RES()); + } + + script->set_script_path(p_original_path); // script needs this. + script->set_path(p_original_path); + //script->set_name(p_path.get_file()); + + script->reload(); + } return scriptres; } void ResourceFormatLoaderGDScript::get_recognized_extensions(List *p_extensions) const { p_extensions->push_back("gd"); + p_extensions->push_back("gdc"); } bool ResourceFormatLoaderGDScript::handles_type(const String& p_type) const { @@ -2180,7 +2238,8 @@ bool ResourceFormatLoaderGDScript::handles_type(const String& p_type) const { String ResourceFormatLoaderGDScript::get_resource_type(const String &p_path) const { - if (p_path.extension().to_lower()=="gd") + String el = p_path.extension().to_lower(); + if (el=="gd" || el=="gdc") return "GDScript"; return ""; } -- cgit v1.2.3