Skip to content

Commit

Permalink
Move Object.new and Object.puts to standalone method
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Jan 23, 2024
1 parent a05ca17 commit 7e55dfe
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,30 @@ func initObject(mrb *State) (err error) {
}

mrb.ObjectClass.DefineMethod(mrb, "new", &Method{
Function: func(mrb *State, recv Value) Value {
args := mrb.GetArgv()
argc := mrb.GetArgc()

super := mrb.ObjectClass
if argc > 0 {
super = args[0].(*Class)
}

return &Object{object{super}, nil}
},
Function: objectNew,
})

mrb.ObjectClass.DefineMethod(mrb, "puts", &Method{
Function: func(mrb *State, recv Value) Value {
args := mrb.GetArgv()
fmt.Println(args...)
return args[0]
},
Function: objectPuts,
})

return nil
}

func objectNew(mrb *State, recv Value) Value {
args := mrb.GetArgv()
argc := mrb.GetArgc()

super := mrb.ObjectClass
if argc > 0 {
super = args[0].(*Class)
}

return &Object{object{super}, nil}
}

func objectPuts(mrb *State, recv Value) Value {
args := mrb.GetArgv()
fmt.Println(args...)
return args[0]
}

0 comments on commit 7e55dfe

Please sign in to comment.