Skip to content

Commit

Permalink
fix: Value.Assign should work with int32 and int64.
Browse files Browse the repository at this point in the history
This applies to:

* `Value.Assign(int32)`
* `Value.Assign(uint32)`

* `Value.Assign(int64)`
* `Value.Assign(uint32)`

* `Value.Assign(int)`
* `Value.Assign(uint)`

refs #286
  • Loading branch information
pravic committed Feb 7, 2021
1 parent 3b44840 commit 6146c79
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions value.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ func (v *Value) Release() {
// Assign go value to Sciter Value
// currently supported go types: bool integer float string and NativeFunctor
func (v *Value) Assign(val interface{}) {
const is64Bit = uint64(^uintptr(0)) == ^uint64(0)
switch val.(type) {
case string:
s := val.(string)
v.SetString(s)
case int:
i := val.(int)
case int32:
i := val.(int32)
v.SetInt(i)
case int64:
i := val.(int64)
v.SetInt64(i)
case float64:
f := val.(float64)
// valueInit(this); valueFloatDataSet(this, v, T_FLOAT, 0)
Expand All @@ -86,16 +90,22 @@ func (v *Value) Assign(val interface{}) {
v.SetInt(i)
case float32:
v.Assign(float64(val.(float32)))
case int:
if is64Bit {
v.Assign(int64(val.(int)))
} else {
v.Assign(int32(val.(int)))
}
case uint:
v.Assign(int(val.(uint)))
if is64Bit {
v.Assign(uint64(val.(uint)))
} else {
v.Assign(uint32(val.(uint)))
}
case uint32:
v.Assign(int(val.(uint32)))
v.Assign(int32(val.(uint32)))
case uint64:
v.Assign(int(val.(uint64)))
case int32:
v.Assign(int(val.(int32)))
case int64:
v.Assign(int(val.(int64)))
v.Assign(int64(val.(uint64)))
case Value:
vf := val.(Value)
v.Copy(&vf)
Expand Down

0 comments on commit 6146c79

Please sign in to comment.