4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-07-06 10:44:04 +00:00

Update dependencies and remove old matterclient lib (#2067)

This commit is contained in:
Wim
2023-08-05 20:43:19 +02:00
committed by GitHub
parent 9459495484
commit 56e7bd01ca
772 changed files with 139315 additions and 121315 deletions

View File

@ -143,6 +143,7 @@ func (p *Parser) ParseFile() (file *File, err error) {
}
stmts := p.parseStmtList()
p.expect(token.EOF)
if p.errors.Len() > 0 {
return nil, p.errors.Err()
}

View File

@ -247,8 +247,8 @@ func (c *Compiled) RunContext(ctx context.Context) (err error) {
// Clone creates a new copy of Compiled. Cloned copies are safe for concurrent
// use by multiple goroutines.
func (c *Compiled) Clone() *Compiled {
c.lock.Lock()
defer c.lock.Unlock()
c.lock.RLock()
defer c.lock.RUnlock()
clone := &Compiled{
globalIndexes: c.globalIndexes,

View File

@ -62,9 +62,12 @@ func (d *decodeState) scanNext() {
// scanWhile processes bytes in d.data[d.off:] until it
// receives a scan code not equal to op.
func (d *decodeState) scanWhile(op int) {
func (d *decodeState) scanWhile(op int) (isFloat bool) {
s, data, i := &d.scan, d.data, d.off
for i < len(data) {
if data[i] == '.' || data[i] == 'e' || data[i] == 'E' {
isFloat = true
}
newOp := s.step(s, data[i])
i++
if newOp != op {
@ -76,6 +79,7 @@ func (d *decodeState) scanWhile(op int) {
d.off = len(data) + 1 // mark processed EOF with len+1
d.opcode = d.scan.eof()
return
}
func (d *decodeState) value() (tengo.Object, error) {
@ -185,7 +189,7 @@ func (d *decodeState) object() (tengo.Object, error) {
func (d *decodeState) literal() (tengo.Object, error) {
// All bytes inside literal return scanContinue op code.
start := d.readIndex()
d.scanWhile(scanContinue)
isFloat := d.scanWhile(scanContinue)
item := d.data[start:d.readIndex()]
@ -210,8 +214,12 @@ func (d *decodeState) literal() (tengo.Object, error) {
if c != '-' && (c < '0' || c > '9') {
panic(phasePanicMsg)
}
n, _ := strconv.ParseFloat(string(item), 10)
return &tengo.Float{Value: n}, nil
if isFloat {
n, _ := strconv.ParseFloat(string(item), 10)
return &tengo.Float{Value: n}, nil
}
n, _ := strconv.ParseInt(string(item), 10, 64)
return &tengo.Int{Value: n}, nil
}
}

View File

@ -7,17 +7,31 @@ import (
)
var mathModule = map[string]tengo.Object{
"e": &tengo.Float{Value: math.E},
"pi": &tengo.Float{Value: math.Pi},
"phi": &tengo.Float{Value: math.Phi},
"sqrt2": &tengo.Float{Value: math.Sqrt2},
"sqrtE": &tengo.Float{Value: math.SqrtE},
"sqrtPi": &tengo.Float{Value: math.SqrtPi},
"sqrtPhi": &tengo.Float{Value: math.SqrtPhi},
"ln2": &tengo.Float{Value: math.Ln2},
"log2E": &tengo.Float{Value: math.Log2E},
"ln10": &tengo.Float{Value: math.Ln10},
"log10E": &tengo.Float{Value: math.Log10E},
"e": &tengo.Float{Value: math.E},
"pi": &tengo.Float{Value: math.Pi},
"phi": &tengo.Float{Value: math.Phi},
"sqrt2": &tengo.Float{Value: math.Sqrt2},
"sqrtE": &tengo.Float{Value: math.SqrtE},
"sqrtPi": &tengo.Float{Value: math.SqrtPi},
"sqrtPhi": &tengo.Float{Value: math.SqrtPhi},
"ln2": &tengo.Float{Value: math.Ln2},
"log2E": &tengo.Float{Value: math.Log2E},
"ln10": &tengo.Float{Value: math.Ln10},
"log10E": &tengo.Float{Value: math.Log10E},
"maxFloat32": &tengo.Float{Value: math.MaxFloat32},
"smallestNonzeroFloat32": &tengo.Float{Value: math.SmallestNonzeroFloat32},
"maxFloat64": &tengo.Float{Value: math.MaxFloat64},
"smallestNonzeroFloat64": &tengo.Float{Value: math.SmallestNonzeroFloat64},
"maxInt": &tengo.Int{Value: math.MaxInt},
"minInt": &tengo.Int{Value: math.MinInt},
"maxInt8": &tengo.Int{Value: math.MaxInt8},
"minInt8": &tengo.Int{Value: math.MinInt8},
"maxInt16": &tengo.Int{Value: math.MaxInt16},
"minInt16": &tengo.Int{Value: math.MinInt16},
"maxInt32": &tengo.Int{Value: math.MaxInt32},
"minInt32": &tengo.Int{Value: math.MinInt32},
"maxInt64": &tengo.Int{Value: math.MaxInt64},
"minInt64": &tengo.Int{Value: math.MinInt64},
"abs": &tengo.UserFunction{
Name: "abs",
Value: FuncAFRF(math.Abs),

View File

@ -180,6 +180,10 @@ var timesModule = map[string]tengo.Object{
Name: "to_utc",
Value: timesToUTC,
}, // to_utc(time) => time
"in_location": &tengo.UserFunction{
Name: "in_location",
Value: timesInLocation,
}, // in_location(time, location) => time
}
func timesSleep(args ...tengo.Object) (ret tengo.Object, err error) {
@ -430,7 +434,7 @@ func timesDate(args ...tengo.Object) (
ret tengo.Object,
err error,
) {
if len(args) != 7 {
if len(args) < 7 || len(args) > 8 {
err = tengo.ErrWrongNumArguments
return
}
@ -499,9 +503,29 @@ func timesDate(args ...tengo.Object) (
return
}
var loc *time.Location
if len(args) == 8 {
i8, ok := tengo.ToString(args[7])
if !ok {
err = tengo.ErrInvalidArgumentType{
Name: "eighth",
Expected: "string(compatible)",
Found: args[7].TypeName(),
}
return
}
loc, err = time.LoadLocation(i8)
if err != nil {
ret = wrapError(err)
return
}
} else {
loc = time.Now().Location()
}
ret = &tengo.Time{
Value: time.Date(i1,
time.Month(i2), i3, i4, i5, i6, i7, time.Now().Location()),
time.Month(i2), i3, i4, i5, i6, i7, loc),
}
return
@ -1113,6 +1137,46 @@ func timesTimeLocation(args ...tengo.Object) (
return
}
func timesInLocation(args ...tengo.Object) (
ret tengo.Object,
err error,
) {
if len(args) != 2 {
err = tengo.ErrWrongNumArguments
return
}
t1, ok := tengo.ToTime(args[0])
if !ok {
err = tengo.ErrInvalidArgumentType{
Name: "first",
Expected: "time(compatible)",
Found: args[0].TypeName(),
}
return
}
s2, ok := tengo.ToString(args[1])
if !ok {
err = tengo.ErrInvalidArgumentType{
Name: "second",
Expected: "string(compatible)",
Found: args[1].TypeName(),
}
return
}
location, err := time.LoadLocation(s2)
if err != nil {
ret = wrapError(err)
return
}
ret = &tengo.Time{Value: t1.In(location)}
return
}
func timesTimeString(args ...tengo.Object) (ret tengo.Object, err error) {
if len(args) != 1 {
err = tengo.ErrWrongNumArguments