Esempio n. 1
0
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
}
Esempio n. 2
0
func checkThing(state *lua.State, argNum int) *Thing {
	userdata := state.CheckUdata(argNum, ThingMetaTableName)
	if userdata == nil {
		state.ArgError(argNum, "`Thing` expected")
	}

	var thingPtr *int64
	thingPtr = (*int64)(userdata)
	thingId := ThingId(*thingPtr)

	thing := World.ThingForId(thingId)
	if thing == nil {
		state.ArgError(argNum, "`Thing` argument is no longer valid")
	}

	return thing
}
Esempio n. 3
0
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
}