Skip to content

Commit

Permalink
Correctly handle argument-counts inside proc
Browse files Browse the repository at this point in the history
We'd previously count the number of required arguments incorrectly
for user-defined procedures.  This was caused by trying to split
arguments by spaces - if no spaces were present we'd return one
regardless.

This update fixes that, and closes #15.
  • Loading branch information
skx committed Jun 22, 2022
1 parent 7b14b23 commit fed8c26
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions interpreter/builtin_proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@ func proc(i *Interpreter, args []string) (string, error) {
// name
name := args[0]

// args
parm := args[1]
a := strings.Split(parm, " ")
// args - split by space
argsIn := strings.Split(args[1], " ")

// But only collect the non-empty ones
argsOut := []string{}

for _, arg := range argsIn {
if strings.TrimSpace(arg) != "" {
argsOut = append(argsOut, arg)
}
}

// body
body := args[2]

// Save the function
i.functions[name] = UserFunction{
Args: a,
Args: argsOut,
Body: body,
}

Expand Down

0 comments on commit fed8c26

Please sign in to comment.