本文整理匯總了Golang中C.lua_remove函數的典型用法代碼示例。如果您正苦於以下問題:Golang lua_remove函數的具體用法?Golang lua_remove怎麽用?Golang lua_remove使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了lua_remove函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Pcall
// Pcall calls a lua function. no panic
func (l *Lua) Pcall(fullname string, args ...interface{}) (returns []interface{}, err error) {
C.push_errfunc(l.State)
curTop := C.lua_gettop(l.State)
// get function
path := strings.Split(fullname, ".")
for i, name := range path {
if i == 0 {
C.lua_getfield(l.State, C.LUA_GLOBALSINDEX, cstr(name))
} else {
if C.lua_type(l.State, -1) != C.LUA_TTABLE {
return nil, fmt.Errorf("%s is not a function", fullname)
}
C.lua_pushstring(l.State, cstr(name))
C.lua_gettable(l.State, -2)
C.lua_remove(l.State, -2) // remove table
}
}
if C.lua_type(l.State, -1) != C.LUA_TFUNCTION {
return nil, fmt.Errorf("%s is not a function", fullname)
}
// args
for _, arg := range args {
l.pushGoValue(arg, "")
}
// call
l.err = nil
if ret := C.lua_pcall(l.State, C.int(len(args)), C.LUA_MULTRET, C.int(-(len(args))-2)); ret != 0 {
// error occured
return nil, fmt.Errorf("CALL ERROR: %s", C.GoString(C.lua_tolstring(l.State, -1, nil)))
} else if l.err != nil { // error raise by invokeGoFunc
return nil, l.err
} else {
// return values
nReturn := C.lua_gettop(l.State) - curTop
returns = make([]interface{}, int(nReturn))
for i := C.int(0); i < nReturn; i++ {
value, err := l.toGoValue(-1-i, interfaceType)
if err != nil {
return nil, err
}
returns[int(nReturn-1-i)] = value.Interface()
}
}
return
}
示例2: encodeArgument
// 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
}
示例3: Remove
// lua_remove
func (L *State) Remove(index int) {
C.lua_remove(L.s, C.int(index))
}
示例4: Remove
// Removes the element at the given valid index, shifting down the elements
// above this index to fill the gap. Cannot be called with a pseudo-index,
// because a pseudo-index is not an actual stack position.
func (this *State) Remove(index int) {
C.lua_remove(this.luastate, C.int(index))
}
示例5: Remove
// Removes the element at the given valid index, shifting down the elements
// above this index to fill the gap. Cannot be called with a pseudo-index,
// because a pseudo-index is not an actual stack position.
func (s *State) Remove(index int) {
C.lua_remove(s.l, C.int(index))
}