godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
86.55k stars 19.27k forks source link

source_code property of inner classes should return source. #27292

Open AlexDarigan opened 5 years ago

AlexDarigan commented 5 years ago

3.1

The source_code property of scripts has been very helpful in parsing GDScripts dynamically for plugins. However when it comes to inner classes, the source_code will always return empty.

extends Node

class Example:
    func greet():
        print("Hello World")

func _ready():
    print(Example.source_code.empty())

Outputs true

Returning source_code for inner classes would be a huge benefit for more complex tool-making. It could also have the extra benefit of

var source = Inner.get_base_script().source_code

making more sense if dealing with non-inner class parents.

Calinou commented 3 years ago

I can reproduce this on 3.2.2 and https://github.com/godotengine/godot/commit/f97280a0127950f5ae7d2e38f239ab9633afb041.