當前位置: 首頁>>代碼示例>>Golang>>正文


Golang C.lua_remove函數代碼示例

本文整理匯總了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
}
開發者ID:reusee,項目名稱:lua,代碼行數:46,代碼來源:lua.go

示例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
}
開發者ID:ngocthanhit,項目名稱:sky,代碼行數:25,代碼來源:execution_engine.go

示例3: Remove

// lua_remove
func (L *State) Remove(index int) {
	C.lua_remove(L.s, C.int(index))
}
開發者ID:szll,項目名稱:golua,代碼行數:4,代碼來源:lua.go

示例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))
}
開發者ID:rdlaitila,項目名稱:leaf,代碼行數:6,代碼來源:State.go

示例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))
}
開發者ID:halturin,項目名稱:luajit,代碼行數:6,代碼來源:state.go


注:本文中的C.lua_remove函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。