Allow users to pass options to persist.New(). Support for bools.
This commit is contained in:
parent
100f65f83a
commit
ee4f005b6c
|
@ -23,7 +23,7 @@ func (v *visitor) Visit(node ast.Node) ast.Visitor {
|
||||||
|
|
||||||
if !reg.MatchString(id.Name) { return v }
|
if !reg.MatchString(id.Name) { return v }
|
||||||
|
|
||||||
if len(x.Args) != 2 {
|
if len(x.Args) < 2 {
|
||||||
log.Fatal("Wrong number of arguments in persistT call.")
|
log.Fatal("Wrong number of arguments in persistT call.")
|
||||||
}
|
}
|
||||||
var tp string
|
var tp string
|
||||||
|
@ -36,6 +36,10 @@ func (v *visitor) Visit(node ast.Node) ast.Visitor {
|
||||||
case *ast.CompositeLit:
|
case *ast.CompositeLit:
|
||||||
tp = types.TypeString(info.TypeOf(arg),types.RelativeTo(pkg))
|
tp = types.TypeString(info.TypeOf(arg),types.RelativeTo(pkg))
|
||||||
case *ast.Ident:
|
case *ast.Ident:
|
||||||
|
if arg.Name == "true" || arg.Name == "false" {
|
||||||
|
tp = "bool"
|
||||||
|
break
|
||||||
|
}
|
||||||
if arg.Obj.Kind != ast.Var { return v }
|
if arg.Obj.Kind != ast.Var { return v }
|
||||||
inner := pkg.Scope().Innermost(arg.Pos())
|
inner := pkg.Scope().Innermost(arg.Pos())
|
||||||
_,obj := inner.LookupParent(arg.Obj.Name,arg.Pos())
|
_,obj := inner.LookupParent(arg.Obj.Name,arg.Pos())
|
||||||
|
|
|
@ -10,13 +10,9 @@ import (
|
||||||
|
|
||||||
type Var_N persist.Var
|
type Var_N persist.Var
|
||||||
|
|
||||||
func New(name string, xs ..._T) *Var_N {
|
func New(name string, x _T, opt ...persist.Option) *Var_N {
|
||||||
var x _T
|
|
||||||
gob.Register(x)
|
gob.Register(x)
|
||||||
if len(xs) > 0 {
|
ptr := persist.New(name, x, opt...)
|
||||||
x = xs[0]
|
|
||||||
}
|
|
||||||
ptr := persist.New(name, x)
|
|
||||||
ret := (*Var_N)(unsafe.Pointer(ptr))
|
ret := (*Var_N)(unsafe.Pointer(ptr))
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ func main() {
|
||||||
y6 = y6p.Get()
|
y6 = y6p.Get()
|
||||||
y7p := persistIntArray("y7",[]int{1,2,3})
|
y7p := persistIntArray("y7",[]int{1,2,3})
|
||||||
_ = y7p
|
_ = y7p
|
||||||
|
y8p := persistBool("y8",true)
|
||||||
|
_ = y8p
|
||||||
|
|
||||||
z := func(interface{}) {
|
z := func(interface{}) {
|
||||||
_ = persistFloat("y7",1.0)
|
_ = persistFloat("y7",1.0)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user