Small update to DoString for stack discipline
This commit is contained in:
parent
146b0a51db
commit
7c79616cac
21
wrapper.go
21
wrapper.go
|
@ -70,9 +70,24 @@ func (s *State) DoString(str string) error {
|
||||||
|
|
||||||
if s.safeStack {
|
if s.safeStack {
|
||||||
return stackGuardErr(s, func() error {
|
return stackGuardErr(s, func() error {
|
||||||
return s.safeCall(func() C.int {
|
// Save the current stack size
|
||||||
return C.do_string(s.L, cstr)
|
initialTop := s.GetTop()
|
||||||
})
|
|
||||||
|
// Execute the string
|
||||||
|
status := C.do_string(s.L, cstr)
|
||||||
|
if status != 0 {
|
||||||
|
// In case of error, get error message from stack
|
||||||
|
errMsg := s.ToString(-1)
|
||||||
|
s.SetTop(initialTop) // Restore stack
|
||||||
|
return &LuaError{
|
||||||
|
Code: int(status),
|
||||||
|
Message: errMsg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return values are now on the stack above initialTop
|
||||||
|
// We don't pop them as they may be needed by the caller
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user