diff --git a/stack.go b/stack.go index 2570a54..3f45799 100644 --- a/stack.go +++ b/stack.go @@ -1,6 +1,9 @@ package lua -import "log" +import ( + "fmt" + "log" +) func (l *State) push(v value) { l.stack[l.top] = v @@ -406,7 +409,10 @@ func (l *State) protect(f func()) (err error) { nestedGoCallCount, protectFunction := l.nestedGoCallCount, l.protectFunction l.protectFunction = func() { if e := recover(); e != nil { - err = e.(error) + var ok bool + if err, ok = e.(error); !ok { + err = fmt.Errorf("%v", e) + } l.nestedGoCallCount, l.protectFunction = nestedGoCallCount, protectFunction } } diff --git a/vm_test.go b/vm_test.go index e78570c..df385ba 100644 --- a/vm_test.go +++ b/vm_test.go @@ -351,6 +351,15 @@ func TestErrorf(t *testing.T) { } } +func TestPanicWithString(t *testing.T) { + l := NewState() + OpenLibraries(l) + LoadString(l, "debug.gethook()") + if err := l.ProtectedCall(0, 0, 0); err == nil { + t.Fatal("expected an error, got none") + } +} + func TestPairsSplit(t *testing.T) { testString(t, ` local t = {}