sysjs: automatically cast numbers to f64 & remove dead code

This commit is contained in:
Ali Chraghi 2022-12-25 16:47:37 +03:30 committed by Stephen Gutekanst
parent 2de36ad75b
commit 7df12a0cae
3 changed files with 23 additions and 24 deletions

View file

@ -228,8 +228,15 @@ pub fn createString(string: []const u8) String {
return .{ .ref = js.zigCreateString(string.ptr, @intCast(u32, string.len)) };
}
pub fn createNumber(num: f64) Value {
return .{ .tag = .num, .val = .{ .num = num } };
pub fn createNumber(num: anytype) Value {
switch (@typeInfo(@TypeOf(num))) {
.Int,
.Float,
.ComptimeInt,
.ComptimeFloat,
=> return .{ .tag = .num, .val = .{ .num = std.math.lossyCast(f64, num) } },
else => @compileError("expected integer, found " ++ @typeName(@TypeOf(num))),
}
}
pub fn createBool(val: bool) Value {