Exemple #1
0
// LoadString loads the given code, executes it, and returns its final
// value that it might return.
func (m *Mrb) LoadString(code string) (*MrbValue, error) {
	value := C.mrb_load_string(m.state, C.CString(code))
	if m.state.exc != nil {
		return nil, newExceptionValue(m.state)
	}

	return newValue(m.state, value), nil
}
Exemple #2
0
// LoadString loads the given code, executes it, and returns its final
// value that it might return.
func (m *Mrb) LoadString(code string) (*MrbValue, error) {
	cs := C.CString(code)
	defer C.free(unsafe.Pointer(cs))

	value := C.mrb_load_string(m.state, cs)
	if m.state.exc != nil {
		return nil, newExceptionValue(m.state)
	}

	return newValue(m.state, value), nil
}
Exemple #3
0
func (m *MRuby) Eval(code string, args ...interface{}) C.mrb_value {
	c := C.CString(code)
	defer C.free(unsafe.Pointer(c))

	value := C.mrb_load_string(m.state, c)
	mtype := C.struct_mrb_data_type{}
	C.mrb_get_datatype(m.state, value, &mtype)

	if m.state.exc != nil {
		exception := C.mrb_obj_value(unsafe.Pointer(m.state.exc))
		fmt.Printf("exception: %#v\n", exception)
	}

	return value
}