// Gets information about the interpreter runtime stack. // // This function fills parts of a Debug structure with an identification of // the activation record of the function executing at a given level. Level // 0 is the current running function, whereas level n+1 is the function that // has called level n. When there are no errors, Getstack returns nil; when // called with a level greater than the stack depth, it returns the error. func (d *Debug) Getstack(level int) error { if int(C.lua_getstack(d.l, C.int(level), d.d)) == 0 { return errors.New("stack depth exceeded") } d.update() return nil }
// Returns the current stack trace func (L *State) StackTrace() []LuaStackEntry { r := []LuaStackEntry{} var d C.lua_Debug Sln := C.CString("Sln") defer C.free(unsafe.Pointer(Sln)) for depth := 0; C.lua_getstack(L.s, C.int(depth), &d) > 0; depth++ { C.lua_getinfo(L.s, Sln, &d) ssb := make([]byte, C.LUA_IDSIZE) for i := 0; i < C.LUA_IDSIZE; i++ { ssb[i] = byte(d.short_src[i]) if ssb[i] == 0 { ssb = ssb[:i] break } } ss := string(ssb) r = append(r, LuaStackEntry{C.GoString(d.name), C.GoString(d.source), ss, int(d.currentline)}) } return r }