Skip to content

Commit f3dec8b

Browse files
committed
Add arguments to defineFunction() calls for specifying secondary type
1 parent 7bbc401 commit f3dec8b

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

json.c

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ char *keys_params_name[] = {
1414
unsigned keys_params_type[] = {
1515
K_DICT
1616
};
17+
unsigned keys_params_secondary_type[] = {
18+
K_ANY
19+
};
1720
unsigned short keys_params_length = (unsigned short) sizeof(keys_params_type) / sizeof(unsigned);
1821
int KAOS_EXPORT Kaos_keys()
1922
{
@@ -40,6 +43,9 @@ char *values_params_name[] = {
4043
unsigned values_params_type[] = {
4144
K_DICT
4245
};
46+
unsigned values_params_secondary_type[] = {
47+
K_ANY
48+
};
4349
unsigned short values_params_length = (unsigned short) sizeof(values_params_type) / sizeof(unsigned);
4450
int KAOS_EXPORT Kaos_values()
4551
{
@@ -86,6 +92,9 @@ char *flip_params_name[] = {
8692
unsigned flip_params_type[] = {
8793
K_DICT
8894
};
95+
unsigned flip_params_secondary_type[] = {
96+
K_ANY
97+
};
8998
unsigned short flip_params_length = (unsigned short) sizeof(flip_params_type) / sizeof(unsigned);
9099
int KAOS_EXPORT Kaos_flip()
91100
{
@@ -117,11 +126,15 @@ char *encode_params_name[] = {
117126
unsigned encode_params_type[] = {
118127
K_DICT
119128
};
129+
unsigned encode_params_secondary_type[] = {
130+
K_ANY
131+
};
120132
unsigned short encode_params_length = (unsigned short) sizeof(encode_params_type) / sizeof(unsigned);
121133
int KAOS_EXPORT Kaos_encode()
122134
{
123135
char *json = kaos.dumpVariableToString(encode_params_name[0], false, true, true);
124136
kaos.returnVariableString(json);
137+
free(json);
125138
return 0;
126139
}
127140

@@ -133,6 +146,9 @@ char *decode_params_name[] = {
133146
unsigned decode_params_type[] = {
134147
K_STRING
135148
};
149+
unsigned decode_params_secondary_type[] = {
150+
K_ANY
151+
};
136152
unsigned short decode_params_length = (unsigned short) sizeof(decode_params_type) / sizeof(unsigned);
137153
int KAOS_EXPORT Kaos_decode()
138154
{
@@ -155,6 +171,10 @@ unsigned search_params_type[] = {
155171
K_DICT,
156172
K_ANY
157173
};
174+
unsigned search_params_secondary_type[] = {
175+
K_ANY,
176+
K_ANY
177+
};
158178
unsigned short search_params_length = (unsigned short) sizeof(search_params_type) / sizeof(unsigned);
159179
int KAOS_EXPORT Kaos_search()
160180
{
@@ -176,6 +196,7 @@ int KAOS_EXPORT Kaos_search()
176196
y_b = kaos.getDictElementBool(search_params_name[0], key);
177197
if (x_b == y_b) {
178198
kaos.returnVariableString(key);
199+
free(key);
179200
return 0;
180201
}
181202
break;
@@ -184,6 +205,7 @@ int KAOS_EXPORT Kaos_search()
184205
y_i = kaos.getDictElementInt(search_params_name[0], key);
185206
if (x_i == y_i) {
186207
kaos.returnVariableString(key);
208+
free(key);
187209
return 0;
188210
}
189211
break;
@@ -192,6 +214,7 @@ int KAOS_EXPORT Kaos_search()
192214
y_f = kaos.getDictElementFloat(search_params_name[0], key);
193215
if (x_f == y_f) {
194216
kaos.returnVariableString(key);
217+
free(key);
195218
return 0;
196219
}
197220
break;
@@ -202,6 +225,7 @@ int KAOS_EXPORT Kaos_search()
202225
free(x_s);
203226
free(y_s);
204227
kaos.returnVariableString(key);
228+
free(key);
205229
return 0;
206230
}
207231
free(x_s);
@@ -213,9 +237,7 @@ int KAOS_EXPORT Kaos_search()
213237
free(key);
214238
}
215239

216-
char *result = malloc(1);
217-
strcpy(result, "");
218-
kaos.returnVariableString(result);
240+
kaos.returnVariableString("");
219241
return 0;
220242
}
221243

@@ -231,6 +253,11 @@ unsigned replace_params_type[] = {
231253
K_ANY,
232254
K_ANY
233255
};
256+
unsigned replace_params_secondary_type[] = {
257+
K_ANY,
258+
K_ANY,
259+
K_ANY
260+
};
234261
unsigned short replace_params_length = (unsigned short) sizeof(replace_params_type) / sizeof(unsigned);
235262
int KAOS_EXPORT Kaos_replace()
236263
{
@@ -312,6 +339,9 @@ char *count_params_name[] = {
312339
unsigned count_params_type[] = {
313340
K_DICT
314341
};
342+
unsigned count_params_secondary_type[] = {
343+
K_ANY
344+
};
315345
unsigned short count_params_length = (unsigned short) sizeof(count_params_type) / sizeof(unsigned);
316346
int KAOS_EXPORT Kaos_count()
317347
{
@@ -325,20 +355,20 @@ int KAOS_EXPORT KaosRegister(struct Kaos _kaos)
325355
kaos = _kaos;
326356

327357
// Dictionary Operations
328-
kaos.defineFunction("keys", K_LIST, K_ANY, keys_params_name, keys_params_type, keys_params_length, NULL, 0);
329-
kaos.defineFunction("values", K_LIST, K_ANY, values_params_name, values_params_type, values_params_length, NULL, 0);
330-
kaos.defineFunction("flip", K_DICT, K_ANY, flip_params_name, flip_params_type, flip_params_length, NULL, 0);
358+
kaos.defineFunction("keys", K_LIST, K_ANY, keys_params_name, keys_params_type, keys_params_secondary_type, keys_params_length, NULL, 0);
359+
kaos.defineFunction("values", K_LIST, K_ANY, values_params_name, values_params_type, values_params_secondary_type, values_params_length, NULL, 0);
360+
kaos.defineFunction("flip", K_DICT, K_ANY, flip_params_name, flip_params_type, flip_params_secondary_type, flip_params_length, NULL, 0);
331361

332362
// JSON Related
333-
kaos.defineFunction("encode", K_STRING, K_ANY, encode_params_name, encode_params_type, encode_params_length, NULL, 0);
334-
kaos.defineFunction("decode", K_DICT, K_ANY, decode_params_name, decode_params_type, decode_params_length, NULL, 0);
363+
kaos.defineFunction("encode", K_STRING, K_ANY, encode_params_name, encode_params_type, encode_params_secondary_type, encode_params_length, NULL, 0);
364+
kaos.defineFunction("decode", K_DICT, K_ANY, decode_params_name, decode_params_type, decode_params_secondary_type, decode_params_length, NULL, 0);
335365

336366
// Searching & Replacing
337-
kaos.defineFunction("search", K_STRING, K_ANY, search_params_name, search_params_type, search_params_length, NULL, 0);
338-
kaos.defineFunction("replace", K_DICT, K_ANY, replace_params_name, replace_params_type, replace_params_length, NULL, 0);
367+
kaos.defineFunction("search", K_STRING, K_ANY, search_params_name, search_params_type, search_params_secondary_type, search_params_length, NULL, 0);
368+
kaos.defineFunction("replace", K_DICT, K_ANY, replace_params_name, replace_params_type, replace_params_secondary_type, replace_params_length, NULL, 0);
339369

340370
// Information Functions
341-
kaos.defineFunction("count", K_NUMBER, K_ANY, count_params_name, count_params_type, count_params_length, NULL, 0);
371+
kaos.defineFunction("count", K_NUMBER, K_ANY, count_params_name, count_params_type, count_params_secondary_type, count_params_length, NULL, 0);
342372

343373
return 0;
344374
}

occultist.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "JSON library of the Chaos langauge.",
55
"tags": ["official", "json", "dict"],
66
"type": "extension",

0 commit comments

Comments
 (0)