summaryrefslogtreecommitdiff
path: root/lua.go
diff options
context:
space:
mode:
Diffstat (limited to 'lua.go')
-rw-r--r--lua.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/lua.go b/lua.go
index 1c23126..f13a8cb 100644
--- a/lua.go
+++ b/lua.go
@@ -121,6 +121,23 @@ func (l *Lua) Next() bool {
return C.lua_next(l.l, -2) != 0
}
+func (l *Lua) LoadString(code string) error {
+ cstr := C.CString(code)
+ defer C.free(unsafe.Pointer(cstr))
+ if C.luaL_loadstring(l.l, cstr) != C.LUA_OK {
+ errMsg := l.ToString(-1)
+ l.Pop(1)
+ return errors.New(errMsg)
+ }
+ if !l.PCall(0, 0) {
+ errMsg := l.ToString(-1)
+ l.Pop(1)
+ return errors.New(errMsg)
+ }
+ l.Pop(l.StackLen())
+ return nil
+}
+
func (l *Lua) PushTableItem(key string) {
ckey := C.CString(key)
defer C.free(unsafe.Pointer(ckey))