diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index d22b90e..962b51e 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -27,7 +27,6 @@ #include "util.h" #include "debugwriter.h" #include "graphics.h" -#include "boost-hash.h" #include #include @@ -115,7 +114,7 @@ static void mriBindingInit() _rb_define_module_function(rb_mKernel, "msgbox", mriPrint); _rb_define_module_function(rb_mKernel, "msgbox_p", mriP); - rb_define_global_const("RGSS_VERSION", rb_str_new_cstr("3.0.0")); + rb_define_global_const("RGSS_VERSION", rb_str_new_cstr("3.0.1")); } else { @@ -304,15 +303,7 @@ static void runCustomScript(const std::string &filename) VALUE kernelLoadDataInt(const char *filename); -struct BacktraceData -{ - /* Maps: Ruby visible filename, To: Actual script name */ - BoostHash scriptNames; -}; - -#define SCRIPT_SECTION_FMT (rgssVer >= 3 ? "{%04ld}" : "Section%03ld") - -static void runRMXPScripts(BacktraceData &btData) +static void runRMXPScripts() { const Config &conf = shState->rtData().config; const std::string &scriptPack = conf.game.scripts; @@ -403,17 +394,17 @@ static void runRMXPScripts(BacktraceData &btData) RSTRING_LEN(scriptDecoded)); VALUE fname; - const char *scriptName = RSTRING_PTR(rb_ary_entry(script, 1)); - char buf[512]; - int len; - if (conf.useScriptNames) - len = snprintf(buf, sizeof(buf), "%03ld:%s", i, scriptName); + { + fname = rb_ary_entry(script, 1); + } else - len = snprintf(buf, sizeof(buf), SCRIPT_SECTION_FMT, i); - - fname = newStringUTF8(buf, len); - btData.scriptNames.insert(buf, scriptName); + { + char buf[32]; + const char *format = rgssVer >= 3 ? "{%04ld}" : "Section%03ld"; + int len = snprintf(buf, sizeof(buf), format, i); + fname = newStringUTF8(buf, len); + } int state; evalString(string, fname, &state); @@ -422,10 +413,9 @@ static void runRMXPScripts(BacktraceData &btData) } } -static void showExc(VALUE exc, const BacktraceData &btData) +static void showExc(VALUE exc) { VALUE bt = rb_funcall2(exc, rb_intern("backtrace"), 0, NULL); - VALUE msg = rb_funcall2(exc, rb_intern("message"), 0, NULL); VALUE bt0 = rb_ary_entry(bt, 0); VALUE name = rb_class_path(rb_obj_class(exc)); @@ -436,49 +426,19 @@ static void showExc(VALUE exc, const BacktraceData &btData) rb_str_catf(ds, "\n\tfrom %" PRIsVALUE, rb_ary_entry(bt, i)); Debug() << StringValueCStr(ds); - char *s = RSTRING_PTR(bt0); - - char line[16]; - std::string file(512, '\0'); - - char *p = s + strlen(s); - char *e; - - while (p != s) - if (*--p == ':') - break; - - e = p; - - while (p != s) - if (*--p == ':') - break; - - /* s p e - * SectionXXX:YY: in 'blabla' */ - - *e = '\0'; - strncpy(line, *p ? p+1 : p, sizeof(line)); - line[sizeof(line)-1] = '\0'; - *e = ':'; - e = p; - - /* s e - * SectionXXX:YY: in 'blabla' */ - - *e = '\0'; - strncpy(&file[0], s, file.size()); - *e = ':'; - - /* Shrink to fit */ - file.resize(strlen(file.c_str())); - file = btData.scriptNames.value(file, file); - - std::string ms(640, '\0'); - snprintf(&ms[0], ms.size(), "Script '%s' line %s: %s occured.\n\n%s", - file.c_str(), line, RSTRING_PTR(name), RSTRING_PTR(msg)); - - showMsg(ms); + ID id_index = rb_intern("index"); + /* an "offset" argument is not needed for the first time */ + VALUE argv[2] = { rb_str_new_cstr(":") }; + long filelen = NUM2LONG(rb_funcall2(bt0, id_index, 1, argv)); + argv[1] = LONG2NUM(filelen + 1); + VALUE tmp = rb_funcall2(bt0, id_index, ARRAY_SIZE(argv), argv); + long linelen = NUM2LONG(tmp) - filelen - 1; + VALUE file = rb_str_subseq(bt0, 0, filelen); + VALUE line = rb_str_subseq(bt0, filelen + 1, linelen); + VALUE ms = rb_sprintf("Script '%" PRIsVALUE "' line %" PRIsVALUE + ": %" PRIsVALUE " occured.\n\n%" PRIsVALUE, + file, line, name, exc); + showMsg(StringValueCStr(ms)); } static void mriBindingExecute() @@ -504,7 +464,6 @@ static void mriBindingExecute() RbData rbData; shState->setBindingData(&rbData); - BacktraceData btData; mriBindingInit(); @@ -512,11 +471,11 @@ static void mriBindingExecute() if (!customScript.empty()) runCustomScript(customScript); else - runRMXPScripts(btData); + runRMXPScripts(); VALUE exc = rb_errinfo(); if (!NIL_P(exc) && !rb_obj_is_kind_of(exc, rb_eSystemExit)) - showExc(exc, btData); + showExc(exc); ruby_cleanup(0); diff --git a/binding-mri/bitmap-binding.cpp b/binding-mri/bitmap-binding.cpp index a49d3e5..1461e74 100644 --- a/binding-mri/bitmap-binding.cpp +++ b/binding-mri/bitmap-binding.cpp @@ -29,12 +29,6 @@ DEF_TYPE(Bitmap); -static const char *objAsStringPtr(VALUE obj) -{ - VALUE str = rb_obj_as_string(obj); - return RSTRING_PTR(str); -} - void bitmapInitProps(Bitmap *b, VALUE self) { /* Wrap properties */ @@ -264,7 +258,10 @@ RB_METHOD(bitmapDrawText) VALUE strObj; rb_get_args(argc, argv, "oo|i", &rectObj, &strObj, &align RB_ARG_END); - str = objAsStringPtr(strObj); + if (!RB_TYPE_P(strObj, RUBY_T_STRING)) + strObj = rb_funcallv(strObj, rb_intern("to_s"), 0, 0); + + str = RSTRING_PTR(strObj); } else { @@ -284,7 +281,10 @@ RB_METHOD(bitmapDrawText) VALUE strObj; rb_get_args(argc, argv, "iiiio|i", &x, &y, &width, &height, &strObj, &align RB_ARG_END); - str = objAsStringPtr(strObj); + if (!RB_TYPE_P(strObj, RUBY_T_STRING)) + strObj = rb_funcallv(strObj, rb_intern("to_s"), 0, 0); + + str = RSTRING_PTR(strObj); } else { @@ -308,7 +308,10 @@ RB_METHOD(bitmapTextSize) VALUE strObj; rb_get_args(argc, argv, "o", &strObj RB_ARG_END); - str = objAsStringPtr(strObj); + if (!RB_TYPE_P(strObj, RUBY_T_STRING)) + strObj = rb_funcallv(strObj, rb_intern("to_s"), 0, 0); + + str = RSTRING_PTR(strObj); } else { diff --git a/binding-mri/etc-binding.cpp b/binding-mri/etc-binding.cpp index 32ad494..731ccca 100644 --- a/binding-mri/etc-binding.cpp +++ b/binding-mri/etc-binding.cpp @@ -22,6 +22,7 @@ #include "etc.h" #include "binding-util.h" #include "serializable-binding.h" +#include "sharedstate.h" DEF_TYPE(Color); DEF_TYPE(Tone); @@ -68,6 +69,9 @@ ATTR_INT_RW(Rect, Height) VALUE otherObj; \ Klass *other; \ rb_get_args(argc, argv, "o", &otherObj RB_ARG_END); \ + if (rgssVer >= 3) \ + if (!rb_typeddata_is_kind_of(otherObj, &Klass##Type)) \ + return Qfalse; \ other = getPrivateDataCheck(otherObj, Klass##Type); \ return rb_bool_new(*p == *other); \ }