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 debug.caller() #390

Merged
merged 2 commits into from
Jan 24, 2024
Merged

Add debug.caller() #390

merged 2 commits into from
Jan 24, 2024

Conversation

s-hadinger
Copy link
Contributor

Add debug.caller()with the following semantics:

  • debug.caller(nil) -> function or nil return current function
  • debug.caller(int) -> function or nil return the nth caller in chain (default is 1).

One typical use-case is to get the name of the current function, or the name of the caller function. Note: use introspect.name() to get the name of a function.

Example:

def guess_my_name()
    import debug
    import introspect
    var func = debug.caller()
    var func_name = introspect.name(func)
    print(func_name)
end
guess_my_name()
# prints: guess_my_name

@s-hadinger s-hadinger merged commit 6152b0b into berry-lang:master Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants