Method: RCSimCinterface.rcsim_add_select_choices

Defined in:
ext/hruby_sim/hruby_rcsim_build.c

.rcsim_add_select_choices(selectV, choiceVs) ⇒ Object

Adds choices to a C select.



1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
# File 'ext/hruby_sim/hruby_rcsim_build.c', line 1459

VALUE rcsim_add_select_choices(VALUE mod, VALUE selectV, VALUE choiceVs) {
    /* Get the C select from the Ruby value. */
    Select select;
    value_to_rcsim(SelectS,selectV,select);
    // printf("rcsim_add_select_choices with select=%p\n",select);
    /* Prepare the size for the choices. */
    long num = RARRAY_LEN(choiceVs);
    long old_num = select->num_choices;
    select->num_choices += num;
    // printf("first select->choices=%p\n",select->choices); fflush(stdout);
    select->choices = realloc(select->choices,
            sizeof(Expression[select->num_choices]));
    // Select->choices = (Expression*)my_realloc(select->choices,
    //         sizeof(Expression[old_num]),sizeof(Expression[select->num_choices]));
    // printf("now select->choices=%p\n",select->choices); fflush(stdout);
    // printf("access test: %p\n",select->choices[0]); fflush(stdout);
    /* Get and add the choices from the Ruby value. */
    for(long i=0; i< num; ++i) {
        Expression choice;
        // show_access(select->choices,old_num+i);
        value_to_rcsim(ExpressionS,rb_ary_entry(choiceVs,i),choice);
        select->choices[old_num + i] = choice;
    }
    return selectV;
}