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


Golang C.lua_rawget函數代碼示例

本文整理匯總了Golang中C.lua_rawget函數的典型用法代碼示例。如果您正苦於以下問題:Golang lua_rawget函數的具體用法?Golang lua_rawget怎麽用?Golang lua_rawget使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了lua_rawget函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RegisterFunction

func (self *Lua) RegisterFunction(name string, fun interface{}) {
	path := strings.Split(name, ".")
	name = path[len(path)-1]
	path = path[0 : len(path)-1]
	if len(path) == 0 {
		path = append(path, "_G")
	}

	// ensure namespaces
	for i, namespace := range path {
		cNamespace := cstr(namespace)
		if i == 0 { // top namespace
			what := C.lua_getglobal(self.State, cNamespace)
			if what == C.LUA_TNIL { // not exists
				C.lua_settop(self.State, -2)
				C.lua_createtable(self.State, 0, 0)
				C.lua_setglobal(self.State, cNamespace)
				C.lua_getglobal(self.State, cNamespace)
			}
			if C.lua_type(self.State, -1) != C.LUA_TTABLE {
				self.Panic("global %s is not a table", namespace)
			}
		} else { // sub namespace
			C.lua_pushstring(self.State, cNamespace)
			C.lua_rawget(self.State, -2)
			if C.lua_type(self.State, -1) == C.LUA_TNIL {
				C.lua_settop(self.State, -2)
				C.lua_pushstring(self.State, cNamespace)
				C.lua_createtable(self.State, 0, 0)
				C.lua_rawset(self.State, -3)
				C.lua_pushstring(self.State, cNamespace)
				C.lua_rawget(self.State, -2)
			}
			if C.lua_type(self.State, -1) != C.LUA_TTABLE {
				self.Panic("namespace %s is not a table", namespace)
			}
		}
	}

	// register function
	funcType := reflect.TypeOf(fun)
	if funcType.IsVariadic() {
		self.Panic("cannot register variadic function: %v", fun)
	}
	argc := funcType.NumIn()
	cName := cstr(name)
	function := &Function{
		fun:       fun,
		lua:       self,
		name:      name,
		funcType:  funcType,
		funcValue: reflect.ValueOf(fun),
		argc:      argc,
	}
	funcId := rand.Int63()
	functionRegister.Set(funcId, function)
	C.register_function(self.State, cName, (C.int64_t)(funcId))
	self.Functions[name] = function
	C.lua_settop(self.State, -2)
}
開發者ID:reusee,項目名稱:lgo,代碼行數:60,代碼來源:lgo.go

示例2: RawGet

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

示例3: Rawget

// Similar to Gettable, but does a raw access (i.e., without metamethods).
func (this *State) Rawget(index int) {
	C.lua_rawget(this.luastate, C.int(index))
}
開發者ID:rdlaitila,項目名稱:leaf,代碼行數:4,代碼來源:State.go

示例4: Rawget

// Similar to Gettable, but does a raw access (i.e., without metamethods).
func (s *State) Rawget(index int) {
	C.lua_rawget(s.l, C.int(index))
}
開發者ID:halturin,項目名稱:luajit,代碼行數:4,代碼來源:state.go


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