Ignore:
Timestamp:
Jul 9, 2020, 8:51:43 AM (4 years ago)
Author:
coas-nagasima
Message:

mrubyを2.1.1に更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/prototool/src/cmdprint.c

    r321 r439  
    44*/
    55
    6 #include <stdlib.h>
    7 
     6#include <string.h>
    87#include "mrdb.h"
    9 #include "mruby/value.h"
    10 #include "mruby/class.h"
    11 #include "mruby/compile.h"
    12 #include "mruby/error.h"
    13 #include "mruby/numeric.h"
    14 #include "mruby/string.h"
     8#include <mruby/value.h>
     9#include <mruby/class.h>
     10#include <mruby/compile.h>
     11#include <mruby/error.h>
     12#include <mruby/numeric.h>
     13#include <mruby/string.h>
    1514#include "apiprint.h"
    1615
     
    1817dbgcmd_print(mrb_state *mrb, mrdb_state *mrdb)
    1918{
    20         mrb_value expr;
    21         mrb_value result;
    22         mrb_value s;
    23         uint8_t wcnt;
    24         int ai;
     19  mrb_value expr;
     20  mrb_value result;
     21  uint8_t wcnt;
     22  int ai;
    2523
    26         if (mrdb->wcnt <= 1) {
    27                 puts("Parameter not specified.");
    28                 return DBGST_PROMPT;
    29         }
     24  if (mrdb->wcnt <= 1) {
     25    puts("Parameter not specified.");
     26    return DBGST_PROMPT;
     27  }
    3028
    31         ai = mrb_gc_arena_save(mrb);
     29  ai = mrb_gc_arena_save(mrb);
    3230
    33         /* eval expr */
    34         expr = mrb_str_new_cstr(mrb, NULL);
    35         for (wcnt = 1; wcnt < mrdb->wcnt; wcnt++) {
    36                 expr = mrb_str_cat_lit(mrb, expr, " ");
    37                 expr = mrb_str_cat_cstr(mrb, expr, mrdb->words[wcnt]);
    38         }
     31  /* eval expr */
     32  expr = mrb_str_new_cstr(mrb, NULL);
     33  for (wcnt=1; wcnt<mrdb->wcnt; wcnt++) {
     34    expr = mrb_str_cat_lit(mrb, expr, " ");
     35    expr = mrb_str_cat_cstr(mrb, expr, mrdb->words[wcnt]);
     36  }
    3937
    40         result = mrb_debug_eval(mrb, mrdb->dbg, RSTRING_PTR(expr), RSTRING_LEN(expr), NULL);
     38  result = mrb_debug_eval(mrb, mrdb->dbg, RSTRING_PTR(expr), RSTRING_LEN(expr), NULL, 0);
    4139
    42         /* $print_no = result */
    43         s = mrb_str_cat_lit(mrb, result, "\0");
    44         printf("$%lu = %s\n", (unsigned long)mrdb->print_no++, RSTRING_PTR(s));
     40  /* $print_no = result */
     41  printf("$%lu = ", (unsigned long)mrdb->print_no++);
     42  fwrite(RSTRING_PTR(result), RSTRING_LEN(result), 1, stdout);
     43  putc('\n', stdout);
    4544
    46         if (mrdb->print_no == 0) {
    47                 mrdb->print_no = 1;
    48         }
     45  if (mrdb->print_no == 0) {
     46    mrdb->print_no = 1;
     47  }
    4948
    50         mrb_gc_arena_restore(mrb, ai);
     49  mrb_gc_arena_restore(mrb, ai);
    5150
    52         return DBGST_PROMPT;
     51  return DBGST_PROMPT;
    5352}
    5453
     
    5655dbgcmd_eval(mrb_state *mrb, mrdb_state *mrdb)
    5756{
    58         return dbgcmd_print(mrb, mrdb);
     57  return dbgcmd_print(mrb, mrdb);
    5958}
     59
     60dbgcmd_state
     61dbgcmd_info_local(mrb_state *mrb, mrdb_state *mrdb)
     62{
     63  mrb_value result;
     64  mrb_value s;
     65  int ai;
     66
     67  ai = mrb_gc_arena_save(mrb);
     68
     69  result = mrb_debug_eval(mrb, mrdb->dbg, "local_variables", 0, NULL, 1);
     70
     71  s = mrb_str_cat_lit(mrb, result, "\0");
     72  printf("$%lu = %s\n", (unsigned long)mrdb->print_no++, RSTRING_PTR(s));
     73
     74  if (mrdb->print_no == 0) {
     75    mrdb->print_no = 1;
     76  }
     77
     78  mrb_gc_arena_restore(mrb, ai);
     79
     80  return DBGST_PROMPT;
     81}
Note: See TracChangeset for help on using the changeset viewer.