Example #1
0
func (state State) goToLuaValue(value reflect.Value) bool {
	L := state.L
	gkind := value.Kind()
	switch gkind {
	case reflect.Bool:
		v := value.Bool()
		if v {
			C.lua_pushboolean(L, 1)
		} else {
			C.lua_pushboolean(L, 0)
		}
		return true
	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
		v := value.Int()
		C.lua_pushinteger(L, C.lua_Integer(v))
		return true
	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
		v := value.Uint()
		C.lua_pushinteger(L, C.lua_Integer(v))
		return true
	// case reflect.Uintptr:
	case reflect.Float32, reflect.Float64:
		v := value.Float()
		C.lua_pushnumber(L, C.lua_Number(v))
		return true

	// case reflect.Array:
	// case reflect.Complex64, reflect.Complex128:
	// case reflect.Chan
	// case reflect.Interface
	case reflect.Ptr:
		iv := value.Interface()
		if v, ok := iv.(ILuaRef); ok {
			v.PushValue(state)
			return true
		}
		state.pushObjToLua(value.Interface())
		return true
	case reflect.Func, reflect.Map, reflect.Slice:
		state.pushObjToLua(value.Interface())
		return true
	case reflect.String:
		v := value.String()
		pushStringToLua(L, v)
		return true
	case reflect.Struct:
		objPtr := reflect.New(value.Type())
		objPtr.Elem().Set(value)
		state.pushObjToLua(objPtr.Interface())
		return true
		//case reflect.UnsafePointer
	case reflect.Interface:
		return state.goToLuaValue(value.Elem())
	}
	C.lua_pushnil(L)
	return false
}
Example #2
0
File: pack.go Project: hxyxj/goinfi
func UnpackToLua(in io.Reader, state State) int {
	L := state.L
	var n int = 0
	var unpack P.Unpacker
	msg, err := unpack.Unpack(in)
	if err != nil {
		C.lua_pushinteger(L, C.lua_Integer(n))
		pushStringToLua(L, fmt.Sprintf("unpack error: %v", err))
		return 2
	}
	n = len(msg.Elems)
	C.lua_pushinteger(L, C.lua_Integer(n))
	for _, elem := range msg.Elems {
		UnpackObjectToLua(state, elem)
	}
	return n + 1
}
Example #3
0
File: lua.go Project: hxyxj/goinfi
//export GO_getObjectLength
func GO_getObjectLength(_L unsafe.Pointer, ref unsafe.Pointer) (ret int) {
	L := (*C.lua_State)(_L)
	node := (*refGo)(ref)
	// vm := node.vm
	// state := State{vm, L}
	v := reflect.ValueOf(node.obj)

	defer func() {
		if r := recover(); r != nil {
			pushStringToLua(L, fmt.Sprintf("%v", r))
			ret = -1
		}
	}()

	n := v.Len()
	C.lua_pushinteger(L, C.lua_Integer(n))
	return 1
}
Example #4
0
File: lua.go Project: szll/golua
// lua_pushinteger
func (L *State) PushInteger(n int64) {
	C.lua_pushinteger(L.s, C.lua_Integer(n))
}
Example #5
0
// Pushes a number with value n onto the stack.
func (s *State) Pushinteger(n int) {
	C.lua_pushinteger(s.l, C.lua_Integer(n))
}
Example #6
0
File: glua.go Project: gooops/glua
func (L *State) pushInt(i int64) {
	C.lua_pushinteger(L.s, C.lua_Integer(i))
}