diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-12 17:56:09 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-12 17:56:09 +0100 |
commit | 40b9c246b65010768bd3c87dd6162e07dabd6898 (patch) | |
tree | 9d23af55c18a30739634db122cd7d2abde0e00a1 /modules/gdscript | |
parent | 9332d17c87bf40fe23a4b5e958e019ac238ad6d1 (diff) | |
parent | e3e55b29cec2dd62f268f24c43c07886378607ad (diff) |
Merge pull request #71197 from adamscott/add-default-virtual-path-gdscript
Add default virtual `gdscript://` path to `GDScript` instances
Diffstat (limited to 'modules/gdscript')
-rw-r--r-- | modules/gdscript/gdscript.cpp | 4 | ||||
-rw-r--r-- | modules/gdscript/tests/scripts/runtime/features/gdscript.gd | 20 | ||||
-rw-r--r-- | modules/gdscript/tests/scripts/runtime/features/gdscript.out | 3 |
3 files changed, 26 insertions, 1 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 7b79c9cf7e..28f478e9cd 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1037,7 +1037,7 @@ String GDScript::get_script_path() const { } Error GDScript::load_source_code(const String &p_path) { - if (p_path.is_empty() || ResourceLoader::get_resource_type(p_path.get_slice("::", 0)) == "PackedScene") { + if (p_path.is_empty() || p_path.begins_with("gdscript://") || ResourceLoader::get_resource_type(p_path.get_slice("::", 0)) == "PackedScene") { return OK; } @@ -1363,6 +1363,8 @@ GDScript::GDScript() : GDScriptLanguage::get_singleton()->script_list.add(&script_list); } + + path = vformat("gdscript://%d.gd", get_instance_id()); } void GDScript::_save_orphaned_subclasses(GDScript::ClearData *p_clear_data) { diff --git a/modules/gdscript/tests/scripts/runtime/features/gdscript.gd b/modules/gdscript/tests/scripts/runtime/features/gdscript.gd new file mode 100644 index 0000000000..f2368643de --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/gdscript.gd @@ -0,0 +1,20 @@ +func test(): + var gdscr: = GDScript.new() + gdscr.source_code = ''' +extends Resource + +func test() -> void: + prints("Outer") + var inner = InnerClass.new() + +class InnerClass: + func _init() -> void: + prints("Inner") +''' + @warning_ignore(return_value_discarded) + gdscr.reload() + + var inst = gdscr.new() + + @warning_ignore(unsafe_method_access) + inst.test() diff --git a/modules/gdscript/tests/scripts/runtime/features/gdscript.out b/modules/gdscript/tests/scripts/runtime/features/gdscript.out new file mode 100644 index 0000000000..16114f57f7 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/gdscript.out @@ -0,0 +1,3 @@ +GDTEST_OK +Outer +Inner |