From 98b2068bca2a969990529f85c7a8003f7efc3293 Mon Sep 17 00:00:00 2001 From: kohkimakimoto Date: Mon, 25 Apr 2016 17:28:40 +0900 Subject: [PATCH] Issue #67 : fix a bug about `dofile` --- _state.go | 2 ++ baselib.go | 5 +++++ state.go | 2 ++ 3 files changed, 9 insertions(+) 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() } }()