Beispiel #1
0
static void
require_libraries(VALUE *req_list)
{
    VALUE list = *req_list;
    VALUE self = rb_vm_top_self();
    ID require;
    rb_thread_t *th = GET_THREAD();
    rb_block_t *prev_base_block = th->base_block;
    rb_encoding *extenc = rb_default_external_encoding();
    int prev_parse_in_eval = th->parse_in_eval;
    th->base_block = 0;
    th->parse_in_eval = 0;

    Init_ext();		/* should be called here for some reason :-( */
    CONST_ID(require, "require");
    while (list && RARRAY_LEN(list) > 0) {
	VALUE feature = rb_ary_shift(list);
	rb_enc_associate(feature, extenc);
	RBASIC(feature)->klass = rb_cString;
	OBJ_FREEZE(feature);
	rb_funcall2(self, require, 1, &feature);
    }
    *req_list = 0;

    th->parse_in_eval = prev_parse_in_eval;
    th->base_block = prev_base_block;
}
void _Init()
{
  state tmp1;
  tmp1 = get_memory_state();
  Init_ext();
  restore_memory_state(tmp1);
  return ;
}
Beispiel #3
0
static void
require_libraries(struct cmdline_options *opt)
{
    VALUE list = opt->req_list;
    ID require;
    rb_thread_t *th = GET_THREAD();
    rb_block_t *prev_base_block = th->base_block;
    int prev_parse_in_eval = th->parse_in_eval;
    th->base_block = 0;
    th->parse_in_eval = 0;

    Init_ext();		/* should be called here for some reason :-( */
    CONST_ID(require, "require");
    while (list && RARRAY_LEN(list) > 0) {
	VALUE feature = rb_ary_shift(list);
	rb_funcall2(rb_vm_top_self(), require, 1, &feature);
    }
    opt->req_list = 0;

    th->parse_in_eval = prev_parse_in_eval;
    th->base_block = prev_base_block;
}
Beispiel #4
0
int main( int argc, char** argv ) 
{
  int state  = 0;
  int rc     = 0;
  int opt_mv = 0;

  crate_app ca;

  /** startup items from ruby's original main.c */
#ifdef _WIN32
  NtInitialize(&argc, &argv);
#endif
#if defined(__MACOS__) && defined(__MWERKS__)
  argc = ccommand(&argv);
#endif

  /* setup ruby */
  ruby_init();
  ruby_script( argv[0] );
  ruby_init_loadpath();

  /* strip out the crate specific arguments from argv using --crate- */
  opt_mv = crate_init_from_options( &ca, argc, argv );
  argc -= opt_mv;
  argv += opt_mv;
 
  /* printf("crate file  : %s\n", ca.file_name);   */
  /* printf("crate class : %s\n", ca.class_name);  */
  /* printf("crate method: %s\n", ca.method_name); */

  /* make ARGV available */
  ruby_set_argv( argc, argv );

  /* initialize all extensions */
  Init_ext();

  /* load up the amalgalite libs */
  am_bootstrap_lift( cARB, Qnil );
 
  /* remove the current LOAD_PATH */
  rb_ary_clear( rb_gv_get( "$LOAD_PATH" ) );

  /* invoke the class / method passing in ARGV and ENV */
  rb_protect( crate_wrap_app, (VALUE)&ca, &state );

  /* check the results */
  if ( state ) {

    /* exception was raised, check the $! var */
    VALUE lasterr  = rb_gv_get("$!");
   
    /* system exit was called so just propogate that up to our exit */
    if ( rb_obj_is_instance_of( lasterr, rb_eSystemExit ) ) {

      rc = NUM2INT( rb_attr_get( lasterr, rb_intern("status") ) );
      /*printf(" Caught SystemExit -> $? will be %d\n", rc ); */

    } else {

      /* some other exception was raised so dump that out */
      VALUE klass     = rb_class_path( CLASS_OF( lasterr ) );
      VALUE message   = rb_obj_as_string( lasterr );
      VALUE backtrace = rb_funcall( lasterr, rb_intern("backtrace"), 0 );

      fprintf( stderr, "%s: %s\n", RSTRING( klass )->ptr, RSTRING( message )->ptr );
      rb_iterate( rb_each, backtrace, dump_backtrace, Qnil );

      rc = state;
    }
  } 

  free( ca.file_name );
  free( ca.class_name );
  free( ca.method_name );

  /* shut down ruby */
  ruby_finalize();

  /* exit the program */
  exit( rc );
}