Add object support
All checks were successful
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=OFF (push) Successful in 13s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=OFF (push) Successful in 11s
CMake / ubuntu-latest - shared=OFF, pthread=OFF, posix=ON (push) Successful in 13s
CMake / ubuntu-latest - shared=ON, pthread=OFF, posix=ON (push) Successful in 11s
CMake / ubuntu-latest - shared=OFF, pthread=ON, posix=ON (push) Successful in 11s
CMake / ubuntu-latest - shared=ON, pthread=ON, posix=ON (push) Successful in 11s

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2025-07-27 21:56:54 +03:00
parent 93ddf7738c
commit 5fcbb97f7a
3 changed files with 89 additions and 19 deletions

View File

@@ -1,10 +1,18 @@
#include <dcfg.h>
#include <alloca.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
void walk_value(dcfg_Value *value, bool evaluate, int indent);
void walk_value(dcfg_Value *value, bool evaluate, int indent, bool first);
#define WALK(v, e, i) walk_value((v), (e), (i), true)
static void print_indent(int indent)
{
for (int i = 0; i < indent; ++i)
putchar('\t');
}
int main(int argc, char *argv[])
{
@@ -28,21 +36,16 @@ int main(int argc, char *argv[])
return 1;
}
walk_value(value, false, 0);
WALK(value, false, 0);
dcfg_destroy(value);
dcfg_destroy_instance(instance);
}
static void print_indent(int indent)
void walk_value(dcfg_Value *value, bool evaluate, int indent, bool first)
{
for (int i = 0; i < indent; ++i)
putchar('\t');
}
void walk_value(dcfg_Value *value, bool evaluate, int indent)
{
print_indent(indent);
if (first)
print_indent(indent);
dcfg_ValueType type = dcfg_Value_type_ex(value, evaluate);
@@ -97,7 +100,7 @@ void walk_value(dcfg_Value *value, bool evaluate, int indent)
print_indent(indent + 1);
printf("\"%.*s\": ", (int)keys[i].size, keys[i].data);
walk_value(child, evaluate, indent + 1);
walk_value(child, evaluate, indent + 1, false);
if (i + 1 < n)
printf(",");
printf("\n");
@@ -116,7 +119,8 @@ void walk_value(dcfg_Value *value, bool evaluate, int indent)
if (!dcfg_Value_get_array_item_ex(value, i, &item, evaluate))
continue;
walk_value(item, evaluate, indent + 1);
print_indent(indent + 1);
walk_value(item, evaluate, indent + 1, false);
if (i + 1 < sz)
printf(",");
printf("\n");
@@ -129,8 +133,8 @@ void walk_value(dcfg_Value *value, bool evaluate, int indent)
dcfg_Value *body = NULL;
if (dcfg_Value_get_function_body_ex(value, &body, evaluate) && body) {
printf("<fn> ");
walk_value(body, evaluate, indent + 1);
printf("<fn>\t");
walk_value(body, evaluate, indent + 1, false);
} else {
printf("<builtin-fn>");
}
@@ -140,7 +144,7 @@ void walk_value(dcfg_Value *value, bool evaluate, int indent)
if (evaluate) {
dcfg_Value *res;
if (dcfg_Value_evaluate(value, &res))
walk_value(res, evaluate, indent);
walk_value(res, evaluate, indent, first);
else
printf("<error-evaluating-call>");
} else {