本文整理汇总了Golang中github.com/kdar/morphgen/golua/lua.State.ToBoolean方法的典型用法代码示例。如果您正苦于以下问题:Golang State.ToBoolean方法的具体用法?Golang State.ToBoolean怎么用?Golang State.ToBoolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/kdar/morphgen/golua/lua.State
的用法示例。
在下文中一共展示了State.ToBoolean方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}