Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new get_stack function to get GDScript stack trace as array #18976

Merged
merged 1 commit into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions modules/gdscript/gdscript_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const char *GDScriptFunctions::get_func_name(Function p_func) {
"Color8",
"ColorN",
"print_stack",
"get_stack",
"instance_from_id",
"len",
"is_instance_valid",
Expand Down Expand Up @@ -1213,6 +1214,22 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
};
} break;

case GET_STACK: {
VALIDATE_ARG_COUNT(0);

ScriptLanguage *script = GDScriptLanguage::get_singleton();
Array ret;
for (int i = 0; i < script->debug_get_stack_level_count(); i++) {

Dictionary frame;
frame["source"] = script->debug_get_stack_level_source(i);
frame["function"] = script->debug_get_stack_level_function(i);
frame["line"] = script->debug_get_stack_level_line(i);
ret.push_back(frame);
};
r_ret = ret;
} break;

case INSTANCE_FROM_ID: {

VALIDATE_ARG_COUNT(1);
Expand Down Expand Up @@ -1813,6 +1830,11 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) {
mi.return_val.type = Variant::NIL;
return mi;
} break;
case GET_STACK: {
MethodInfo mi("get_stack");
mi.return_val.type = Variant::NIL;
return mi;
} break;

case INSTANCE_FROM_ID: {
MethodInfo mi("instance_from_id", PropertyInfo(Variant::INT, "instance_id"));
Expand Down
1 change: 1 addition & 0 deletions modules/gdscript/gdscript_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class GDScriptFunctions {
COLOR8,
COLORN,
PRINT_STACK,
GET_STACK,
INSTANCE_FROM_ID,
LEN,
IS_INSTANCE_VALID,
Expand Down