Open MiranDMC opened 2 months ago
I think type should be set in the constructor.
int_container = create_container type 0
string_container = create_container type 1
container_add int_container 1 2 3
container_add int_container "runtime error"
container_add string_container "ok"
I think type should be set in the constructor.
int_container = create_container type 0 string_container = create_container type 1 container_add int_container 1 2 3 container_add int_container "runtime error" container_add string_container "ok"
How getters will look then?
int_container = create_container type 0
container_add int_container 1 2 3
int x = get_by_index int_container 0 // x= 1
int y = get_by_index int_container 1 // y= 2
int z = get_by_index int_container 2 // z= 3
string_container = create_container type 1
container_add string_container "ok"
longstring s = get_by_index string_container 0 // s= "ok"
names are temporary to illustrate the idea
Will the getter opcode be able in every case to distinguish return parameter type and validate it? Especially float and int types.
addition
int_container = create_container type 0
container_add int_container 1 2 3
int x = get_by_index int_container 0 // x= 1
int y = get_by_index int_container 1 // y= 2
int z = get_by_index int_container 2 // z= 3
string_container = create_container type 1
container_add string_container "this is a very long string that couldn't live in a variable"
int s = get_by_index string_container 0 // s= pointer to "this is a very long string that couldn't live in a variable"
print_help_formatted s // prints "this is a very long string that couldn't live in a variable"
string containers return a pointer.
Will the getter opcode be able in every case to distinguish return parameter type and validate it? Especially float and int types.
I wouldn't care in runtime. you provide a 32-bit variable and runtime either copies the value (if it's int or float) or returns a pointer if it's a string, or other object.
validation can be done in compiler or linter
runtime should keep track of created containers and delete them / free memory when the script ends (on game reload)
Introduce data container feature and opcodes to support it.
Container instance is meant to store single kind of data type. Available types: int, float, text As far as it is technically possible types validation is performed in opcode commands at runtime. In case of mismatch error is thrown.
Class name: container
Opcodes: