lang: funcs: Allow the len function to determine str length
This commit is contained in:
@@ -26,6 +26,10 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
simplepoly.Register("len", []*types.FuncValue{
|
simplepoly.Register("len", []*types.FuncValue{
|
||||||
|
{
|
||||||
|
T: types.NewType("func(str) int"),
|
||||||
|
V: Len,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
T: types.NewType("func([]variant) int"),
|
T: types.NewType("func([]variant) int"),
|
||||||
V: Len,
|
V: Len,
|
||||||
@@ -43,6 +47,8 @@ func init() {
|
|||||||
func Len(input []types.Value) (types.Value, error) {
|
func Len(input []types.Value) (types.Value, error) {
|
||||||
var length int
|
var length int
|
||||||
switch k := input[0].Type().Kind; k {
|
switch k := input[0].Type().Kind; k {
|
||||||
|
case types.KindStr:
|
||||||
|
length = len(input[0].Str())
|
||||||
case types.KindList:
|
case types.KindList:
|
||||||
length = len(input[0].List())
|
length = len(input[0].List())
|
||||||
case types.KindMap:
|
case types.KindMap:
|
||||||
|
|||||||
Reference in New Issue
Block a user