Using the Device Modeling Language (DML), version 1.4.
I create a param of lists like
param X = [ [0, 0, 0], [0, 0, 1].......];
And I want to access them in a method using variable like
method get_var(uint32 idx) -> (uint32) {
return X[idx][0];
}
But when I try to compile it says I cannot use variable index in a constant list.
Is there a different data type that I should be using other than param to allow this? Or is there a way to define "idx" as a const so it could be used?
The workaround that I currently have is creating a session variable and copying the param list over during post_init() since then I'm allowed to access that session variable using variable index. I don't know if it's the best way to handle that.
The traditional approach (popular in DML 1.2) is to use
#foreach:This approach will however unroll the for loop, so it should be used with care if the list can be large.
Also, note that in other
#foreachuse cases where the loop body is somewhat large, you should break out the body into a separate method. Yourget_varmethod is in fact one good example of how to do that.