Closed skx closed 4 years ago
Sample program:
frodo ~/Repos/github.com/skx/evalfilter/cmd/evalfilter $ cat hash.in
a = { "Name": "Steve", "Age": 2020 - 1976 }
printf("I am %s - %d\n", a["Name"], a["Age"] );
This works!
frodo ~/Repos/github.com/skx/evalfilter/cmd/evalfilter $ ./evalfilter run hash.in
I am Steve - 44
Script gave result type:NULL value:null - which is 'false'.
To support foreach
our signature needs to change from:
Object, int, bool
To :
Object, Object, bool
Next up ..
Test-coverage needs to be improved, and documentation added; otherwise things work as you'd expect:
// Declare a hash
printf("Creating hash\n")
a = { "Name": "Steve", "Age": 2020 - 1976 }
// Get the keys which are present in the hash:
k = keys(a);
// Show the keys and their values
printf("Iterating over the hash via the output of keys():\n");
foreach name in k {
printf("\tKEY:%s Value:'%s'\n", name, string(a[name]))
}
// Now do the same thing in one go, via our iteration interface.
printf("Iterating via foreach key,value:\n");
foreach key, value in a {
printf("\t%s -> %s\n", key, string(value) )
}
// Finally test the index-operation
printf("I am %s - %d\n", a["Name"], a["Age"] );
printf("My hash is %s\n", string(a));
printf("My hash has len %d\n", len(a))
Of course I've not considered what happens if a user passes a map/interface from the golang side to the scripting language. It might be that the reflection code all needs to be updated.
If so I can handle that seperetely, as the language core now contains "hash-support".
This pull-request will add support for Hashes, to our parser, run-time, and evaluation engine.
Once complete #154 will be closed.