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

Method stackTrace

state.go:795–822  ·  view source on GitHub ↗
(level int)

Source from the content-addressed store, hash-verified

793}
794
795func (ls *LState) stackTrace(level int) string {
796 buf := []string{}
797 header := "stack traceback:"
798 if ls.currentFrame != nil {
799 i := 0
800 for dbg, ok := ls.GetStack(i); ok; dbg, ok = ls.GetStack(i) {
801 cf := dbg.frame
802 buf = append(buf, fmt.Sprintf("\t%v in %v", ls.Where(i), ls.formattedFrameFuncName(cf)))
803 if !cf.Fn.IsG && cf.TailCall > 0 {
804 for tc := cf.TailCall; tc > 0; tc-- {
805 buf = append(buf, "\t(tailcall): ?")
806 i++
807 }
808 }
809 i++
810 }
811 }
812 buf = append(buf, fmt.Sprintf("\t%v: %v", "[G]", "?"))
813 buf = buf[intMax(0, intMin(level, len(buf))):len(buf)]
814 if len(buf) > 20 {
815 newbuf := make([]string, 0, 20)
816 newbuf = append(newbuf, buf[0:7]...)
817 newbuf = append(newbuf, "\t...")
818 newbuf = append(newbuf, buf[len(buf)-7:len(buf)]...)
819 buf = newbuf
820 }
821 return fmt.Sprintf("%s\n%s", header, strings.Join(buf, "\n"))
822}
823
824func (ls *LState) formattedFrameFuncName(fr *callFrame) string {
825 name, ischunk := ls.frameFuncName(fr)

Callers 3

PCallMethod · 0.95
debugTracebackFunction · 0.45
panicWithTracebackFunction · 0.45

Calls 5

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

Tested by

no test coverage detected