diff options
Diffstat (limited to 'bridge/convert.zig')
| -rw-r--r-- | bridge/convert.zig | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/bridge/convert.zig b/bridge/convert.zig new file mode 100644 index 0000000..5718428 --- /dev/null +++ b/bridge/convert.zig @@ -0,0 +1,18 @@ +const std = @import("std"); +const revo = @import("revo"); + +pub const HostResult = revo.baselib.host.HostResult; +pub const Data = revo.Value; + +// revos only number type is f64 which is really fucking annoying +pub fn f64ToInt(comptime T: type, n: f64) ?T { + if (!std.math.isFinite(n)) return null; + const min_f: f64 = @floatFromInt(std.math.minInt(T)); + const max_f: f64 = @floatFromInt(std.math.maxInt(T)); + if (n < min_f or n > max_f) return null; + return @intFromFloat(n); +} + +pub fn argInt(comptime T: type, args: []const revo.Value, i: usize) ?T { + return f64ToInt(T, args[i].asNumOpt().?); +} |
