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