-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement minimal rest parameter feature
- Loading branch information
Showing
8 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package mruby | ||
|
||
func initArray(mrb *State) (err error) { | ||
mrb.ArrayClass, err = mrb.DefineClassId(_ArrayClass(mrb), mrb.ObjectClass) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
mrb.DefineMethodId(mrb.ArrayClass, _join(mrb), arrayJoin) | ||
|
||
return nil | ||
} | ||
|
||
func arrayJoin(mrb *State, self Value) Value { | ||
argv := mrb.GetArgv() | ||
|
||
elem, ok := self.([]Value) | ||
if !ok { | ||
return nil | ||
} | ||
|
||
ret := "" | ||
elemLen := len(elem) | ||
for i, v := range elem { | ||
v, ok := v.(string) | ||
if !ok { | ||
continue | ||
} | ||
|
||
ret += v | ||
hasNext := elemLen > i+1 | ||
if hasNext { | ||
ret += argv[0].(string) | ||
} | ||
} | ||
|
||
return ret | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,9 @@ func initCore(mrb *State) (err error) { | |
return | ||
} | ||
|
||
if err = initArray(mrb); err != nil { | ||
return | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters