I’ve now finished implementing arrays in my scripting language. For now, they’re not dynamically sized, and they need all their arguments when first created.
I.e. you need to write:
1 |
int[] anArray = {24,252,-24}; |
You can’t write
1 2 |
int[] anArray; anArray = {24,252,-24}; |
You can otherwise access array elements and update them as necessary. All regular automatic type conversion is handled. So:
1 |
int[] anArray = {"2949",234,52}; |
Will work. However, it does it a bit of a round-about way. The first element in an array value, everything between the { and } is used to determine the type of the array. In the above case it’s a string array.
Then, each subsequent element is type-converted to this type. So this becomes an array of strings.
Then the assignment of a string array value to an int array variable will cause a conversion from a string array to an int array.
If the first element was an int and not a string, only the first conversion takes place.
But, this allows me to keep the any-type to any-type conversion I wanted.