Add $member.get(value) to replace value.$eval($member.nameof)

This commit is contained in:
Christoffer Lerno
2024-08-20 14:24:12 +02:00
parent 0963ab4cc0
commit fb4a231703
13 changed files with 106 additions and 18 deletions

View File

@@ -25,7 +25,7 @@ macro deep_print(a)
io::print("{");
$foreach ($i, $m : $typeof(a).membersof)
if ($i > 0) io::print(", ");
deep_print(a.$eval($m.nameof));
deep_print($m.get(a));
$endforeach
io::print("}");
$default:

View File

@@ -74,7 +74,7 @@ fn void! TextTemplate.init(&self, String template, String tag_start = "{{", Stri
.data = (String*)(data + $m.offsetof),
};
$default:
$if $defined(self.data.$eval($m.nameof).as_stream):
$if $defined($m.get(self.data).as_stream):
return TextTag{
.kind = TEMPLATE,
.template = self.data.$eval($m.nameof).as_stream(),

View File

@@ -71,6 +71,8 @@ fn void methodsof()
Foo foo = { .i = 4, .b = true };
assert(Foo.$eval(Foo.methodsof[2])(&foo) == true); // Foo.xyz
assert(Foo.$eval(Foo.methodsof[1])(&foo, 2) == 8); // Foo.bar
assert(Foo.$eval(Foo.methodsof[2])(&foo) == true); // Foo.xyz
assert(Foo.$eval(Foo.methodsof[1])(&foo, 2) == 8); // Foo.bar
Foo foo2 = { .i = 2, .b = false };
assert(foo2.$eval(Foo.methodsof[2])() == false); // Foo.xyz