diff options
| author | unwox <me@unwox.com> | 2025-09-08 15:07:22 +0600 |
|---|---|---|
| committer | unwox <me@unwox.com> | 2025-09-08 15:22:13 +0600 |
| commit | 40abca541e331c213a5cc94c676d58b3ca84b7ad (patch) | |
| tree | d6becf38f191f1c8b8c670c1674bde51953149ce /luajit.go | |
| parent | 89fe6e4978e47254ae0c349d02cab6b267e5076f (diff) | |
add native support for fennel
Diffstat (limited to 'luajit.go')
| -rw-r--r-- | luajit.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() 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 } |
