diff options
Diffstat (limited to 'lua.go')
| -rw-r--r-- | lua.go | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -66,6 +66,8 @@ func (l *Lua) Close() { } // Require loads and executes the file pushing results onto the Lua stack. +// FIXME: traceback handler remains dangling on the stack, we need to remove +// it somehow. func (l *Lua) Require(file string) error { l.PushTracebackHandler() err := l.LoadFile(file) @@ -326,8 +328,11 @@ func (l *Lua) Next() bool { return C.lua_next(l.l, -2) != 0 } -// LoadString loads and executes the code in the current Lua context. -func (l *Lua) LoadString(code string) error { +// LoadAndCall loads and calls the code in the current Lua context. Whatever +// the code returns is stored in the stack. To drop the results use l.Pop. +// FIXME: traceback handler remains dangling on the stack, we need to remove +// it somehow. +func (l *Lua) LoadAndCall(code string) error { cstr := C.CString(code) defer C.free(unsafe.Pointer(cstr)) l.PushTracebackHandler() @@ -336,11 +341,10 @@ func (l *Lua) LoadString(code string) error { l.Pop(1) return errors.New(errMsg) } - err := l.PCall(0, 0, -2) + err := l.PCall(0, C.LUA_MULTRET, -2) if err != nil { return err } - l.Pop(l.StackLen()) return nil } |
