func (m *Mrb) KernelModule() *Class {
	return newClass(m, m.state.kernel_module)
}
KernelModule returns the Kernel top-level module.
package mruby
import "unsafe"
import "C"
type Mrb struct {
	state *C.mrb_state
}
func (m *Mrb) GetGlobalVariable(name string) *MrbValue {
	cs := C.CString(name)
	defer C.free(unsafe.Pointer(cs))
	return newValue(m.state, C._go_mrb_gv_get(m.state, C.mrb_intern_cstr(m.state, cs)))
}
func (m *Mrb) SetGlobalVariable(name string, value Value) {
	cs := C.CString(name)
	defer C.free(unsafe.Pointer(cs))
	v := value.MrbValue(m)
	C._go_mrb_gv_set(m.state, C.mrb_intern_cstr(m.state, cs), v.value)
}
type ArenaIndex int
func NewMrb() *Mrb {
	state := C.mrb_open()
	return &Mrb{
		state: state,
	}
}
func (m *Mrb) ArenaRestore(idx ArenaIndex) {
	C.mrb_gc_arena_restore(m.state, C.int(idx))
}
func (m *Mrb) ArenaSave() ArenaIndex {
	return ArenaIndex(C.mrb_gc_arena_save(m.state))
}
func (m *Mrb) EnableGC() {
	C._go_enable_gc(m.state)
}
func (m *Mrb) DisableGC() {
	C._go_disable_gc(m.state)
}
func (m *Mrb) LiveObjectCount() int {
	return int(C._go_gc_live(m.state))
}
func (m *Mrb) Class(name string, super *Class) *Class {
	cs := C.CString(name)
	defer C.free(unsafe.Pointer(cs))
	var class *C.struct_RClass
	if super == nil {
		class = C.mrb_class_get(m.state, cs)
	} else {
		class = C.mrb_class_get_under(m.state, super.class, cs)
	}
	return newClass(m, class)
}
func (m *Mrb) Module(name string) *Class {
	cs := C.CString(name)
	defer C.free(unsafe.Pointer(cs))
	class := C.mrb_module_get(m.state, cs)
	return newClass(m, class)
}
func (m *Mrb) Close() {
	stateMethodTable.Mutex.Lock()
	delete(stateMethodTable.Map, m.state)
	stateMethodTable.Mutex.Unlock()
	C.mrb_close(m.state)
}
func (m *Mrb) ConstDefined(name string, scope Value) bool {
	cs := C.CString(name)
	defer C.free(unsafe.Pointer(cs))
	scopeV := scope.MrbValue(m).value
	b := C.mrb_const_defined(
		m.state, scopeV, C.mrb_intern_cstr(m.state, cs))
	return C.ushort(b) != 0
}
func (m *Mrb) FullGC() {
	C.mrb_full_gc(m.state)
}
func (m *Mrb) GetArgs() []*MrbValue {
	getArgLock.Lock()
	defer getArgLock.Unlock()
	getArgAccumulator = make([]C.mrb_value, 0, C._go_get_max_funcall_args())
	count := C._go_mrb_get_args_all(m.state)
	values := make([]*MrbValue, count)
	for i := 0; i < int(count); i++ {
		values[i] = newValue(m.state, getArgAccumulator[i])
	}
	return values
}
func (m *Mrb) IncrementalGC() {
	C.mrb_incremental_gc(m.state)
}
func (m *Mrb) LoadString(code string) (*MrbValue, error) {
	cs := C.CString(code)
	defer C.free(unsafe.Pointer(cs))
	value := C._go_mrb_load_string(m.state, cs)
	if exc := checkException(m.state); exc != nil {
		return nil, exc
	}
	return newValue(m.state, value), nil
}
func (m *Mrb) Run(v Value, self Value) (*MrbValue, error) {
	if self == nil {
		self = m.TopSelf()
	}
	mrbV := v.MrbValue(m)
	mrbSelf := self.MrbValue(m)
	proc := C._go_mrb_proc_ptr(mrbV.value)
	value := C.mrb_run(m.state, proc, mrbSelf.value)
	if exc := checkException(m.state); exc != nil {
		return nil, exc
	}
	return newValue(m.state, value), nil
}
func (m *Mrb) RunWithContext(v Value, self Value, stackKeep int) (int, *MrbValue, error) {
	if self == nil {
		self = m.TopSelf()
	}
	mrbV := v.MrbValue(m)
	mrbSelf := self.MrbValue(m)
	proc := C._go_mrb_proc_ptr(mrbV.value)
	i := C.int(stackKeep)
	value := C._go_mrb_context_run(m.state, proc, mrbSelf.value, &i)
	if exc := checkException(m.state); exc != nil {
		return stackKeep, nil, exc
	}
	return int(i), newValue(m.state, value), nil
}
func (m *Mrb) Yield(block Value, args ...Value) (*MrbValue, error) {
	mrbBlock := block.MrbValue(m)
	var argv []C.mrb_value
	var argvPtr *C.mrb_value
	if len(args) > 0 {
		argv = make([]C.mrb_value, len(args))
		for i, arg := range args {
			argv[i] = arg.MrbValue(m).value
		}
		argvPtr = &argv[0]
	}
	result := C._go_mrb_yield_argv(
		m.state,
		mrbBlock.value,
		C.mrb_int(len(argv)),
		argvPtr)
	if exc := checkException(m.state); exc != nil {
		return nil, exc
	}
	return newValue(m.state, result), nil
}
func (m *Mrb) DefineClass(name string, super *Class) *Class {
	if super == nil {
		super = m.ObjectClass()
	}
	cs := C.CString(name)
	defer C.free(unsafe.Pointer(cs))
	return newClass(
		m, C.mrb_define_class(m.state, cs, super.class))
}
func (m *Mrb) DefineClassUnder(name string, super *Class, outer *Class) *Class {
	if super == nil {
		super = m.ObjectClass()
	}
	if outer == nil {
		outer = m.ObjectClass()
	}
	cs := C.CString(name)
	defer C.free(unsafe.Pointer(cs))
	return newClass(m, C.mrb_define_class_under(
		m.state, outer.class, cs, super.class))
}
func (m *Mrb) DefineModule(name string) *Class {
	cs := C.CString(name)
	defer C.free(unsafe.Pointer(cs))
	return newClass(m, C.mrb_define_module(m.state, cs))
}
func (m *Mrb) DefineModuleUnder(name string, outer *Class) *Class {
	if outer == nil {
		outer = m.ObjectClass()
	}
	cs := C.CString(name)
	defer C.free(unsafe.Pointer(cs))
	return newClass(m,
		C.mrb_define_module_under(m.state, outer.class, cs))
}
func (m *Mrb) ObjectClass() *Class {
	return newClass(m, m.state.object_class)
}