Search results

There are no results.

std.debug.stacktrace

Show source code
Hide source code
fn pub stacktrace(skip: Int) -> Array[StackFrame] {
  let trace = inko_process_stacktrace(_INKO.process)
  let len = inko_process_stacktrace_size(trace) as Int
  let max = len - skip
  let mut index = 0

  if max <= 0 { return [] }

  let frames = Array.with_capacity(max)

  while index < max {
    let path = Path.new(
      inko_process_stack_frame_path(_INKO.state, trace, index),
    )
    let name = inko_process_stack_frame_name(_INKO.state, trace, index)
    let line = inko_process_stack_frame_line(trace, index) as Int

    frames.push(StackFrame.new(path, name, line))
    index += 1
  }

  inko_process_stacktrace_drop(trace)
  frames
}
fn pub static stacktrace(skip: Int) -> Array[StackFrame]

Returns a stack trace leading up to the line that called this method.

The stack trace is returned in reverse order. This means that the most recent stack frame is the last value in the returned Array.

The skip argument specifies how many call frames to skip (from new to old). A value of 0 means no frames are skipped.

Example

Returning the trace of a method call:

import std.debug (stacktrace, StackFrame)

fn first {
  second
}

fn second {
  let frames = stacktrace(skip: 1)
  let frame = frames.get(frames.size - 1)

  frame.name # => 'second'
}