Skip to content

Commit ffa2205

Browse files
committed
fix: toNumeric raises a Zig error
1 parent 3ea22a6 commit ffa2205

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/lib.zig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,14 +2596,12 @@ pub const Lua = opaque {
25962596

25972597
/// Converts the Lua value at the given `index` to a numeric type;
25982598
/// if T is an integer type, the Lua value is converted to an integer.
2599-
/// The conversion from `Integer` or `Number` to T is performed with `@_Cast`,
2600-
/// which will assert in builds with runtime safety enabled
26012599
///
26022600
/// * Pops: `0`
26032601
/// * Pushes: `0`
2604-
/// * Errors: `never`
2602+
/// * Errors: `error.IntegerCastFailed` if `T` is an integer type and the value at index doesn't fit
26052603
pub fn toNumeric(lua: *Lua, comptime T: type, index: i32) !T {
2606-
if (@typeInfo(T) == .int) return @intCast(try lua.toInteger(index));
2604+
if (@typeInfo(T) == .int) return std.math.cast(try lua.toInteger(index)) orelse error.IntegerCastFailed;
26072605
return @floatCast(try lua.toNumber(index));
26082606
}
26092607

0 commit comments

Comments
 (0)