upgrade-dev v2.3.41

This commit is contained in:
杨红岩 2023-03-27 16:40:37 +08:00
parent 7e3d6d14a1
commit 3f6cd0c575
2 changed files with 18 additions and 2 deletions

View File

@ -110,6 +110,10 @@ func Test() {
inArgument.Add("字符串参数")
funcKey.Invoke(inArgument)
funcKey.SetValue("函数变字符串")
funcToString := funcKey.AsString()
fmt.Println("funcToString:", funcToString.Value())
// 对象
type objectDemo1 struct {
Key1 string
@ -162,8 +166,16 @@ func Test() {
objectKey8 := objectKey.Get("Key8")
fmt.Println("objectKey8:", objectKey8.JSONString())
objectKey8.AsArray()
//end
//object end
fmt.Println("objectKey:", objectKey.JSONString())
//object to string
objectKey.SetValue("对象变成字符串")
objectToString := objectKey.AsString()
fmt.Println("objectToString:", objectToString.Value())
fmt.Println("objectKey:", objectKey.JSONString())
objectKey.SetValue(testObj)
fmt.Println("objectKey:", objectKey.JSONString())
// 数组
}

View File

@ -97,7 +97,6 @@ func (m *V8Value) JSONString() string {
}
// SetValue 设置值
// 函数不能设置值
func (m *V8Value) SetValue(value any) {
if isMainProcess {
rv := reflect.ValueOf(value)
@ -115,10 +114,15 @@ func (m *V8Value) SetValue(value any) {
case reflect.Func:
m.value = &json.JsonData{T: consts.GO_VALUE_FUNC, V: value, S: 0}
default:
//基本类型
m.value.SetValue(value)
m.rv = nil
return
}
if m.rv != nil {
m.rv.Set(rv)
} else {
m.rv = &rv
}
}
}