Skip to content

Commit

Permalink
Added Length to Set Variable
Browse files Browse the repository at this point in the history
  • Loading branch information
gentee committed Nov 12, 2020
1 parent 4f2803f commit 7c86712
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion script/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ var (
{Prototype: `Condition(str,str) bool`, Object: Condition},
{Prototype: `File(str) str`, Object: FileLoad},
{Prototype: `Form(str)`, Object: Form},
{Prototype: `IsObjVar(str) bool`, Object: IsVarObj},
{Prototype: `IsVar(str) bool`, Object: IsVar},
{Prototype: `LogOutput(int,str)`, Object: LogOutput},
{Prototype: `Macro(str) str`, Object: Macro},
Expand All @@ -137,7 +138,6 @@ var (
{Prototype: `GetVarObj(str) obj`, Object: GetVarObj},
// For gentee
{Prototype: `YamlToMap(str) map`, Object: YamlToMap},
{Prototype: `FindFirstRegExp(str,str) arr.str`, Object: FindFirstRegExpºStrStr},
}
)

Expand Down
16 changes: 0 additions & 16 deletions script/gentee.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package script

import (
"regexp"

"github.com/gentee/gentee"
"github.com/gentee/gentee/core"
"gopkg.in/yaml.v2"
Expand All @@ -27,17 +25,3 @@ func YamlToMap(in string) (*core.Map, error) {
}
return ret.(*core.Map), nil
}

// FindFirstRegExpºStrStr returns an array of the first successive matches of the expression
func FindFirstRegExpºStrStr(src, rePattern string) (*core.Array, error) {
re, err := regexp.Compile(rePattern)
if err != nil {
return nil, err
}
list := re.FindStringSubmatch(src)
out := core.NewArray()
for _, sub := range list {
out.Data = append(out.Data, sub)
}
return out, nil
}
8 changes: 8 additions & 0 deletions script/varobj.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ func GetVarObj(name string) (*core.Obj, error) {
return val.(*core.Obj), nil
}

func IsVarObj(name string) int64 {
_, ok := dataScript.ObjVars[len(dataScript.ObjVars)-1].Load(name)
if ok {
return 1
}
return 0
}

func setRawVarObj(shift int, name string, value *core.Obj) error {
off := len(dataScript.ObjVars) - 1 - shift
if off < 0 {
Expand Down

0 comments on commit 7c86712

Please sign in to comment.