@@ -88,7 +88,8 @@ function Get-Turtle {
88
88
# We want to keep track of the current member,
89
89
# and continue to the next word until we find a member name.
90
90
$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
92
93
93
94
# To do this in one pass, we will iterate through the words and arguments.
94
95
# We use an indexed loop so we can skip past claimed arguments.
@@ -116,15 +117,13 @@ function Get-Turtle {
116
117
}
117
118
# Now we know how long it took to get to the next member name.
118
119
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)
120
122
$argList =
121
- if ($methodArgIndex -eq ($argIndex + 1 )) {
122
- @ ()
123
- }
124
- else {
123
+ @ (if ($methodArgIndex -ne ($argIndex + 1 )) {
125
124
$wordsAndArguments [($argIndex + 1 ).. ($methodArgIndex - 1 )]
126
125
$argIndex = $methodArgIndex - 1
127
- }
126
+ })
128
127
129
128
# Look up the member information for the current member.
130
129
$memberInfo = $turtleType.Members [$currentMember ]
@@ -145,8 +144,18 @@ function Get-Turtle {
145
144
) {
146
145
# If we have arguments,
147
146
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
+
150
159
} else {
151
160
# otherwise, just invoke the method with no arguments.
152
161
$currentTurtle .$currentMember.Invoke ()
0 commit comments