Skip to content

Instantly share code, notes, and snippets.

@polachok
Created June 25, 2014 21:28
Show Gist options
  • Save polachok/62a1532482bf9a1236a2 to your computer and use it in GitHub Desktop.
Save polachok/62a1532482bf9a1236a2 to your computer and use it in GitHub Desktop.
package main
// #include <stdlib.h>
// #include <lua5.1/lua.h>
// #include <lua5.1/lualib.h>
// #include <lua5.1/lauxlib.h>
// #cgo LDFLAGS: -llua5.1
import "C"
import "unsafe"
type Lua struct {
ptr *C.lua_State
}
func NewLuaInterp() (self *Lua) {
p := C.luaL_newstate()
C.luaopen_base(p)
return &Lua { ptr: p }
}
func (interp Lua) eval(s string) {
cs := C.CString(s)
C.luaL_loadstring(interp.ptr, cs)
C.lua_pcall(interp.ptr, 0, C.LUA_MULTRET, 0)
C.free(unsafe.Pointer(cs))
}
func main() {
lua := NewLuaInterp()
lua.eval(`print("HELLO WORLD")`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment