Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
unset.c
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2025 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
26
27/* OP_INI_UNSET */
28#ifdef FUN_WITH_INI
29case OP_INI_UNSET: {
30 Value vkey = pop_value(vm);
31 Value vsec = pop_value(vm);
32 Value vh = pop_value(vm);
33 dictionary *d = ini_get((vh.type == VAL_INT) ? (int)vh.i : 0);
34 const char *key = (vkey.type == VAL_STRING) ? vkey.s : NULL;
35 const char *sec = (vsec.type == VAL_STRING) ? vsec.s : NULL;
36 int ok = 0;
37 if (d && sec && key) {
38 char full[1024];
39 char alt[1024];
40 ini_make_full_key(full, sizeof(full), sec, key);
41 memcpy(alt, full, sizeof(alt));
42 for (size_t i = 0; i < sizeof(alt) && alt[i]; ++i) {
43 if (alt[i] == ':') {
44 alt[i] = '.';
45 break;
46 }
47 }
48 /* iniparser 4.2.6 dictionary_unset returns void; remove both forms */
49 dictionary_unset(d, full);
50 dictionary_unset(d, alt);
51 ok = 1;
52 }
56 push_value(vm, make_int(ok));
57 break;
58}
59#endif
@ OP_INI_UNSET
Definition bytecode.h:210
int ok
Definition contains.c:38
Tagged union representing a Fun value.
Definition value.h:68
Value vh
Definition stubs.c:44
Value vsec
Definition stubs.c:43
Value vkey
Definition stubs.c:42
void free_value(Value v)
Free dynamic storage owned by a Value.
Definition value.c:517
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51
@ VAL_STRING
Definition value.h:53
@ VAL_INT
Definition value.h:51