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


Golang State.IsBoolean方法代码示例

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


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

示例1: popMap

func popMap(L *lua.State) map[string]interface{} {
	m := make(map[string]interface{})
	L.PushNil()
	for L.Next(-2) != 0 {
		if L.IsString(-2) {
			var v interface{}
			if L.IsBoolean(-1) {
				v = L.ToBoolean(-1)
			} else if L.IsNumber(-1) {
				var t float64
				t = L.ToNumber(-1)
				if t == float64(int64(t)) {
					v = int(t)
				} else {
					v = t
				}
			} else if L.IsString(-1) {
				v = L.ToString(-1)
			} else if L.IsNil(-1) {
				v = nil
			} else if L.IsTable(-1) {
				v = popMap(L)
			}
			m[L.ToString(-2)] = v
		}
		L.Pop(1)
	}
	return m
}
开发者ID:12foo,项目名称:apiplexy,代码行数:29,代码来源:lua.go

示例2: LuaToGo


//.........这里部分代码省略.........
		case reflect.Uint8:
			{
				ptr := new(uint8)
				*ptr = uint8(L.ToNumber(idx))
				value = *ptr
			}
		case reflect.Uint16:
			{
				ptr := new(uint16)
				*ptr = uint16(L.ToNumber(idx))
				value = *ptr
			}
		case reflect.Uint32:
			{
				ptr := new(uint32)
				*ptr = uint32(L.ToNumber(idx))
				value = *ptr
			}
		case reflect.Uint64:
			{
				ptr := new(uint64)
				*ptr = uint64(L.ToNumber(idx))
				value = *ptr
			}
		default:
			cannotConvert(L, idx, "number", kind, t)
		}
	case lua.LUA_TTABLE:
		if t == nil {
			kind = reflect.Interface
		}
		fallthrough
	default:
		istable := L.IsTable(idx)
		// if we don't know the type and the Lua object is userdata,
		// then it might be a proxy for a Go object. Otherwise wrap
		// it up as a LuaObject.
		if t == nil && !istable {
			if isValueProxy(L, idx) {
				return unwrapProxy(L, idx)
			} else {
				return NewLuaObject(L, idx)
			}
		}
		switch kind {
		case reflect.Slice:
			{
				// if we get a table, then copy its values to a new slice
				if istable {
					value = CopyTableToSlice(L, t, idx)
				} else {
					value = unwrapProxyOrComplain(L, idx)
				}
			}
		case reflect.Map:
			{
				if istable {
					value = CopyTableToMap(L, t, idx)
				} else {
					value = unwrapProxyOrComplain(L, idx)
				}
			}
		case reflect.Struct:
			{
				if istable {
					value = CopyTableToStruct(L, t, idx)
				} else {
					value = unwrapProxyOrComplain(L, idx)
				}
			}
		case reflect.Interface:
			{
				if istable {
					// have to make an executive decision here: tables with non-zero
					// length are assumed to be slices!
					if L.ObjLen(idx) > 0 {
						value = CopyTableToSlice(L, nil, idx)
					} else {
						value = CopyTableToMap(L, nil, idx)
					}
				} else if L.IsNumber(idx) {
					value = L.ToNumber(idx)
				} else if L.IsString(idx) {
					value = L.ToString(idx)
				} else if L.IsBoolean(idx) {
					value = L.ToBoolean(idx)
				} else if L.IsNil(idx) {
					return nil
				} else {
					value = unwrapProxyOrComplain(L, idx)
				}
			}
		default:
			value = unwrapProxyOrComplain(L, idx)
			//cannotConvert(L,idx,"unknown",kind,t)
		}
	}

	return value
}
开发者ID:imvu,项目名称:Tetra,代码行数:101,代码来源:luar.go

示例3: luaToGo


