Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
set.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_SET */
28#ifdef FUN_WITH_INI
29case OP_INI_SET: {
30 Value vval = pop_value(vm);
31 Value vkey = pop_value(vm);
32 Value vsec = pop_value(vm);
33 Value vh = pop_value(vm);
34 dictionary *d = ini_get((vh.type == VAL_INT) ? (int)vh.i : 0);
35 const char *key = (vkey.type == VAL_STRING) ? vkey.s : NULL;
36 const char *sec = (vsec.type == VAL_STRING) ? vsec.s : NULL;
37 int ok = 0;
38 if (d && sec && key) {
39 char *valstr = value_to_string_alloc(&vval);
40 if (valstr) {
41 char full[1024];
42 char alt[1024];
43 ini_make_full_key(full, sizeof(full), sec, key);
44 memcpy(alt, full, sizeof(alt));
45 for (size_t i = 0; i < sizeof(alt) && alt[i]; ++i) {
46 if (alt[i] == ':') {
47 alt[i] = '.';
48 break;
49 }
50 }
51 /* iniparser 4.x does not expose iniparser_set; use dictionary_set */
52 if (dictionary_set(d, full, valstr) == 0) {
53 ok = 1; /* 0 means success */
54 } else if (dictionary_set(d, alt, valstr) == 0) {
55 ok = 1;
56 }
57 free(valstr);
58 }
59 }
60 free_value(vval);
65 break;
66}
67#endif
free_value(arr)
push_value(vm, copy_value(&v))
@ OP_INI_SET
Definition bytecode.h:209
int ok
Definition contains.c:38
free(vals)
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
char * value_to_string_alloc(const Value *v)
Allocate a printable C string for a Value.
Definition value.c:641
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