// Encodes a Go object into Msgpack and adds it to the function arguments. func (e *ExecutionEngine) encodeArgument(value interface{}) error { // Encode Go object into msgpack. buffer := new(bytes.Buffer) encoder := msgpack.NewEncoder(buffer) err := encoder.Encode(value) if err != nil { return err } // Push the msgpack data onto the Lua stack. data := buffer.String() cdata := C.CString(data) defer C.free(unsafe.Pointer(cdata)) C.lua_pushlstring(e.state, cdata, (C.size_t)(len(data))) // Convert the argument from msgpack into Lua. rc := C.mp_unpack(e.state) if rc != 1 { return errors.New("skyd.ExecutionEngine: Unable to msgpack encode Lua argument") } C.lua_remove(e.state, -2) return nil }
// lua_pushstring func (L *State) PushString(str string) { Cstr := C.CString(str) defer C.free(unsafe.Pointer(Cstr)) C.lua_pushlstring(L.s, Cstr, C.size_t(len(str))) }
func (L *State) PushBytes(b []byte) { C.lua_pushlstring(L.s, (*C.char)(unsafe.Pointer(&b[0])), C.size_t(len(b))) }
func pushBytesToLua(L *C.lua_State, bytes []byte) { h := (*reflect.SliceHeader)(unsafe.Pointer(&bytes)) data := unsafe.Pointer(h.Data) size := h.Len C.lua_pushlstring(L, (*C.char)(data), C.size_t(size)) }
func pushStringToLua(L *C.lua_State, str string) { s, n := stringToC(str) C.lua_pushlstring(L, s, n) }