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


Golang State.CheckString方法代码示例

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


在下文中一共展示了State.CheckString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: MessThingTellallMethod

func MessThingTellallMethod(state *lua.State, thing *Thing) int {
	state.PushGoFunction(func(state *lua.State) int {
		place := checkThing(state, 1)
		text := state.CheckString(2)

		// If arg 3 is present, it should be a table of Things to exclude.
		excludes := make(map[ThingId]bool)
		if 2 < state.GetTop() {
			if !state.IsTable(3) {
				state.ArgError(3, "expected `table` for exclude argument if present")
			}
			numExcludes := int(state.ObjLen(3))
			for i := 0; i < numExcludes; i++ {
				state.RawGeti(3, i+1)
				exclude := checkThing(state, -1)
				excludes[exclude.Id] = true
			}
		}

		for _, content := range place.GetContents() {
			if excludes[content.Id] {
				continue
			}
			if content.Client != nil {
				content.Client.Send(text)
			}
		}

		return 0
	})
	return 1
}
开发者ID:natmeox,项目名称:mess,代码行数:32,代码来源:softcode.go

示例3: MessThingTellMethod

func MessThingTellMethod(state *lua.State, thing *Thing) int {
	state.PushGoFunction(func(state *lua.State) int {
		thing := checkThing(state, 1)
		text := state.CheckString(2)

		if thing.Client != nil {
			thing.Client.Send(text)
		}
		state.Pop(2) // ( udataThing strText -- )
		return 0
	})
	return 1
}
开发者ID:natmeox,项目名称:mess,代码行数:13,代码来源:softcode.go

示例4: MessThingFindinsideMethod

func MessThingFindinsideMethod(state *lua.State, thing *Thing) int {
	state.PushGoFunction(func(state *lua.State) int {
		thing := checkThing(state, 1)
		text := state.CheckString(2)
		if text == "" {
			state.ArgError(2, "cannot find empty string")
		}

		otherThing := thing.FindInside(text)
		if otherThing == nil {
			return 0
		}
		pushValue(state, otherThing.Id)
		return 1
	})
	return 1
}
开发者ID:natmeox,项目名称:mess,代码行数:17,代码来源:softcode.go

示例5: MessThingPronounsubMethod

func MessThingPronounsubMethod(state *lua.State, thing *Thing) int {
	state.PushGoFunction(func(state *lua.State) int {
		thing := checkThing(state, 1)
		text := state.CheckString(2)

		for code, pronoun := range thing.Pronouns() {
			lowerCode := fmt.Sprintf(`%%%s`, code)
			upperCode := fmt.Sprintf(`%%%s`, strings.ToUpper(code))
			text = strings.Replace(text, lowerCode, pronoun, -1)
			text = strings.Replace(text, upperCode, strings.ToTitle(pronoun), -1)
		}

		text = strings.Replace(text, `%n`, thing.Name, -1)
		text = strings.Replace(text, `%N`, thing.Name, -1)

		state.Pop(2)           // ( udataThing str -- )
		state.PushString(text) // ( -- str' )
		return 1
	})
	return 1
}
开发者ID:natmeox,项目名称:mess,代码行数:21,代码来源:softcode.go

示例6: apiOn

func (p *Plugin) apiOn(l *lua.State) int {
	event := strings.ToLower(l.CheckString(1))
	function := luar.NewLuaObject(l, 2)
	p.listeners[event] = append(p.listeners[event], function)
	return 0
}
开发者ID:mgalvey,项目名称:piepan,代码行数:6,代码来源:plugin.go


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