当前位置: 首页>>代码示例>>Golang>>正文


Golang State.LGetMetaTable方法代码示例

本文整理汇总了Golang中github.com/aarzilli/golua/lua.State.LGetMetaTable方法的典型用法代码示例。如果您正苦于以下问题:Golang State.LGetMetaTable方法的具体用法?Golang State.LGetMetaTable怎么用?Golang State.LGetMetaTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/aarzilli/golua/lua.State的用法示例。


在下文中一共展示了State.LGetMetaTable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: MessThingIndex

func MessThingIndex(state *lua.State) int {
	log.Println("HEY WE MADE IT")
	printStackTypes(state)

	state.GetMetaTable(1)
	state.LGetMetaTable(ThingMetaTableName)
	isThing := state.RawEqual(-1, -2)
	state.Pop(2)
	if !isThing {
		log.Println("!!! OMG ARG #1 IS NOT A MESS.THING !!!")
	}

	fieldName := state.CheckString(2)
	log.Println("Arg #2 checks out, it's a string")
	thing := checkThing(state, 1)
	log.Println("So we're tryin'a look up", fieldName, "on thing", thing.Id)

	if member, ok := MessThingMembers[fieldName]; ok {
		return member(state, thing)
	}

	// That wasn't one of our members, so look it up in our Table.
	if data, ok := thing.Table[fieldName]; ok {
		// TODO: instead of pushing a whole map if the script asks for one, maybe we should use another kind of userdata that tracks the name & can access its submembers until the script asks for the leaf (or a non-existent branch)?
		pushValue(state, data)
		return 1
	}

	// uh... I guess we didn't do anything, so...?
	return 0
}
开发者ID:natmeox,项目名称:mess,代码行数:31,代码来源:softcode.go

示例2: makeValueProxy

func makeValueProxy(L *lua.State, val reflect.Value, proxyMT string) {
	rawptr := L.NewUserdata(uintptr(unsafe.Sizeof(ValueProxy{})))
	ptr := (*ValueProxy)(rawptr)
	ptr.value = val
	ptr.t = val.Type()
	L.LGetMetaTable(proxyMT)
	L.SetMetaTable(-2)
}
开发者ID:kdar,项目名称:luar,代码行数:8,代码来源:luar.go

示例3: pushValue

func pushValue(state *lua.State, value interface{}) error {
	switch v := value.(type) {
	default:
		return fmt.Errorf("An item of unknown type was included in the environment or arguments of a Lua call (skipping it): %v",
			value)
	case nil:
		log.Println("Pushing nil onto lua stack")
		state.PushNil()
	case string:
		log.Println("Pushing string onto lua stack")
		state.PushString(v)
	case int:
		log.Println("Pushing int onto lua stack")
		state.PushInteger(int64(v))
	case int64:
		log.Println("Pushing int64 onto lua stack")
		state.PushInteger(v)
	case float64:
		log.Println("Pushing float64 onto lua stack")
		state.PushNumber(v)
	case bool:
		log.Println("Pushing bool onto lua stack")
		state.PushBoolean(v)

	case map[string]interface{}:
		log.Println("Pushing map[string]interface{} onto lua stack")
		state.CreateTable(0, len(v))
		for name, value := range v {
			err := pushValue(state, value)
			if err != nil {
				// error means nothing was added to stack. So pop our new table so *we* leave nothing added to the stack.
				state.Pop(1)
				return err
			}
			state.SetField(-2, name)
		}
		// then leave the table on the stack

	case ThingType:
		// These are singleton sentinel values, so load them from Lua-land.
		state.GetGlobal("world")
		state.GetField(-1, strings.Title(v.String()))
		state.Remove(-2)

	case *Thing:
		log.Println("Pushing *Thing onto lua stack")
		return pushValue(state, v.Id)
	case ThingId:
		log.Println("Pushing ThingId onto lua stack")
		// We're pushing a ThingId, so make a new userdata for it, with the Thing metatable.
		userdata := state.NewUserdata(uintptr(unsafe.Sizeof(int64(0))))
		thingPtr := (*int64)(userdata)
		*thingPtr = int64(v)
		if !state.IsUserdata(-1) {
			log.Println("!!! HOGAD JUST PUSHED NEW USERDATA BUT IT ISN'T OMG !!!")
		}
		log.Println("Pushed ThingId", *thingPtr, "onto lua stack")

		// Now make it act like a Thing.
		state.LGetMetaTable(ThingMetaTableName) // ( udata -- udata mtbl )
		state.SetMetaTable(-2)                  // ( udata mtbl -- udata )

		// Let's just check that it's that, for sures.
		if !state.IsUserdata(-1) {
			log.Println("!!! WOOP WOOP DID NOT SET METATABLE RIGHT :( !!!")
		}
	}
	return nil
}
开发者ID:natmeox,项目名称:mess,代码行数:69,代码来源:softcode.go


注:本文中的github.com/aarzilli/golua/lua.State.LGetMetaTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。