diff --git a/cmd/pgen/main.go b/cmd/pgen/main.go index 6777c7f..7b96dd6 100644 --- a/cmd/pgen/main.go +++ b/cmd/pgen/main.go @@ -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()) diff --git a/cmd/pgen/template.go b/cmd/pgen/template.go index 27ac21f..048cac0 100644 --- a/cmd/pgen/template.go +++ b/cmd/pgen/template.go @@ -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 } diff --git a/test/basic/main.go b/test/basic/main.go index 4550890..de32520 100644 --- a/test/basic/main.go +++ b/test/basic/main.go @@ -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)