forked from ground/ground
added solstice support to the collections lib
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include <uthash.h>
|
||||
#include <stdio.h>
|
||||
|
||||
GroundStruct hashmapStruct = {};
|
||||
|
||||
GroundValue hashmapStructSet(GroundScope* scope, List args) {
|
||||
char* key = args.values[0].data.stringVal;
|
||||
GroundValue value = args.values[1];
|
||||
@@ -117,8 +119,14 @@ GroundValue hashmapStructRemoveIfPresent(GroundScope* scope, List args) {
|
||||
return groundCreateValue(BOOL, true);
|
||||
}
|
||||
|
||||
GroundValue createHashmapStruct() {
|
||||
GroundStruct hashmapStruct = groundCreateStruct();
|
||||
GroundValue hashmapStructConstructor(GroundScope* scope, List args) {
|
||||
GroundValue value = groundCreateValue(CUSTOM, &hashmapStruct);
|
||||
value.type = CUSTOM;
|
||||
return value;
|
||||
}
|
||||
|
||||
void initHashmaps(GroundScope* scope) {
|
||||
hashmapStruct = groundCreateStruct();
|
||||
|
||||
groundAddFieldToStruct(&hashmapStruct, "private_ptr", groundCreateValue(INT, 0));
|
||||
|
||||
@@ -128,5 +136,6 @@ GroundValue createHashmapStruct() {
|
||||
groundAddFunctionToStruct(&hashmapStruct, "remove", hashmapStructRemove, INT, 1, STRING, "key"); // remove a key from the hashmap, throws KeyNotFound if the key does not exist
|
||||
groundAddFunctionToStruct(&hashmapStruct, "removeIfPresent", hashmapStructRemoveIfPresent, BOOL, 1, STRING, "key"); // remove a key from the hashmap, returns true if the key was removed or false if it didn't exist
|
||||
|
||||
return groundCreateValue(STRUCTVAL, hashmapStruct);
|
||||
groundAddNativeFunction(scope, "newHashmap", hashmapStructConstructor, CUSTOM, 0);
|
||||
groundAddNativeFunction(scope, "Hashmap_SOLS_CONSTRUCTOR", hashmapStructConstructor, CUSTOM, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user