mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
add a getter for a given views size and add some safety when setting the size
This commit is contained in:
parent
12aa7b6448
commit
54c1a976c8
2 changed files with 50 additions and 2 deletions
26
src/lua/LuaUtils.zig
Normal file
26
src/lua/LuaUtils.zig
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
const LuaUtils = @This();
|
||||
|
||||
const std = @import("std");
|
||||
const zlua = @import("zlua");
|
||||
|
||||
pub fn coerceNumber(comptime x: type, number: zlua.Number) error{InvalidNumber}!x {
|
||||
if (number < std.math.minInt(x) or number > std.math.maxInt(x) or std.math.isNan(number)) {
|
||||
return error.InvalidNumber;
|
||||
}
|
||||
switch (@typeInfo(x)) {
|
||||
.int => return @as(x, @intFromFloat(number)),
|
||||
.float => return @floatCast(number),
|
||||
else => @compileError("unsupported type"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn coerceInteger(comptime x: type, number: zlua.Integer) error{InvalidInteger}!x {
|
||||
if (number < std.math.minInt(x) or number > std.math.maxInt(x) or std.math.isNan(number)) {
|
||||
return error.InvalidInteger;
|
||||
}
|
||||
switch (@typeInfo(x)) {
|
||||
.int => return @intCast(number),
|
||||
.float => return @as(x, @floatFromInt(number)),
|
||||
else => @compileError("unsupported type"),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue