2 replies
Dec '14

cristian_slav_ifb Imported from Blogger

You can also try this:

get_reg_side(reg_index : uint, side_index : uint) : uint is {
var reg := graphics_model.graphics_regs.get_reg_by_kind(appendf(“TRIANGLE%d”, reg_index).as_a(vr_ad_reg_kind));
var fld_name : string = appendf(“SIDE%d”, side_index);
var field_info := reg.static_info.fields_info.first(it.fld_name == fld_name);
return reg.get_cur_value()[(field_info.fld_fidx + field_info.fld_size - 1):field_info.fld_fidx];
};

You should also include protection for the values of reg_index and side_index

1 reply
Dec '14 ▶ cristian_slav_ifb

TudorTimi Verification Gentleman

You’re right! This also removes the need to do reflection. I was so fixed on that idea that I forgot about get_reg_by_kind(…).

What I also usually do is define an extra method inside vr_ad_reg, called get_field_by_name(fld_name : string). This basically does what your snippet does (including asserts, etc.). I find it really handy.