MCPcopy Index your code
hub / github.com/yuin/gopher-lua / stackTrace

Method stackTrace

_state.go:695–722  ·  view source on GitHub ↗
(level int)

Source from the content-addressed store, hash-verified

693}
694
695func (ls *LState) stackTrace(level int) string {
696 buf := []string{}
697 header := "stack traceback:"
698 if ls.currentFrame != nil {
699 i := 0
700 for dbg, ok := ls.GetStack(i); ok; dbg, ok = ls.GetStack(i) {
701 cf := dbg.frame
702 buf = append(buf, fmt.Sprintf("\t%v in %v", ls.Where(i), ls.formattedFrameFuncName(cf)))
703 if !cf.Fn.IsG && cf.TailCall > 0 {
704 for tc := cf.TailCall; tc > 0; tc-- {
705 buf = append(buf, "\t(tailcall): ?")
706 i++
707 }
708 }
709 i++
710 }
711 }
712 buf = append(buf, fmt.Sprintf("\t%v: %v", "[G]", "?"))
713 buf = buf[intMax(0, intMin(level, len(buf))):len(buf)]
714 if len(buf) > 20 {
715 newbuf := make([]string, 0, 20)
716 newbuf = append(newbuf, buf[0:7]...)
717 newbuf = append(newbuf, "\t...")
718 newbuf = append(newbuf, buf[len(buf)-7:len(buf)]...)
719 buf = newbuf
720 }
721 return fmt.Sprintf("%s\n%s", header, strings.Join(buf, "\n"))
722}
723
724func (ls *LState) formattedFrameFuncName(fr *callFrame) string {
725 name, ischunk := ls.frameFuncName(fr)

Callers 2

PCallMethod · 0.95
panicWithTracebackFunction · 0.45

Calls 5

GetStackMethod · 0.95
WhereMethod · 0.95
intMaxFunction · 0.85
intMinFunction · 0.85

Tested by

no test coverage detected