source: EcnlProtoTool/trunk/prototool/src/cmdprint.c@ 439

Last change on this file since 439 was 439, checked in by coas-nagasima, 4 years ago

mrubyを2.1.1に更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 1.6 KB
Line 
1/*
2** cmdprint.c - mruby debugger print command functions
3**
4*/
5
6#include <string.h>
7#include "mrdb.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>
14#include "apiprint.h"
15
16dbgcmd_state
17dbgcmd_print(mrb_state *mrb, mrdb_state *mrdb)
18{
19 mrb_value expr;
20 mrb_value result;
21 uint8_t wcnt;
22 int ai;
23
24 if (mrdb->wcnt <= 1) {
25 puts("Parameter not specified.");
26 return DBGST_PROMPT;
27 }
28
29 ai = mrb_gc_arena_save(mrb);
30
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 }
37
38 result = mrb_debug_eval(mrb, mrdb->dbg, RSTRING_PTR(expr), RSTRING_LEN(expr), NULL, 0);
39
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);
44
45 if (mrdb->print_no == 0) {
46 mrdb->print_no = 1;
47 }
48
49 mrb_gc_arena_restore(mrb, ai);
50
51 return DBGST_PROMPT;
52}
53
54dbgcmd_state
55dbgcmd_eval(mrb_state *mrb, mrdb_state *mrdb)
56{
57 return dbgcmd_print(mrb, mrdb);
58}
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 TracBrowser for help on using the repository browser.