int main(int argc, char **argv) { #ifndef __MINGW32__ FILE *fileconf; #endif char *tmp; char lichdir[256] = { '\0' }; char datadir[512] = { '\0' }; int nerr; sig_setup(); #ifndef __MINGW32__ snprintf(lichdir, 256, "%s%s", getenv("HOME"), "/.lich.cfg"); fileconf = fopen(lichdir, "rb"); if (!fileconf) { perror("fopen"); fprintf(stderr, "Your `$HOME/.lich.cfg' file cannot be opened: please create the file and put the full directory name Lich should use for settings/config files in it.\n\nFor example, to do that, you could type: echo \"$HOME/lich\" > $HOME/.lich.cfg\n"); exit(EXIT_FAILURE); } fgets(lichdir, 256, fileconf); fclose(fileconf); lichdir[strnlen(lichdir, 256) - 1] = '/'; chdir(lichdir); #else NtInitialize(&argc, &argv); strncpy(lichdir, argv[0], 255); tmp = &lichdir[strlen(lichdir)]; while (tmp && (*tmp != '\\') && (*tmp != '/')) { tmp--; } *tmp = '\0'; chdir(lichdir); #endif init_ruby_interpreter(argc, argv); init_libs(); prep_ruby_env(); getcwd(lichdir, 255); lichdir[strlen(lichdir) + 1] = '\0'; lichdir[strlen(lichdir)] = RSTRING(rb_const_get(rb_cFile, rb_intern("SEPARATOR")))->ptr[0]; strcpy(datadir, lichdir); strcat(datadir, "data"); datadir[strlen(datadir)] = lichdir[strlen(lichdir) - 1]; rb_gv_set("$data_dir", rb_str_new(datadir, strlen(datadir))); rb_gv_set("$lich_dir", rb_str_new(lichdir, strlen(lichdir))); ruby_safe_level = 0; if (nerr = ruby_exec()) { tmp = RSTRING(rb_funcall(rb_gv_get("$!"), rb_intern("to_s"), 0))->ptr; if (!strncasecmp(tmp, "exit", 4)) ruby_stop(0); fprintf(stderr, "%s\n", tmp); fprintf(stderr, "%s\n", RSTRING(rb_funcall(rb_funcall(rb_gv_get("$!"), rb_intern("backtrace"), 0), rb_intern("join"), 1, rb_str_new2("\n")))->ptr); ruby_stop(nerr); } ruby_stop(0); }
static void reg32_setup() { char *tmp; if (tmp = reg_get_value(HKEY_LOCAL_MACHINE, "System\\CurrentControlSet\\Services\\Tcpip\\Parameters\\DataBasePath")) { rb_gv_set("$hosts_dir", rb_str_new2(tmp)); free(tmp); } else if (tmp = reg_get_value(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\DataBasePath")) { rb_gv_set("$hosts_dir", rb_str_new2(tmp)); free(tmp); } if (tmp = reg_get_value(HKEY_LOCAL_MACHINE, "Software\\Simutronics\\SGE32\\Directory")) { rb_hash_aset(rb_gv_get("$LICHCONFIG"), rb_str_new2("SGE Directory"), rb_str_new2(tmp)); free(tmp); } if (tmp = reg_get_value(HKEY_LOCAL_MACHINE, "Software\\Simutronics\\Launcher\\Directory")) { rb_hash_aset(rb_gv_get("$LICHCONFIG"), rb_str_new2("Launcher Directory"), rb_str_new2(tmp)); free(tmp); } if (tmp = reg_get_value(HKEY_LOCAL_MACHINE, "Software\\Simutronics\\WIZ32\\Directory")) { rb_hash_aset(rb_gv_get("$LICHCONFIG"), rb_str_new2("Wizard Directory"), rb_str_new2(tmp)); free(tmp); } if (tmp = reg_get_value(HKEY_LOCAL_MACHINE, "Software\\Classes\\Simutronics.Autolaunch\\Shell\\Open\\command\\")) { rb_hash_aset(rb_gv_get("$LICHCONFIG"), rb_str_new2("Launcher Shell Command"), rb_str_new2(tmp)); free(tmp); } if (tmp = getenv("windir")) { rb_hash_aset(rb_gv_get("$LICHCONFIG"), rb_str_new2("Windows Directory"), rb_str_new2(tmp)); rb_hash_aset(rb_gv_get("$LICHCONFIG"), rb_str_new2("windir"), rb_str_new2(tmp)); } }
static VALUE switch_run( VALUE self ) { setenv( "CHIBACH_HOME", STR2CSTR( rb_funcall( mTrema, rb_intern( "home" ), 0 ) ), 1 ); VALUE name = rb_funcall( self, rb_intern( "name" ), 0 ); rb_gv_set( "$PROGRAM_NAME", name ); int argc = 6; char **argv = xmalloc( sizeof( char * ) * ( uint32_t ) ( argc + 1 ) ); argv[ 0 ] = STR2CSTR( name ); argv[ 1 ] = ( char * ) ( uintptr_t ) "--name"; argv[ 2 ] = STR2CSTR( name ); argv[ 3 ] = ( char * ) ( uintptr_t ) "--datapath_id"; argv[ 4 ] = STR2CSTR( rb_funcall( rb_iv_get( self, "@dpid" ), rb_intern( "to_hex" ), 0 ) ); argv[ 5 ] = ( char * ) ( uintptr_t ) "--daemonize"; argv[ 6 ] = NULL; init_chibach( &argc, &argv ); xfree( argv ); set_controller_connected_handler( handle_controller_connected, ( void * ) self ); set_hello_handler( handle_hello, ( void * ) self ); set_features_request_handler( handle_features_request, ( void * ) self ); set_set_config_handler( handle_set_config, ( void * ) self ); set_flow_mod_handler( handle_flow_mod, ( void * ) self ); set_echo_request_handler( handle_echo_request, ( void * ) self ); if ( rb_respond_to( self, rb_intern( "start" ) ) == Qtrue ) { rb_funcall( self, rb_intern( "start" ), 0 ); } rb_funcall( self, rb_intern( "start_chibach" ), 0 ); return self; }
static void coverage_event_coverage_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass) { char *sourcefile; unsigned int sourceline; static unsigned int in_hook = 0; if(in_hook) { return; } in_hook++; #if COVERAGE_DEBUG_EVENTS do { int status; VALUE old_exception; old_exception = rb_gv_get("$!"); rb_protect(rb_inspect, klass, &status); if(!status) { printf("EVENT: %d %s %s %s %d\n", event, klass ? RSTRING(rb_inspect(klass))->ptr : "", mid ? (mid == ID_ALLOCATOR ? "ID_ALLOCATOR" : rb_id2name(mid)) : "unknown", node ? node->nd_file : "", node ? nd_line(node) : 0); } else { printf("EVENT: %d %s %s %d\n", event, mid ? (mid == ID_ALLOCATOR ? "ID_ALLOCATOR" : rb_id2name(mid)) : "unknown", node ? node->nd_file : "", node ? nd_line(node) : 0); } rb_gv_set("$!", old_exception); } while (0); #endif if(event & RUBY_EVENT_C_CALL) { coverage_mark_caller(); } if(event & (RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN | RUBY_EVENT_CLASS)) { in_hook--; return; } if(node == NULL) { in_hook--; return; } sourcefile = node->nd_file; sourceline = nd_line(node) - 1; coverage_increase_counter_cached(sourcefile, sourceline); if(event & RUBY_EVENT_CALL) coverage_mark_caller(); in_hook--; }
VALUE RubyEvaluator::GetContext(KObjectRef global) { std::string theid = this->GetContextId(global); VALUE ctx = rb_gv_get(theid.c_str()); if (ctx == Qnil) { VALUE ctx_class = rb_define_class("KrollRubyContext", rb_cObject); rb_define_method(ctx_class, "method_missing", VALUEFUNC(m_missing), -1); ctx = rb_obj_alloc(ctx_class); rb_gv_set(theid.c_str(), ctx); } return ctx; }
int main(int argc, char **argv) { ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); ruby_init_loadpath(); ruby_script("testing!!!!"); rb_gv_set("$brent", ID2SYM(rb_intern("c_defined_symbol"))); int state; rb_protect(require_wrap, 0, &state); } return ruby_cleanup(0); }
static inline void lich_set_config() { rb_global_variable(&lichconfig); rb_define_readonly_variable("$LICHCONFIG", &lichconfig); lichconfig = rb_hash_new(); // rb_eException = rb_eval_string("Exception"); // rb_cRuntimeError = rb_define_class("RuntimeError", rb_eException); rb_gv_set("$version", rb_str_new2(LICH_VERSION)); rb_hash_aset(lichconfig, rb_str_new2("version"), rb_str_new2(LICH_VERSION)); #ifdef __MINGW32__ rb_hash_aset(lichconfig, rb_str_new2("OS"), rb_str_new2("Windows")); #else rb_hash_aset(lichconfig, rb_str_new2("OS"), rb_str_new2("Linux")); #endif }
/* * Starts this controller. Usually you do not need to invoke * explicitly, because this is called implicitly by "trema run" * command. */ static VALUE controller_run( VALUE self ) { setenv( "TREMA_HOME", STR2CSTR( rb_funcall( mTrema, rb_intern( "home" ), 0 ) ), 1 ); VALUE name = rb_funcall( self, rb_intern( "name" ), 0 ); rb_gv_set( "$PROGRAM_NAME", name ); int argc = 3; char **argv = xmalloc( sizeof( char * ) * ( uint32_t ) ( argc + 1 ) ); argv[ 0 ] = STR2CSTR( name ); argv[ 1 ] = ( char * ) ( uintptr_t ) "--name"; argv[ 2 ] = STR2CSTR( name ); argv[ 3 ] = NULL; init_trema( &argc, &argv ); xfree( argv ); set_switch_ready_handler( handle_switch_ready, ( void * ) self ); set_features_reply_handler( handle_features_reply, ( void * ) self ); set_packet_in_handler( handle_packet_in, ( void * ) self ); set_flow_removed_handler( handle_flow_removed, ( void * ) self ); set_switch_disconnected_handler( handle_switch_disconnected, ( void * ) self ); set_port_status_handler( handle_port_status, ( void * ) self ); set_stats_reply_handler( handle_stats_reply, ( void * ) self ); set_error_handler( handle_openflow_error, ( void * ) self ); set_get_config_reply_handler( handle_get_config_reply, ( void * ) self ); set_barrier_reply_handler( handle_barrier_reply, ( void * ) self ); set_vendor_handler( handle_vendor, ( void * ) self ); set_queue_get_config_reply_handler( handle_queue_get_config_reply, ( void * ) self ); set_list_switches_reply_handler( handle_list_switches_reply ); struct itimerspec interval; interval.it_interval.tv_sec = 1; interval.it_interval.tv_nsec = 0; interval.it_value.tv_sec = 0; interval.it_value.tv_nsec = 0; add_timer_event_callback( &interval, handle_timer_event, ( void * ) self ); if ( rb_respond_to( self, rb_intern( "start" ) ) == Qtrue ) { rb_funcall( self, rb_intern( "start" ), 0 ); } rb_funcall( self, rb_intern( "start_trema" ), 0 ); return self; }
/* This is an old, and deprecated function which checks the pad. Do not use this, use Pad's methods directly. */ VALUE checkKeys(VALUE self) { VALUE keys = rb_gv_get("$keys"); std::string keys_str[] = { "select", "start", "up", "down", "left", "right", "L", "R", "cross", "triangle", "square", "hold" }; Pad &pad = Pad::getInstance(); pad.update(); for (int i = 0; i < 12; ++i) { if (pad.held(keys_str[i])) rb_hash_aset(keys, rb_str_new2(keys_str[i].c_str()), Qtrue); else rb_hash_aset(keys, rb_str_new2(keys_str[i].c_str()), Qfalse); if (pad.pressed(keys_str[i])) rb_hash_aset(keys, rb_str_new2(("pressed_" + keys_str[i]).c_str()), Qtrue); else rb_hash_aset(keys, rb_str_new2(("pressed_" + keys_str[i]).c_str()), Qfalse); if (pad.released(keys_str[i])) rb_hash_aset(keys, rb_str_new2(("released_" + keys_str[i]).c_str()), Qtrue); else rb_hash_aset(keys, rb_str_new2(("released_" + keys_str[i]).c_str()), Qfalse); } int analogX = pad.getStickX(); int analogY = pad.getStickY(); rb_hash_aset(keys, rb_str_new2("analogX"), INT2FIX(analogX)); rb_hash_aset(keys, rb_str_new2("analogY"), INT2FIX(analogY)); rb_gv_set("$keys", keys); return Qnil; }
static VALUE sb_gv_set(VALUE self, VALUE var, VALUE val) { return rb_gv_set(StringValuePtr(var), val); }
static void mriBindingInit() { tableBindingInit(); etcBindingInit(); fontBindingInit(); bitmapBindingInit(); spriteBindingInit(); viewportBindingInit(); planeBindingInit(); if (rgssVer == 1) { windowBindingInit(); tilemapBindingInit(); } else { windowVXBindingInit(); tilemapVXBindingInit(); } inputBindingInit(); audioBindingInit(); graphicsBindingInit(); fileIntBindingInit(); if (rgssVer >= 3) { _rb_define_module_function(rb_mKernel, "rgss_main", mriRgssMain); _rb_define_module_function(rb_mKernel, "rgss_stop", mriRgssStop); _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.1")); } else { _rb_define_module_function(rb_mKernel, "print", mriPrint); _rb_define_module_function(rb_mKernel, "p", mriP); rb_define_alias(rb_singleton_class(rb_mKernel), "_mkxp_kernel_caller_alias", "caller"); _rb_define_module_function(rb_mKernel, "caller", _kernelCaller); } if (rgssVer == 1) rb_eval_string(module_rpg1); else if (rgssVer == 2) rb_eval_string(module_rpg2); else if (rgssVer == 3) rb_eval_string(module_rpg3); else assert(!"unreachable"); VALUE mod = rb_define_module("MKXP"); _rb_define_module_function(mod, "data_directory", mkxpDataDirectory); _rb_define_module_function(mod, "puts", mkxpPuts); _rb_define_module_function(mod, "raw_key_states", mkxpRawKeyStates); _rb_define_module_function(mod, "mouse_in_window", mkxpMouseInWindow); rb_gv_set("MKXP", Qtrue); }
static void process_sflag(struct cmdline_options *opt) { if (opt->sflag) { long n; VALUE *args; VALUE argv = rb_argv; n = RARRAY_LEN(argv); args = RARRAY_PTR(argv); while (n > 0) { VALUE v = *args++; char *s = StringValuePtr(v); char *p; int hyphen = Qfalse; if (s[0] != '-') break; n--; if (s[1] == '-' && s[2] == '\0') break; v = Qtrue; /* check if valid name before replacing - with _ */ for (p = s + 1; *p; p++) { if (*p == '=') { *p++ = '\0'; v = rb_str_new2(p); break; } if (*p == '-') { hyphen = Qtrue; } else if (*p != '_' && !ISALNUM(*p)) { VALUE name_error[2]; name_error[0] = rb_str_new2("invalid name for global variable - "); if (!(p = strchr(p, '='))) { rb_str_cat2(name_error[0], s); } else { rb_str_cat(name_error[0], s, p - s); } name_error[1] = args[-1]; rb_exc_raise(rb_class_new_instance(2, name_error, rb_eNameError)); } } s[0] = '$'; if (hyphen) { for (p = s + 1; *p; ++p) { if (*p == '-') *p = '_'; } } rb_gv_set(s, v); } n = RARRAY_LEN(argv) - n; while (n--) { rb_ary_shift(argv); } } opt->sflag = 0; }
static void set_client_string(VALUE arg) { rb_gv_set("$_CLIENTSTRING_", arg); }
static void runRMXPScripts(BacktraceData &btData) { const Config &conf = shState->rtData().config; const std::string &scriptPack = conf.game.scripts; if (scriptPack.empty()) { showMsg("No game scripts specified (missing Game.ini?)"); return; } if (!shState->fileSystem().exists(scriptPack.c_str())) { showMsg("Unable to open '" + scriptPack + "'"); return; } VALUE scriptArray; /* We checked if Scripts.rxdata exists, but something might * still go wrong */ try { scriptArray = kernelLoadDataInt(scriptPack.c_str(), false); } catch (const Exception &e) { showMsg(std::string("Failed to read script data: ") + e.msg); return; } if (!RB_TYPE_P(scriptArray, RUBY_T_ARRAY)) { showMsg("Failed to read script data"); return; } rb_gv_set("$RGSS_SCRIPTS", scriptArray); long scriptCount = RARRAY_LEN(scriptArray); std::string decodeBuffer; decodeBuffer.resize(0x1000); for (long i = 0; i < scriptCount; ++i) { VALUE script = rb_ary_entry(scriptArray, i); if (!RB_TYPE_P(script, RUBY_T_ARRAY)) continue; VALUE scriptName = rb_ary_entry(script, 1); VALUE scriptString = rb_ary_entry(script, 2); int result = Z_OK; unsigned long bufferLen; while (true) { unsigned char *bufferPtr = reinterpret_cast<unsigned char*>(const_cast<char*>(decodeBuffer.c_str())); const unsigned char *sourcePtr = reinterpret_cast<const unsigned char*>(RSTRING_PTR(scriptString)); bufferLen = decodeBuffer.length(); result = uncompress(bufferPtr, &bufferLen, sourcePtr, RSTRING_LEN(scriptString)); bufferPtr[bufferLen] = '\0'; if (result != Z_BUF_ERROR) break; decodeBuffer.resize(decodeBuffer.size()*2); } if (result != Z_OK) { static char buffer[256]; snprintf(buffer, sizeof(buffer), "Error decoding script %ld: '%s'", i, RSTRING_PTR(scriptName)); showMsg(buffer); break; } rb_ary_store(script, 3, rb_str_new_cstr(decodeBuffer.c_str())); } /* Execute preloaded scripts */ for (std::set<std::string>::iterator i = conf.preloadScripts.begin(); i != conf.preloadScripts.end(); ++i) runCustomScript(*i); VALUE exc = rb_gv_get("$!"); if (exc != Qnil) return; while (true) { for (long i = 0; i < scriptCount; ++i) { VALUE script = rb_ary_entry(scriptArray, i); VALUE scriptDecoded = rb_ary_entry(script, 3); VALUE string = newStringUTF8(RSTRING_PTR(scriptDecoded), 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); else len = snprintf(buf, sizeof(buf), SCRIPT_SECTION_FMT, i); fname = newStringUTF8(buf, len); btData.scriptNames.insert(buf, scriptName); int state; evalString(string, fname, &state); if (state) break; } VALUE exc = rb_gv_get("$!"); if (rb_obj_class(exc) != getRbData()->exc[Reset]) break; processReset(); } }
static void set_server_string(VALUE arg) { rb_gv_set("$_SERVERSTRING_", arg); }
static void set_server_buffer(VALUE arg) { rb_gv_set("$_SERVERBUFFER_", arg); }
static void set_client_buffer(VALUE arg) { rb_gv_set("$_CLIENTBUFFER_", arg); }
void defineKeys() { VALUE keys = rb_hash_new(); rb_gv_set("$keys", keys); VALUE joyau = JOYAU_MOD; defModFunc(joyau, "readKeys", checkKeys, 0); defModFunc(joyau, "gets", Joyau_gets, 0); VALUE mPad = defModule("Pad"); defModFunc(mPad, "update", Pad_update, 0); defModFunc(mPad, "held?", Pad_held, 1); defModFunc(mPad, "pressed?", Pad_pressed, 1); defModFunc(mPad, "released?", Pad_released, 1); defModFunc(mPad, "stickX", Pad_stickX, 0); defModFunc(mPad, "stickY", Pad_stickY, 0); defConst(mPad, "SELECT", INT2FIX(PSP_CTRL_SELECT)); defConst(mPad, "START", INT2FIX(PSP_CTRL_START)); defConst(mPad, "L", INT2FIX(PSP_CTRL_LTRIGGER)); defConst(mPad, "R", INT2FIX(PSP_CTRL_RTRIGGER)); defConst(mPad, "CROSS", INT2FIX(PSP_CTRL_CROSS)); defConst(mPad, "SQUARE", INT2FIX(PSP_CTRL_SQUARE)); defConst(mPad, "TRIANGLE", INT2FIX(PSP_CTRL_TRIANGLE)); defConst(mPad, "CIRCLE", INT2FIX(PSP_CTRL_CIRCLE)); defConst(mPad, "UP", INT2FIX(PSP_CTRL_UP)); defConst(mPad, "DOWN", INT2FIX(PSP_CTRL_DOWN)); defConst(mPad, "LEFT", INT2FIX(PSP_CTRL_LEFT)); defConst(mPad, "RIGHT", INT2FIX(PSP_CTRL_RIGHT)); defConst(mPad, "HOLD", INT2FIX(PSP_CTRL_HOLD)); /* Document-class: Joyau::OSK There is a built-in keyboard in your firmware, which can be used by your program easily through this class. Notice Joyau.gets is a simpliefied version of this module, which can handle more advanced settings. You can, by using its constants, specify what has to be input. you can indicated the used language: 1. DEFAULT 2. JAPANESE 3. ENGLISH 4. FRENCH 5. SPANISH 6. GERMAN 7. ITALIAN 8. DUTCH 9. PORTUGESE 10. RUSSIAN 11. KOREAN As well as the caracters to input: 1. ALL 2. LATIN_SYMBOL 3. LATIN_LOWERCASE 4. LATIN_UPPERCASE 5. LATIN_DIGIT 6. JAPANESE_DIGIT 7. JAPANESE_SYMBOL 8. JAPANESE_LOWERCASE 9. JAPANESE_UPPERCASE 10. JAPANESE_HIRAGANA 11. JAPANASE_HALF_KATAKANA 12. JAPANESE_KATAKANA 13. JAPANESE_LOWERCASE 14. RUSSIAN_LOWERCASE 15. RUSSIAN_UPPERCASE 16. IT_KOREAN 17. URL You can also set the default text and the description, and give a block telling what to draw under the keyboard (if nothing were drawn, there'd be graphical glitches). */ VALUE mOSK = defModule("OSK"); defModFunc(mOSK, "run", Osk_run, 5); defConst(mOSK, "DEFAULT", INT2FIX(PSP_UTILITY_OSK_LANGUAGE_DEFAULT)); defConst(mOSK, "JAPANESE", INT2FIX(PSP_UTILITY_OSK_LANGUAGE_JAPANESE)); defConst(mOSK, "ENGLISH", INT2FIX(PSP_UTILITY_OSK_LANGUAGE_ENGLISH)); defConst(mOSK, "FRENCH", INT2FIX(PSP_UTILITY_OSK_LANGUAGE_SPANISH)); defConst(mOSK, "SPANISH", INT2FIX(PSP_UTILITY_OSK_LANGUAGE_SPANISH)); defConst(mOSK, "GERMAN", INT2FIX(PSP_UTILITY_OSK_LANGUAGE_GERMAN)); defConst(mOSK, "ITALIAN", INT2FIX(PSP_UTILITY_OSK_LANGUAGE_ITALIAN)); defConst(mOSK, "PORTUGESE", INT2FIX(PSP_UTILITY_OSK_LANGUAGE_PORTUGESE)); defConst(mOSK, "RUSSIAN", INT2FIX(PSP_UTILITY_OSK_LANGUAGE_RUSSIAN)); defConst(mOSK, "KOREAN", INT2FIX(PSP_UTILITY_OSK_LANGUAGE_KOREAN)); defConst(mOSK, "ALL", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_ALL)); defConst(mOSK, "LATIN_DIGIT", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_LATIN_DIGIT)); defConst(mOSK, "LATIN_SYMBOL", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_LATIN_SYMBOL)); defConst(mOSK, "LATIN_LOWERCASE", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_LATIN_LOWERCASE)); defConst(mOSK, "LATIN_UPPERCASE", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_LATIN_UPPERCASE)); defConst(mOSK, "JAPANESE_DIGIT", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_DIGIT)); defConst(mOSK, "JAPANESE_SYMBOL", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_SYMBOL)); defConst(mOSK, "JAPANESE_LOWERCASE", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_LOWERCASE)); defConst(mOSK, "JAPANESE_UPPERCASE", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_UPPERCASE)); defConst(mOSK, "JAPANESE_HIRAGANA", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_HIRAGANA)); defConst(mOSK, "JAPANASE_HALF_KATAKANA", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_HALF_KATAKANA)); defConst(mOSK, "JAPANESE_KATAKANA", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_KATAKANA)); defConst(mOSK, "RUSSIAN_LOWERCASE", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_JAPANESE_LOWERCASE)); defConst(mOSK, "RUSSIAN_UPPERCASE", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_RUSSIAN_UPPERCASE)); defConst(mOSK, "IT_KOREAN", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_KOREAN)); defConst(mOSK, "URL", INT2FIX(PSP_UTILITY_OSK_INPUTTYPE_URL)); VALUE cCursor = defClass<Cursor>("Cursor", "Sprite"); defMethod(cCursor, "updatePos", Cursor_updatePos, 0); defMethod(cCursor, "setSensibility", Cursor_setSensibility, 1); defMethod(cCursor, "sensibility", Cursor_sensibility, 0); defMethod(cCursor, "rect=", Cursor_setRect, 1); defMethod(cCursor, "rect", Cursor_rect, 0); defAlias(cCursor, "setSensibility", "sensibility="); defAlias(cCursor, "updatePos", "update_pos"); }
static void runRMXPScripts() { const std::string &scriptPack = shState->rtData().config.game.scripts; if (scriptPack.empty()) { showMsg("No game scripts specified (missing Game.ini?)"); return; } if (!shState->fileSystem().exists(scriptPack.c_str())) { showMsg("Unable to open '" + scriptPack + "'"); return; } VALUE scriptArray = kernelLoadDataInt(scriptPack.c_str()); if (rb_type(scriptArray) != RUBY_T_ARRAY) { showMsg("Failed to read script data"); return; } rb_gv_set("$RGSS_SCRIPTS", scriptArray); long scriptCount = RARRAY_LEN(scriptArray); std::string decodeBuffer; decodeBuffer.resize(0x1000); for (long i = 0; i < scriptCount; ++i) { VALUE script = rb_ary_entry(scriptArray, i); if (rb_type(script) != RUBY_T_ARRAY) continue; VALUE scriptName = rb_ary_entry(script, 1); VALUE scriptString = rb_ary_entry(script, 2); int result = Z_OK; unsigned long bufferLen; while (true) { unsigned char *bufferPtr = reinterpret_cast<unsigned char*>(const_cast<char*>(decodeBuffer.c_str())); const unsigned char *sourcePtr = reinterpret_cast<const unsigned char*>(RSTRING_PTR(scriptString)); bufferLen = decodeBuffer.length(); result = uncompress(bufferPtr, &bufferLen, sourcePtr, RSTRING_LEN(scriptString)); bufferPtr[bufferLen] = '\0'; if (result != Z_BUF_ERROR) break; decodeBuffer.resize(decodeBuffer.size()*2); } if (result != Z_OK) { static char buffer[256]; snprintf(buffer, sizeof(buffer), "Error decoding script %ld: '%s'", i, RSTRING_PTR(scriptName)); showMsg(buffer); break; } rb_ary_store(script, 3, rb_str_new_cstr(decodeBuffer.c_str())); } for (long i = 0; i < scriptCount; ++i) { VALUE script = rb_ary_entry(scriptArray, i); VALUE scriptDecoded = rb_ary_entry(script, 3); VALUE string = newStringUTF8(RSTRING_PTR(scriptDecoded), RSTRING_LEN(scriptDecoded)); VALUE fname; if (shState->rtData().config.useScriptNames) { fname = rb_ary_entry(script, 1); } else { char buf[32]; int len = snprintf(buf, sizeof(buf), RGSS_SECTION_STR, i); fname = newStringUTF8(buf, len); } int state; evalString(string, fname, &state); if (state) break; } }
static void set_client(VALUE arg) { rb_gv_set("$_CLIENT_", arg); }
rpmruby rpmrubyNew(char ** av, uint32_t flags) { static char * _av[] = { "rpmruby", NULL }; rpmruby ruby = (flags & 0x80000000) ? rpmrubyI() : rpmrubyGetPool(_rpmrubyPool); int xx; RUBYDBG((stderr, "--> %s(%p,0x%x) ruby %p\n", __FUNCTION__, av, flags, ruby)); /* If failure, or retrieving already initialized _rpmrubyI, just exit. */ if (ruby == NULL || ruby == _rpmrubyI) goto exit; if (av == NULL) av = _av; ruby->flags = flags; xx = argvAppend(&ruby->av, (ARGV_t)av); ruby->ac = argvCount(ruby->av); /* XXX FIXME: 0x40000000 => xruby.c wrapper without interpreter. */ if (ruby->flags & 0x40000000) { static size_t _rpmrubyStackSize = 4 * 1024 * 1024; /* XXX save as global interpreter. */ _rpmrubyI = ruby; ruby->nstack = _rpmrubyStackSize; ruby->stack = malloc(ruby->nstack); assert(ruby->stack != NULL); gettimeofday(&ruby->start, NULL); /* starting time for log entries */ if (_rpmruby_debug) ruby->zlog = rpmzLogNew(&ruby->start); /* initialize logging */ /* initialize the relay mechanism */ ruby->ruby_coroutine_lock = yarnNewLock(0); ruby->main_coroutine_lock = yarnNewLock(0); } else { #if defined(WITH_RUBYEMBED) VALUE variable_in_this_stack_frame; /* RUBY_INIT_STSCK */ #if defined(HAVE_RUBY_DEFINES_H) /* XXX ruby-1.9.2 */ ruby_sysinit(&ruby->ac, (char ***) &ruby->av); /* XXX ruby-1.9.2p0 ruby_bind_stack() patch needed */ { uint8_t * b = ruby->stack; uint8_t * e = b + ruby->nstack; ruby_bind_stack((VALUE *)b, (VALUE *) e); } #endif /* NOTYET */ ruby_init_stack(&variable_in_this_stack_frame); /* RUBY_INIT_STACK */ ruby_init(); ruby_init_loadpath(); ruby_script((char *)av[0]); if (av[1]) ruby_set_argv(argvCount((ARGV_t)av)-1, av+1); rb_gv_set("$result", rb_str_new2("")); #if !defined(HAVE_RUBY_DEFINES_H) /* XXX ruby-1.8.6 */ (void) rpmrubyRun(ruby, rpmrubyInitStringIO, NULL); #endif #endif /* WITH_RUBYEMBED */ } exit: return rpmrubyLink(ruby); }