Skip to content

Commit

Permalink
Add initObject method
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Dec 9, 2023
1 parent e6c21e0 commit 1a28bd0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions class.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func (mrb *State) ClassOf(v Value) *RClass {
if v == false {
return mrb.falseClass
}

return mrb.trueClass
}

return nil
Expand Down
12 changes: 2 additions & 10 deletions mruby.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package mruby

import (
"fmt"

"github.com/elct9620/mruby-go/stack"
)

Expand All @@ -29,6 +27,7 @@ type State struct {
context *context

falseClass *RClass
trueClass *RClass
objectClass *RClass

topSelf *RObject
Expand All @@ -39,7 +38,6 @@ func New() *State {
context: &context{
callinfo: stack.New[*callinfo](),
},
falseClass: NewClass(),
objectClass: NewClass(),
topSelf: &RObject{},
}
Expand All @@ -62,11 +60,5 @@ func (s *State) GetArgv() []Value {
}

func initCore(mrb *State) {
mrb.objectClass.DefineMethod("puts", &Method{
Function: func(mrb *State, recv Value) Value {
args := mrb.GetArgv()
fmt.Println(args...)
return args[0]
},
})
initObject(mrb)
}
15 changes: 15 additions & 0 deletions object.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
package mruby

import "fmt"

type RBasic struct {
}

type RObject struct {
RBasic
}

func initObject(mrb *State) {
mrb.falseClass = NewClass()
mrb.trueClass = NewClass()

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

0 comments on commit 1a28bd0

Please sign in to comment.