From 40abca541e331c213a5cc94c676d58b3ca84b7ad Mon Sep 17 00:00:00 2001 From: unwox Date: Mon, 8 Sep 2025 15:07:22 +0600 Subject: add native support for fennel --- luajit.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'luajit.go') diff --git a/luajit.go b/luajit.go index 373beb1..40b91ba 100644 --- a/luajit.go +++ b/luajit.go @@ -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() if !l.LoadFile(file) { @@ -319,8 +321,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() @@ -329,11 +334,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 } -- cgit v1.2.3