Skip to content

Commit

Permalink
Refactor argument parsting
Browse files Browse the repository at this point in the history
  • Loading branch information
zhulik committed Aug 7, 2024
1 parent 8a3b6f3 commit 8e48ca2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
12 changes: 6 additions & 6 deletions gruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type GRuby struct {
state *C.mrb_state

loadedFiles map[string]bool
getArgAccumulator []C.mrb_value
getArgAccumulator []Value

methods methodsStore

Expand All @@ -28,7 +28,7 @@ type GRuby struct {
func goGetArgAppend(state *C.mrb_state, v C.mrb_value) {
grb := states.Get(state)

grb.getArgAccumulator = append(grb.getArgAccumulator, v)
grb.getArgAccumulator = append(grb.getArgAccumulator, grb.value(v))
}

// GetGlobalVariable returns the value of the global variable by the given name.
Expand Down Expand Up @@ -64,7 +64,7 @@ func New() *GRuby {
grb: nil,
classes: classMethodMap{},
},
getArgAccumulator: make([]C.mrb_value, 0, C._go_get_max_funcall_args()),
getArgAccumulator: make([]Value, 0, C._go_get_max_funcall_args()),
trueV: nil,
falseV: nil,
nilV: nil,
Expand Down Expand Up @@ -190,7 +190,7 @@ func (g *GRuby) FullGC() {
// called function (currently on the stack).
func (g *GRuby) GetArgs() []Value {
// Clear reset the accumulator to zero length
g.getArgAccumulator = make([]C.mrb_value, 0, C._go_get_max_funcall_args())
g.getArgAccumulator = make([]Value, 0, C._go_get_max_funcall_args())

// Get all the arguments and put it into our accumulator
count := C._go_mrb_get_args_all(g.state)
Expand All @@ -199,7 +199,7 @@ func (g *GRuby) GetArgs() []Value {
values := make([]Value, count)

for i := range int(count) {
values[i] = g.value(g.getArgAccumulator[i])
values[i] = g.getArgAccumulator[i]
}

return values
Expand Down Expand Up @@ -413,7 +413,7 @@ func (g *GRuby) TopSelf() Value {

// FalseValue returns a Value for "false"
func (g *GRuby) FalseValue() Value {
return g.falseV // TODO: const?
return g.falseV
}

// NilValue returns "nil"
Expand Down
1 change: 0 additions & 1 deletion gruby_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,6 @@ func TestStackedException(t *testing.T) {

grb.TopSelf().SingletonClass().DefineMethod("myeval", evalFunc, gruby.ArgsBlock())

// TODO: fix me and enable back
result, err := grb.LoadString("myeval { raise 'foo' }")
g.Expect(err).To(HaveOccurred())
g.Expect(result).To(BeNil())
Expand Down
5 changes: 2 additions & 3 deletions methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ type (
)

type methodsStore struct {
grb *GRuby
classes classMethodMap
getArgAccumulator []C.mrb_value
grb *GRuby
classes classMethodMap
}

func (s *methodsStore) add(class *C.struct_RClass, name string, callback Func) {
Expand Down
2 changes: 1 addition & 1 deletion value.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (v *GValue) call(method string, args []Value, block Value) (Value, error) {
var argvPtr *C.mrb_value

if len(args) > 0 {
// Make the raw byte slice to hold our arguments we'll pass to C
// Make the raw byte slice to hold our arguments we'll pass to C*C.mrb
argv = make([]C.mrb_value, len(args))
for i, arg := range args {
argv[i] = arg.CValue()
Expand Down

0 comments on commit 8e48ca2

Please sign in to comment.