Skip to content

Commit

Permalink
Move #puts and #raise to Kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Sep 19, 2024
1 parent 4fe3ec2 commit 9f0b734
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
20 changes: 20 additions & 0 deletions kernel.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mruby

import "fmt"

func objectInspect(mrb *State, self Value) Value {
switch v := self.(type) {
case *Object:
Expand All @@ -14,10 +16,28 @@ func objectInspect(mrb *State, self Value) Value {
}
}

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

func funcRaise(mrb *State, recv Value) Value {
args := mrb.GetArgv()
mrb.Raise(nil, fmt.Sprint(args...))

return nil
}

func initKernel(mrb *State) (err error) {
mrb.KernelModule = mrb.DefineModuleId(_Kernel(mrb))

mrb.DefineMethodId(mrb.KernelModule, _inspect(mrb), objectInspect)
mrb.DefineMethodId(mrb.ObjectClass, _raise(mrb), funcRaise)

// defined in mruby-io
putsSym := mrb.Intern("puts")
mrb.DefineMethodId(mrb.ObjectClass, putsSym, objectPuts)

return mrb.IncludeModule(mrb.ObjectClass, mrb.KernelModule)
}
19 changes: 0 additions & 19 deletions object.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package mruby

import "fmt"

type RBasic interface {
Class() RClass
Flags() uint32
Expand Down Expand Up @@ -46,19 +44,6 @@ func (obj *Object) ivGet(sym Symbol) Value {
return obj.iv.Get(sym)
}

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

func objectRaise(mrb *State, recv Value) Value {
args := mrb.GetArgv()
mrb.Raise(nil, fmt.Sprint(args...))

return nil
}

func initObject(mrb *State) (err error) {
mrb.FalseClass, err = mrb.DefineClassId(_FalseClass(mrb), mrb.ObjectClass)
if err != nil {
Expand All @@ -69,9 +54,5 @@ func initObject(mrb *State) (err error) {
return err
}

putsSym := mrb.Intern("puts")
mrb.DefineMethodId(mrb.ObjectClass, putsSym, objectPuts)

mrb.DefineMethodId(mrb.ObjectClass, _raise(mrb), objectRaise)
return nil
}

0 comments on commit 9f0b734

Please sign in to comment.