summaryrefslogtreecommitdiff
path: root/luajit.go
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2025-09-08 15:07:22 +0600
committerunwox <me@unwox.com>2025-09-08 15:22:13 +0600
commit40abca541e331c213a5cc94c676d58b3ca84b7ad (patch)
treed6becf38f191f1c8b8c670c1674bde51953149ce /luajit.go
parent89fe6e4978e47254ae0c349d02cab6b267e5076f (diff)
add native support for fennel
Diffstat (limited to 'luajit.go')
-rw-r--r--luajit.go12
1 files changed, 8 insertions, 4 deletions
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
}