Changeset 398

Show
Ignore:
Timestamp:
01/09/2008 00:01:45 (8 months ago)
Author:
why
Message:
  • shoes/world.c: exception handling prior to launch. so file not found doesn't spawn shoes.
  • lib/shoes.rb: added --version.
Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/shoes.rb

    r326 r398  
    8585    opts.banner = "Usage: shoes [options] (app.rb or app.shy)" 
    8686     
    87     opts.separator "" 
    88     opts.separator "Specific options:" 
    89      
    9087    opts.on("-m", "--manual", 
    91             "Open the built-in manual.") do |s| 
     88            "Open the built-in manual.") do 
    9289      @main_app = Shoes::Help 
    9390    end 
     91 
    9492    opts.on("-s", "--shy DIRECTORY", 
    9593            "Compress a directory into a Shoes YAML (SHY) archive.") do |s| 
    9694      @main_app = ShyMake.call(s) 
     95    end 
     96 
     97    opts.on_tail("-v", "--version", "Display the version info.") do 
     98      puts "shoes #{Shoes::RELEASE_NAME.downcase} (0.r#{Shoes::REVISION})" 
     99      raise SystemExit 
     100    end 
     101 
     102    opts.on_tail("-h", "--help", "Show this message") do 
     103      puts opts 
     104      raise SystemExit 
    97105    end 
    98106  end 
  • trunk/samples/jot.rb

    r381 r398  
    44 
    55Shoes.app :title => "vJot Clone",  
    6   :width => 420, :height => 560 do 
     6  :width => 420, :height => 560, :resizable => false do 
    77 
    88  @note = NOTES.first 
  • trunk/shoes/world.c

    r376 r398  
    5252} 
    5353 
     54static VALUE 
     55shoes_load_begin(VALUE v) 
     56{ 
     57  char *bootup = (char *)v; 
     58  return rb_eval_string(bootup); 
     59} 
     60 
     61static VALUE 
     62shoes_load_exception(VALUE v, VALUE exc) 
     63{ 
     64  return exc; 
     65} 
     66 
    5467shoes_code 
    5568shoes_load(char *path, char *uri) 
     
    6073  { 
    6174    char bootup[SHOES_BUFSIZE]; 
    62     sprintf(bootup, 
    63       "begin;" 
    64         "Shoes.load(%%q<%s>);" 
    65       "rescue Object => e;" 
    66         SHOES_META 
    67           EXC_RUN 
    68         "end;" 
    69       "end;", path); 
    70     rb_eval_string(bootup); 
     75    sprintf(bootup, "Shoes.load(%%q<%s>);", path); 
     76    VALUE v = rb_rescue2(shoes_load_begin, (VALUE)bootup, shoes_load_exception, Qnil, rb_cObject, 0); 
     77    if (rb_obj_is_kind_of(v, rb_eException)) 
     78    { 
     79      VALUE msg = rb_funcall(v, rb_intern("message"), 0); 
     80      printf("%s\n", RSTRING_PTR(msg)); 
     81      return SHOES_QUIT; 
     82    } 
    7183  } 
    7284 
     
    8698{ 
    8799  ruby_set_argv(argc, argv); 
     100} 
     101 
     102static VALUE 
     103shoes_start_begin(VALUE v) 
     104{ 
     105  return rb_eval_string("$SHOES_URI = Shoes.args!"); 
     106} 
     107 
     108static VALUE 
     109shoes_start_exception(VALUE v, VALUE exc) 
     110{ 
     111  return exc; 
    88112} 
    89113 
     
    118142 
    119143  char *load_uri_str = NULL; 
    120   VALUE load_uri = rb_eval_string("$SHOES_URI = Shoes.args!"); 
     144  VALUE load_uri = rb_rescue2(shoes_start_begin, Qnil, shoes_start_exception, Qnil, rb_cObject, 0); 
    121145  if (!RTEST(load_uri)) 
    122146    return SHOES_QUIT; 
     147  if (rb_obj_is_kind_of(load_uri, rb_eSystemExit)) 
     148    return SHOES_QUIT; 
     149  if (rb_obj_is_kind_of(load_uri, rb_eException)) 
     150  { 
     151    VALUE msg = rb_funcall(load_uri, rb_intern("message"), 0); 
     152    printf("%s\n", RSTRING_PTR(msg)); 
     153    return SHOES_QUIT; 
     154  } 
    123155 
    124156  if (rb_obj_is_kind_of(load_uri, rb_cString))