Skip to content

Commit

Permalink
Add enum_value to supported interpolated strings
Browse files Browse the repository at this point in the history
  • Loading branch information
bgk- committed Apr 28, 2024
1 parent 9c0c44c commit 328085e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ and [LoLa](https://github.com/MasterQ32/LoLa/tree/master) both of which are cred

## Contributing

Download and install [Zig](https://ziglang.org). Currently Topiary uses version `0.12.0-dev.3686+3adfaf91f`
Download and install [Zig](https://ziglang.org). Currently Topiary uses version `0.12.0`

```
git clone https://github.com/peartreegames/topiary
Expand Down
13 changes: 9 additions & 4 deletions src/vm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -540,17 +540,22 @@ pub const Vm = struct {
close = i;
}
const arg_index = try std.fmt.parseInt(u8, str[open..close], 10);
switch (args[arg_index]) {
const val = args[arg_index];
switch (val) {
.number => |n| {
try std.fmt.format(writer, "{d}", .{n});
},
.bool => |b| try writer.writeAll(if (b) "true" else "false"),
.enum_value => |e| try writer.writeAll(e.base.data.@"enum".values[e.index]),
.obj => |o| {
// remove final 0
try writer.writeAll(o.data.string[0..(o.data.string.len - 1)]);
switch (o.data) {
// remove final 0
.string => try writer.writeAll(o.data.string[0..(o.data.string.len - 1)]),
else => return self.fail("Unsupported interpolated type {s} for {s}", .{ val.typeName(), str }),
}
},
.visit => |v| try std.fmt.formatIntValue(v, "", .{}, list.writer()),
else => return self.fail("Unsupported interpolated type {s} for {s}", .{ args[arg_index].typeName(), str }),
else => return self.fail("Unsupported interpolated type {s} for {s}", .{ val.typeName(), str }),
}
s = i;
}
Expand Down

0 comments on commit 328085e

Please sign in to comment.