You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
GDScript: Update get_stack(), print_stack(), and print_debug()
This commit is contained in:
@@ -1,10 +1,28 @@
|
||||
@warning_ignore_start("unsafe_call_argument")
|
||||
|
||||
class_name Utils
|
||||
|
||||
|
||||
# `assert()` is not evaluated in non-debug builds. Do not use `assert()`
|
||||
# for anything other than testing the `assert()` itself.
|
||||
static func check(condition: Variant) -> void:
|
||||
if not condition:
|
||||
printerr("Check failed.")
|
||||
if condition:
|
||||
return
|
||||
|
||||
printerr("Check failed. Backtrace (most recent call first):")
|
||||
for stack: ScriptBacktrace in Engine.capture_script_backtraces():
|
||||
if stack.get_language_name() == "GDScript":
|
||||
var dir: String
|
||||
for i: int in stack.get_frame_count():
|
||||
if i == 0:
|
||||
dir = stack.get_frame_file(i).trim_suffix("utils.notest.gd")
|
||||
else:
|
||||
printerr(" %s:%d @ %s()" % [
|
||||
stack.get_frame_file(i).trim_prefix(dir),
|
||||
stack.get_frame_line(i),
|
||||
stack.get_frame_function(i),
|
||||
])
|
||||
break
|
||||
|
||||
|
||||
static func get_type(property: Dictionary, is_return: bool = false) -> String:
|
||||
@@ -34,7 +52,11 @@ static func get_type(property: Dictionary, is_return: bool = false) -> String:
|
||||
return type_string(property.type)
|
||||
|
||||
|
||||
static func get_property_signature(property: Dictionary, base: Object = null, is_static: bool = false) -> String:
|
||||
static func get_property_signature(
|
||||
property: Dictionary,
|
||||
base: Object = null,
|
||||
is_static: bool = false,
|
||||
) -> String:
|
||||
if property.usage & PROPERTY_USAGE_CATEGORY:
|
||||
return '@export_category("%s")' % str(property.name).c_escape()
|
||||
if property.usage & PROPERTY_USAGE_GROUP:
|
||||
@@ -88,13 +110,17 @@ static func get_human_readable_hint_string(property: Dictionary) -> String:
|
||||
return property.hint_string
|
||||
|
||||
|
||||
static func print_property_extended_info(property: Dictionary, base: Object = null, is_static: bool = false) -> void:
|
||||
static func print_property_extended_info(
|
||||
property: Dictionary,
|
||||
base: Object = null,
|
||||
is_static: bool = false,
|
||||
) -> void:
|
||||
print(get_property_signature(property, base, is_static))
|
||||
print(' hint=%s hint_string="%s" usage=%s class_name=&"%s"' % [
|
||||
get_property_hint_name(property.hint).trim_prefix("PROPERTY_HINT_"),
|
||||
get_human_readable_hint_string(property).c_escape(),
|
||||
get_property_usage_string(property.usage).replace("PROPERTY_USAGE_", ""),
|
||||
property.class_name.c_escape(),
|
||||
str(property.class_name).c_escape(),
|
||||
])
|
||||
|
||||
|
||||
@@ -107,7 +133,7 @@ static func get_method_signature(method: Dictionary, is_signal: bool = false) ->
|
||||
var args: Array[Dictionary] = method.args
|
||||
var default_args: Array = method.default_args
|
||||
var mandatory_argc: int = args.size() - default_args.size()
|
||||
for i in args.size():
|
||||
for i: int in args.size():
|
||||
if i > 0:
|
||||
result += ", "
|
||||
var arg: Dictionary = args[i]
|
||||
@@ -253,7 +279,7 @@ static func get_property_usage_string(usage: int) -> String:
|
||||
result += "PROPERTY_USAGE_DEFAULT|"
|
||||
usage &= ~PROPERTY_USAGE_DEFAULT
|
||||
|
||||
for flag in FLAGS:
|
||||
for flag: Array in FLAGS:
|
||||
if usage & flag[0]:
|
||||
result += flag[1] + "|"
|
||||
usage &= ~flag[0]
|
||||
|
||||
Reference in New Issue
Block a user