summaryrefslogtreecommitdiffstats
path: root/modules/mono/csharp_script.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mono/csharp_script.cpp')
-rw-r--r--modules/mono/csharp_script.cpp46
1 files changed, 28 insertions, 18 deletions
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index e08491729b..93fb5f1dc6 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -307,7 +307,7 @@ void CSharpLanguage::get_reserved_words(List<String> *p_words) const {
}
}
-bool CSharpLanguage::is_control_flow_keyword(String p_keyword) const {
+bool CSharpLanguage::is_control_flow_keyword(const String &p_keyword) const {
return p_keyword == "break" ||
p_keyword == "case" ||
p_keyword == "catch" ||
@@ -405,6 +405,10 @@ bool CSharpLanguage::supports_builtin_mode() const {
return false;
}
+ScriptLanguage::ScriptNameCasing CSharpLanguage::preferred_file_name_casing() const {
+ return SCRIPT_NAME_CASING_PASCAL_CASE;
+}
+
#ifdef TOOLS_ENABLED
struct VariantCsName {
Variant::Type variant_type;
@@ -516,22 +520,11 @@ static String variant_type_to_managed_name(const String &p_var_type_name) {
}
String CSharpLanguage::make_function(const String &, const String &p_name, const PackedStringArray &p_args) const {
- // FIXME
- // - Due to Godot's API limitation this just appends the function to the end of the file
- // - Use fully qualified name if there is ambiguity
- String s = "private void " + p_name + "(";
- for (int i = 0; i < p_args.size(); i++) {
- const String &arg = p_args[i];
-
- if (i > 0) {
- s += ", ";
- }
-
- s += variant_type_to_managed_name(arg.get_slice(":", 1)) + " " + escape_csharp_keyword(arg.get_slice(":", 0));
- }
- s += ")\n{\n // Replace with function body.\n}\n";
-
- return s;
+ // The make_function() API does not work for C# scripts.
+ // It will always append the generated function at the very end of the script. In C#, it will break compilation by
+ // appending code after the final closing bracket (either the class' or the namespace's).
+ // To prevent issues, we have can_make_function() returning false, and make_function() is never implemented.
+ return String();
}
#else
String CSharpLanguage::make_function(const String &, const String &, const PackedStringArray &) const {
@@ -2862,7 +2855,24 @@ Ref<Resource> ResourceFormatLoaderCSharpScript::load(const String &p_path, const
ERR_FAIL_COND_V_MSG(!scr->get_path().is_empty() && scr->get_path() != p_original_path, Ref<Resource>(),
"The C# script path is different from the path it was registered in the C# dictionary.");
- scr->set_path(p_original_path, true);
+ Ref<Resource> existing = ResourceCache::get_ref(p_path);
+ switch (p_cache_mode) {
+ case ResourceFormatLoader::CACHE_MODE_IGNORE:
+ case ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP:
+ break;
+ case ResourceFormatLoader::CACHE_MODE_REUSE:
+ if (existing.is_null()) {
+ scr->set_path(p_original_path);
+ } else {
+ scr = existing;
+ }
+ break;
+ case ResourceFormatLoader::CACHE_MODE_REPLACE:
+ case ResourceFormatLoader::CACHE_MODE_REPLACE_DEEP:
+ scr->set_path(p_original_path, true);
+ break;
+ }
+
scr->reload();
if (r_error) {