-
-
Save polachok/62a1532482bf9a1236a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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