summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gd_editor.cpp2
-rw-r--r--modules/gdscript/gd_functions.cpp34
-rw-r--r--modules/gdscript/gd_functions.h2
-rw-r--r--modules/gdscript/gd_script.cpp8
-rw-r--r--modules/gdscript/gd_tokenizer.cpp7
5 files changed, 44 insertions, 9 deletions
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp
index 20cd09efd0..df091fbcc9 100644
--- a/modules/gdscript/gd_editor.cpp
+++ b/modules/gdscript/gd_editor.cpp
@@ -51,7 +51,7 @@ String GDScriptLanguage::get_template(const String& p_class_name, const String&
"# var a=2\n"+
"# var b=\"textvar\"\n\n"+
"func _ready():\n"+
- "\t# Initalization here\n"+
+ "\t# Initialization here\n"+
"\tpass\n"+
"\n"+
"\n";
diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp
index fcfbbb04da..f37b2f645a 100644
--- a/modules/gdscript/gd_functions.cpp
+++ b/modules/gdscript/gd_functions.cpp
@@ -89,6 +89,8 @@ const char *GDFunctions::get_func_name(Function p_func) {
"printt",
"printerr",
"printraw",
+ "var2str",
+ "str2var",
"range",
"load",
"inst2dict",
@@ -577,10 +579,23 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
r_ret=Variant();
} break;
+ case VAR_TO_STR: {
+ VALIDATE_ARG_COUNT(1);
+ r_ret=p_args[0]->get_construct_string();
+ } break;
+ case STR_TO_VAR: {
+ VALIDATE_ARG_COUNT(1);
+ if (p_args[0]->get_type()!=Variant::STRING) {
+ r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument=0;
+ r_error.expected=Variant::STRING;
+ r_ret=Variant();
+ return;
+ }
+ Variant::construct_from_string(*p_args[0],r_ret);
+ } break;
case GEN_RANGE: {
-
-
switch(p_arg_count) {
case 0: {
@@ -861,7 +876,6 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
}
}
-
r_ret = gdscr->_new(NULL,0,r_error);
} break;
@@ -1087,7 +1101,7 @@ MethodInfo GDFunctions::get_info(Function p_func) {
return mi;
} break;
case MATH_LERP: {
- MethodInfo mi("lerp",PropertyInfo(Variant::REAL,"a"),PropertyInfo(Variant::REAL,"b"), PropertyInfo(Variant::REAL,"c"));
+ MethodInfo mi("lerp",PropertyInfo(Variant::REAL,"from"),PropertyInfo(Variant::REAL,"to"), PropertyInfo(Variant::REAL,"weight"));
mi.return_val.type=Variant::REAL;
return mi;
} break;
@@ -1224,6 +1238,18 @@ MethodInfo GDFunctions::get_info(Function p_func) {
return mi;
} break;
+ case VAR_TO_STR: {
+ MethodInfo mi("var2str",PropertyInfo(Variant::NIL,"var"));
+ mi.return_val.type=Variant::STRING;
+ return mi;
+
+ } break;
+ case STR_TO_VAR: {
+
+ MethodInfo mi("str2var:var",PropertyInfo(Variant::STRING,"string"));
+ 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 340763fb8c..05ff6a2e73 100644
--- a/modules/gdscript/gd_functions.h
+++ b/modules/gdscript/gd_functions.h
@@ -85,6 +85,8 @@ public:
TEXT_PRINT_TABBED,
TEXT_PRINTERR,
TEXT_PRINTRAW,
+ VAR_TO_STR,
+ STR_TO_VAR,
GEN_RANGE,
RESOURCE_LOAD,
INST2DICT,
diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp
index 0aa115ffbc..06c746c4fb 100644
--- a/modules/gdscript/gd_script.cpp
+++ b/modules/gdscript/gd_script.cpp
@@ -337,9 +337,10 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
Variant::evaluate(op,*a,*b,*dst,valid);
if (!valid) {
- if (false && dst->get_type()==Variant::STRING) {
+ if (dst->get_type()==Variant::STRING) {
//return a string when invalid with the error
err_text=*dst;
+ err_text += " in operator '"+Variant::get_operator_name(op)+"'.";
} else {
err_text="Invalid operands '"+Variant::get_type_name(a->get_type())+"' and '"+Variant::get_type_name(b->get_type())+"' in operator '"+Variant::get_operator_name(op)+"'.";
}
@@ -2696,7 +2697,10 @@ Error ResourceFormatSaverGDScript::save(const String &p_path,const RES& p_resour
}
file->store_string(source);
-
+ if (file->get_error()!=OK && file->get_error()!=ERR_FILE_EOF) {
+ memdelete(file);
+ return ERR_CANT_CREATE;
+ }
file->close();
memdelete(file);
return OK;
diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp
index 6f968f2080..1979577a17 100644
--- a/modules/gdscript/gd_tokenizer.cpp
+++ b/modules/gdscript/gd_tokenizer.cpp
@@ -538,9 +538,12 @@ void GDTokenizerText::_advance() {
is_node_path=true;
case '\'':
- string_mode=STRING_SINGLE_QUOTE;
case '"': {
-
+
+ if (GETCHAR(0)=='\'')
+ string_mode=STRING_SINGLE_QUOTE;
+
+
int i=1;
if (string_mode==STRING_DOUBLE_QUOTE && GETCHAR(i)=='"' && GETCHAR(i+1)=='"') {
i+=2;