From e785dae64d951e707980259380df8586c3d66b02 Mon Sep 17 00:00:00 2001 From: Darxo Date: Sat, 17 Feb 2024 15:33:49 +0100 Subject: [PATCH 1/2] feat: add type checker for unsigned integers --- msu/utils/type_checkers.nut | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/msu/utils/type_checkers.nut b/msu/utils/type_checkers.nut index 8a8eb4202..132feb3ed 100644 --- a/msu/utils/type_checkers.nut +++ b/msu/utils/type_checkers.nut @@ -8,6 +8,19 @@ ::MSU.requireTypeArray("integer", vargv); } +::MSU.requireUnsigned <- function( ... ) +{ + ::MSU.requireTypeArray("integer", vargv); + foreach (value in vargv) + { + if (value < 0) + { + ::logError(value + " must have the type: unsigned"); + throw ::MSU.Exception.InvalidType(value); + } + } +} + ::MSU.requireArray <- function( ... ) { ::MSU.requireTypeArray("array", vargv); From 0fa21c83efe5b2009e5d088be1168d434b778f7b Mon Sep 17 00:00:00 2001 From: Darxo Date: Mon, 4 Mar 2024 08:40:57 +0100 Subject: [PATCH 2/2] refactor: rename function and improve exception feedback --- msu/utils/type_checkers.nut | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/msu/utils/type_checkers.nut b/msu/utils/type_checkers.nut index 132feb3ed..e8cc3e71a 100644 --- a/msu/utils/type_checkers.nut +++ b/msu/utils/type_checkers.nut @@ -8,12 +8,11 @@ ::MSU.requireTypeArray("integer", vargv); } -::MSU.requireUnsigned <- function( ... ) +::MSU.requireUInt <- function( ... ) { - ::MSU.requireTypeArray("integer", vargv); foreach (value in vargv) { - if (value < 0) + if (typeof value != "integer" || value < 0) { ::logError(value + " must have the type: unsigned"); throw ::MSU.Exception.InvalidType(value);