berry-lang / berry

A ultra-lightweight embedded scripting language optimized for microcontrollers.
https://berry-lang.github.io
MIT License
812 stars 97 forks source link

Add `debug.caller()` #390

Closed s-hadinger closed 8 months ago

s-hadinger commented 8 months ago

Add debug.caller()with the following semantics:

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