本文整理匯總了Golang中C.lua_touserdata函數的典型用法代碼示例。如果您正苦於以下問題:Golang lua_touserdata函數的具體用法?Golang lua_touserdata怎麽用?Golang lua_touserdata使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了lua_touserdata函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ToUserdata
// lua_touserdata
func (L *State) ToUserdata(index int) unsafe.Pointer {
return unsafe.Pointer(C.lua_touserdata(L.s, C.int(index)))
}
示例2: Touserdata
// If the value at the given valid index is a full userdata, returns
// its block address. If the value is a light userdata, returns its
// pointer. Otherwise, returns unsafe.Pointer(nil).
func (s *State) Touserdata(index int) unsafe.Pointer {
return C.lua_touserdata(s.l, C.int(index))
}
示例3: Touserdata
// If the value at the given valid index is a full userdata, returns
// its block address. If the value is a light userdata, returns its
// pointer. Otherwise, returns unsafe.Pointer(nil).
func (this *State) Touserdata(index int) unsafe.Pointer {
return C.lua_touserdata(this.luastate, C.int(index))
}
示例4: toGoValue
func (l *Lua) toGoValue(i C.int, paramType reflect.Type) (ret *reflect.Value, err error) {
luaType := C.lua_type(l.State, i)
paramKind := paramType.Kind()
switch paramKind {
case reflect.Bool:
if luaType != C.LUA_TBOOLEAN {
err = fmt.Errorf("not a boolean")
return
}
v := reflect.ValueOf(C.lua_toboolean(l.State, i) == C.int(1))
ret = &v
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
if luaType != C.LUA_TNUMBER {
err = fmt.Errorf("not an integer")
return
}
v := reflect.New(paramType).Elem()
v.SetInt(int64(C.lua_tointeger(l.State, i)))
ret = &v
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
if luaType != C.LUA_TNUMBER {
err = fmt.Errorf("not a unsigned")
return
}
v := reflect.New(paramType).Elem()
v.SetUint(uint64(C.lua_tointeger(l.State, i)))
ret = &v
case reflect.Float32, reflect.Float64:
if luaType != C.LUA_TNUMBER {
err = fmt.Errorf("not a float")
return
}
v := reflect.New(paramType).Elem()
v.SetFloat(float64(C.lua_tonumber(l.State, i)))
ret = &v
case reflect.Interface:
switch paramType {
case interfaceType:
switch luaType {
case C.LUA_TNUMBER:
v := reflect.New(floatType).Elem() // always return float64 for interface{}
v.SetFloat(float64(C.lua_tonumber(l.State, i)))
ret = &v
case C.LUA_TSTRING:
v := reflect.New(stringType).Elem()
v.SetString(C.GoString(C.lua_tolstring(l.State, i, nil)))
ret = &v
case C.LUA_TLIGHTUSERDATA, C.LUA_TUSERDATA:
v := reflect.ValueOf(C.lua_touserdata(l.State, i))
ret = &v
case C.LUA_TBOOLEAN:
v := reflect.New(boolType).Elem()
v.SetBool(C.lua_toboolean(l.State, i) == C.int(1))
ret = &v
case C.LUA_TNIL:
ret = nil
default:
err = fmt.Errorf("unsupported type %s for interface{}", luaTypeName(luaType))
return
}
default:
err = fmt.Errorf("only interface{} is supported, no %v", paramType)
return
}
case reflect.String:
if luaType != C.LUA_TSTRING {
err = fmt.Errorf("not a string")
return
}
v := reflect.New(paramType).Elem()
v.SetString(C.GoString(C.lua_tolstring(l.State, i, nil)))
ret = &v
case reflect.Slice:
switch luaType {
case C.LUA_TSTRING:
v := reflect.New(paramType).Elem()
cstr := C.lua_tolstring(l.State, i, nil)
v.SetBytes(C.GoBytes(unsafe.Pointer(cstr), C.int(C.strlen(cstr))))
ret = &v
case C.LUA_TTABLE:
v := reflect.MakeSlice(paramType, 0, 0)
C.lua_pushnil(l.State)
elemType := paramType.Elem()
for C.lua_next(l.State, i) != 0 {
elemValue, e := l.toGoValue(-1, elemType)
if e != nil {
err = e
return
}
// there is no nil value in lua table so elemValue will never be nil
v = reflect.Append(v, *elemValue)
C.lua_settop(l.State, -2)
ret = &v
}
default:
err = fmt.Errorf("wrong slice argument")
return
}
case reflect.Ptr:
if luaType != C.LUA_TLIGHTUSERDATA {
//.........這裏部分代碼省略.........