mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
cmdprint.c: extract next_print_no() helper
Consolidate the duplicated print_no increment-and-wrap logic from dbgcmd_print() and dbgcmd_info_local() into a single next_print_no() function. Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,14 @@
|
||||
#include <mruby/string.h>
|
||||
#include "apiprint.h"
|
||||
|
||||
static uint32_t
|
||||
next_print_no(mrdb_state *mrdb)
|
||||
{
|
||||
uint32_t no = mrdb->print_no++;
|
||||
if (mrdb->print_no == 0) mrdb->print_no = 1;
|
||||
return no;
|
||||
}
|
||||
|
||||
dbgcmd_state
|
||||
dbgcmd_print(mrb_state *mrb, mrdb_state *mrdb)
|
||||
{
|
||||
@@ -33,14 +41,10 @@ dbgcmd_print(mrb_state *mrb, mrdb_state *mrdb)
|
||||
mrb_value result = mrb_debug_eval(mrb, mrdb->dbg, RSTRING_PTR(expr), RSTRING_LEN(expr), NULL, 0);
|
||||
|
||||
/* $print_no = result */
|
||||
printf("$%lu = ", (unsigned long)mrdb->print_no++);
|
||||
printf("$%lu = ", (unsigned long)next_print_no(mrdb));
|
||||
fwrite(RSTRING_PTR(result), RSTRING_LEN(result), 1, stdout);
|
||||
putc('\n', stdout);
|
||||
|
||||
if (mrdb->print_no == 0) {
|
||||
mrdb->print_no = 1;
|
||||
}
|
||||
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
|
||||
return DBGST_PROMPT;
|
||||
@@ -59,11 +63,7 @@ dbgcmd_info_local(mrb_state *mrb, mrdb_state *mrdb)
|
||||
|
||||
mrb_value result = mrb_debug_eval(mrb, mrdb->dbg, "local_variables", 0, NULL, 1);
|
||||
mrb_value s = mrb_str_cat_lit(mrb, result, "\0");
|
||||
printf("$%lu = %s\n", (unsigned long)mrdb->print_no++, RSTRING_PTR(s));
|
||||
|
||||
if (mrdb->print_no == 0) {
|
||||
mrdb->print_no = 1;
|
||||
}
|
||||
printf("$%lu = %s\n", (unsigned long)next_print_no(mrdb), RSTRING_PTR(s));
|
||||
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user