added solstice support to the collections lib

This commit is contained in:
2026-04-12 09:47:27 +10:00
parent f6c59a61d3
commit aa0c71a47b
5 changed files with 48 additions and 11 deletions

View File

@@ -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);
}