//.........这里部分代码省略.........
			ptr := new(uint32)
			*ptr = uint32(L.ToNumber(idx))
			value = *ptr
		case reflect.Uint64:
			ptr := new(uint64)
			*ptr = uint64(L.ToNumber(idx))
			value = *ptr
		default:
			value = reflect.Zero(t).Interface()
		}
	case lua.LUA_TTABLE:
		if t == nil {
			kind = reflect.Interface
		}
		fallthrough
	default:
		istable := L.IsTable(idx)
		// If we don't know the type and the Lua object is userdata,
		// then it might be a proxy for a Go object. Otherwise wrap
		// it up as a LuaObject.
		if t == nil && !istable {
			if isValueProxy(L, idx) {
				v, _ := valueOfProxy(L, idx)
				return v.Interface()
			}
			return NewLuaObject(L, idx)
		}
		switch kind {
		case reflect.Array:
			if istable {
				ptr := L.ToPointer(idx)
				if val, ok := visited[ptr]; ok {
					return val
				}
				value = copyTableToSlice(L, t, idx, visited)
			} else {
				value = mustUnwrapProxy(L, idx)
			}
		case reflect.Slice:
			// if we get a table, then copy its values to a new slice
			if istable {
				ptr := L.ToPointer(idx)
				if val, ok := visited[ptr]; ok {
					return val
				}
				value = copyTableToSlice(L, t, idx, visited)
			} else {
				value = mustUnwrapProxy(L, idx)
			}
		case reflect.Map:
			if istable {
				ptr := L.ToPointer(idx)
				if val, ok := visited[ptr]; ok {
					return val
				}
				value = copyTableToMap(L, t, idx, visited)
			} else {
				value = mustUnwrapProxy(L, idx)
			}
		case reflect.Struct:
			if istable {
				ptr := L.ToPointer(idx)
				if val, ok := visited[ptr]; ok {
					return val
				}
				value = copyTableToStruct(L, t, idx, visited)
			} else {
				value = mustUnwrapProxy(L, idx)
			}
		case reflect.Interface:
			if istable {
				ptr := L.ToPointer(idx)
				if val, ok := visited[ptr]; ok {
					return val
				}
				// We have to make an executive decision here: tables with non-zero
				// length are assumed to be slices!
				if L.ObjLen(idx) > 0 {
					value = copyTableToSlice(L, nil, idx, visited)
				} else {
					value = copyTableToMap(L, nil, idx, visited)
				}
			} else if L.IsNumber(idx) {
				value = L.ToNumber(idx)
			} else if L.IsString(idx) {
				value = L.ToString(idx)
			} else if L.IsBoolean(idx) {
				value = L.ToBoolean(idx)
			} else if L.IsNil(idx) {
				return nil
			} else {
				value = mustUnwrapProxy(L, idx)
			}
		default:
			value = mustUnwrapProxy(L, idx)
		}
	}

	return value
}
开发者ID:stevedonovan,项目名称:luar,代码行数:101,代码来源:luar.go

示例4: LuaToGo


//.........这里部分代码省略.........
		}
	} else if t.Kind() == reflect.Ptr {
		kind = t.Elem().Kind()
	} else {
		kind = t.Kind()
	}

	switch kind {
	// various numerical types are tedious but straightforward
	case reflect.Float64:
		{
			ptr := new(float64)
			*ptr = L.ToNumber(idx)
			value = *ptr
		}
	case reflect.Float32:
		{
			ptr := new(float32)
			*ptr = float32(L.ToNumber(idx))
			value = *ptr
		}
	case reflect.Int:
		{
			ptr := new(int)
			*ptr = int(L.ToNumber(idx))
			value = *ptr
		}
	case reflect.Int8:
		{
			ptr := new(byte)
			*ptr = byte(L.ToNumber(idx))
			value = *ptr
		}
	case reflect.String:
		{
			tos := L.ToString(idx)
			ptr := new(string)
			*ptr = tos
			value = *ptr
		}
	case reflect.Bool:
		{
			ptr := new(bool)
			*ptr = bool(L.ToBoolean(idx))
			value = *ptr
		}
	case reflect.Slice:
		{
			// if we get a table, then copy its values to a new slice
			if L.IsTable(idx) {
				value = CopyTableToSlice(L, t, idx)
			} else {
				value = unwrapProxy(L, idx)
			}
		}
	case reflect.Map:
		{
			if L.IsTable(idx) {
				value = CopyTableToMap(L, t, idx)
			} else {
				value = unwrapProxy(L, idx)
			}
		}
	case reflect.Struct:
		{
			if L.IsTable(idx) {
				value = CopyTableToStruct(L, t, idx)
			} else {
				value = unwrapProxy(L, idx)
			}
		}
	case reflect.Interface:
		{
			if L.IsTable(idx) {
				// have to make an executive decision here: tables with non-zero
				// length are assumed to be slices!
				if L.ObjLen(idx) > 0 {
					value = CopyTableToSlice(L, nil, idx)
				} else {
					value = CopyTableToMap(L, nil, idx)
				}
			} else if L.IsNumber(idx) {
				value = L.ToNumber(idx)
			} else if L.IsString(idx) {
				value = L.ToString(idx)
			} else if L.IsBoolean(idx) {
				value = L.ToBoolean(idx)
			} else {
				value = unwrapProxy(L, idx)
			}
		}
	default:
		{
			fmt.Println("unhandled type", t)
			value = 20
		}

	}
	return value
}
开发者ID:kdar,项目名称:luar,代码行数:101,代码来源:luar.go


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