diff --git a/_state.go b/_state.go index beafd8c4..40ebdb92 100644 --- a/_state.go +++ b/_state.go @@ -1571,6 +1571,8 @@ func (ls *LState) PCall(nargs, nret int, errfunc *LFunction) (err error) { ls.stack.SetSp(sp) if sp == 0 { ls.currentFrame = nil + } else { + ls.currentFrame = ls.stack.Last() } }() diff --git a/baselib.go b/baselib.go index bcba8e01..4757bd77 100644 --- a/baselib.go +++ b/baselib.go @@ -69,6 +69,11 @@ func baseDoFile(L *LState) int { src := L.ToString(1) top := L.GetTop() if err := L.DoFile(src); err != nil { + if _, ok := err.(*ApiError); ok { + // if the error is *ApiError, runs panic directly to prevent overriding a stacktrace in the error object. + panic(err) + } + L.RaiseError(err.Error()) } return L.GetTop() - top diff --git a/state.go b/state.go index 96f8e90e..9659d48c 100644 --- a/state.go +++ b/state.go @@ -1656,6 +1656,8 @@ func (ls *LState) PCall(nargs, nret int, errfunc *LFunction) (err error) { ls.stack.SetSp(sp) if sp == 0 { ls.currentFrame = nil + } else { + ls.currentFrame = ls.stack.Last() } }()