These are chat archives for ChaiScript/ChaiScript

3rd
Jan 2017
StanEpp
@StanEpp
Jan 03 2017 02:27

@emersont1 Hi! Here is a simple example:

class MyClass {
    attr val;
    def MyClass() {this.val = 0;}
    def incr(x){ this.val += x;}
}

var arr = [];
for(auto i = 0; i < 4; ++i){
    arr.push_back(MyClass());
    arr[i].incr(i);
}
for(auto i = 0; i < 4; ++i){
    puts(arr[i].val);
    puts("\n");
}

If you got a map, and you want to iterate through all objects in it you can use for_each like for_each(mapWithObjects, fun(x){puts(x.second.val);});

Peter Taylor
@emersont1
Jan 03 2017 08:52
@StanEpp, sorry i didn't explain myself fully. can it be done if MyClass is a C++ Class