diff options
Diffstat (limited to 'lua.go')
| -rw-r--r-- | lua.go | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -58,12 +58,11 @@ func (l *Lua) Close() { // Require loads and executes the file pushing results onto the Lua stack. func (l *Lua) Require(file string) error { - if !l.LoadFile(file) { - errMsg := l.ToString(-1) - l.Pop(1) - return errors.New("could not open the file:\n" + errMsg) + err := l.LoadFile(file) + if err != nil { + return errors.New("could not open the file:\n" + err.Error()) } - err := l.PCall(0, C.LUA_MULTRET) + err = l.PCall(0, C.LUA_MULTRET) if err != nil { return errors.New("could not execute the file:\n" + err.Error()) } @@ -83,11 +82,16 @@ func (l *Lua) PCall(nargs int, nresults int) error { } // LoadFile loads the file code in the current Lua context. -func (l *Lua) LoadFile(file string) bool { +func (l *Lua) LoadFile(file string) error { cstr := C.CString(file) defer C.free(unsafe.Pointer(cstr)) res := C.luaL_loadfilex(l.l, cstr, nil) - return res == C.LUA_OK + if res != C.LUA_OK { + errMsg := l.ToString(-1) + l.Pop(1) + return errors.New(errMsg) + } + return nil } // StackLen returns the length of the Lua stack. |
