@@ -88,7 +88,8 @@ function Get-Turtle {
8888 # We want to keep track of the current member,
8989 # and continue to the next word until we find a member name.
9090 $currentMember = $null
91- $outputTurtle = $false
91+ # We want to output the turtle by default, in case we were called with no parameters.
92+ $outputTurtle = $true
9293
9394 # To do this in one pass, we will iterate through the words and arguments.
9495 # We use an indexed loop so we can skip past claimed arguments.
@@ -116,15 +117,13 @@ function Get-Turtle {
116117 }
117118 # Now we know how long it took to get to the next member name.
118119
119- # And we can determine if we have any parameters
120+ # And we can determine if we have any parameters.
121+ # (it is important that we always force any parameters into an array)
120122 $argList =
121- if ($methodArgIndex -eq ($argIndex + 1 )) {
122- @ ()
123- }
124- else {
123+ @ (if ($methodArgIndex -ne ($argIndex + 1 )) {
125124 $wordsAndArguments [($argIndex + 1 ).. ($methodArgIndex - 1 )]
126125 $argIndex = $methodArgIndex - 1
127- }
126+ })
128127
129128 # Look up the member information for the current member.
130129 $memberInfo = $turtleType.Members [$currentMember ]
@@ -145,8 +144,18 @@ function Get-Turtle {
145144 ) {
146145 # If we have arguments,
147146 if ($argList ) {
148- # pass them to the method.
149- $currentTurtle .$currentMember.Invoke ($argList )
147+ # and we have a script method
148+ if ($memberInfo -is [Management.Automation.Runspaces.ScriptMethodData ]) {
149+ # set this to the current turtle
150+ $this = $currentTurtle
151+ # and call the script, splatting positional parameters
152+ # (this allows more complex binding, like ValueFromRemainingArguments)
153+ . $currentTurtle .$currentMember.Script @argList
154+ } else {
155+ # Otherwise, we pass the parameters directly to the method
156+ $currentTurtle .$currentMember.Invoke ($argList )
157+ }
158+
150159 } else {
151160 # otherwise, just invoke the method with no arguments.
152161 $currentTurtle .$currentMember.Invoke ()
0 commit comments