Skip to content

Commit 5854638

Browse files
committed
186 - 4 (beta)
build 4 - use new check type function
1 parent 1bcbff5 commit 5854638

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

int.lua

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
-- ULTIMATE INT --
33
----------------------------------------------------
44
-- MODULE VERSION: 186
5-
-- BUILD VERSION: 3 (24/08/2024) dd:mm:yyyy
6-
-- USER FEATURE: 19/10/2024
7-
-- DEV FEATURE: 19/10/2024
5+
-- BUILD VERSION: 4 (9/12/2024) dd:mm:yyyy
6+
-- USER FEATURE: 9/12/2024
7+
-- DEV FEATURE: 9/12/2024
88
-- AUTHOR: SupTan85
99
-- LICENSE: MIT (the same license as Lua itself)
1010
-- LINK: https://github.com/SupTan85/int.lua
@@ -66,11 +66,14 @@ local master = {
6666
MAXIMUM_LUA_INTEGER = "9223372036854775807" -- math.maxinteger
6767
},
6868

69-
_VERSION = "186"
69+
_VERSION = "186",
70+
_BUILD = "186.4"
7071
}
7172

7273
local OPTION = master._config.OPTION
7374
local ACCURACY_LIMIT = master._config.ACCURACY_LIMIT
75+
local OBJECT_CODENAME = "int object"
76+
local OBJECT_PROFILE = ({(OBJECT_CODENAME):gsub("%s+", "-")})[1] -- auto create profile
7477

7578
---@diagnostic disable-next-line: deprecated
7679
table.unpack = table.unpack or unpack
@@ -85,6 +88,16 @@ local function sign(number) -- Returns -1 if `x < 0`, 0 if `x == 0`, or 1 if `x
8588
return 0
8689
end
8790

91+
local function istableobj(...)
92+
for _, v in ipairs({...}) do
93+
local itype = type(v)
94+
if itype ~= "table" and itype ~= OBJECT_CODENAME then
95+
return false
96+
end
97+
end
98+
return true
99+
end
100+
88101
master.convert = function(st, s)
89102
assert(type(st) == "string" or type(st) == "number", ("[CONVERT] INVALID_INPUT_TYPE | attempt to convert with a '%s'."):format(type(st)))
90103
st, s = tostring(st), s or 1
@@ -110,7 +123,7 @@ master.convert = function(st, s)
110123
end
111124

112125
master.deconvert = function(x)
113-
assert(type(x or error("[DECONVERT] VOID_INPUT")) == "table", ("[DECONVERT] INVALID_INPUT_TYPE | attempt to deconvert with a '%s'."):format(type(x)))
126+
assert(istableobj(x or error("[DECONVERT] VOID_INPUT")), ("[DECONVERT] INVALID_INPUT_TYPE | attempt to deconvert with a '%s'."):format(type(x)))
114127
local em, sm, fm, s = false, {}, {}, x._size or 1
115128
for i = x._dlen or 1, 0 do
116129
local v = tostring(x[i] or error(("[DECONVERT] DAMAGED_OBJECT | missing decimal part value. index[%s]"):format(i)))
@@ -205,7 +218,7 @@ master.custom = {
205218
end,
206219

207220
_floor = function(x) -- Returns the largest integral value smaller than or equal to `x`.
208-
assert(type(x) == "table", ("[FLOOR] INVALID_INPUT_TYPE | x: table (not %s)"):format(type(x)))
221+
assert(istableobj(x or error("[FLOOR] VOID_INPUT")), ("[FLOOR] INVALID_INPUT_TYPE | x: table/%s (not %s)"):format(OBJECT_PROFILE, type(x)))
209222
for i = x._dlen or 1, 0 do
210223
x[i] = nil
211224
end
@@ -215,13 +228,13 @@ master.custom = {
215228

216229
cfloor = function(self, x, length) -- Custom a `x` decimal part. *use ":" to call a function*
217230
assert(type(length) == "number", ("[CFLOOR] INVALID_INPUT_TYPE | length: number (not %s)"):format(type(length)))
218-
assert(type(x) == "table", ("[CFLOOR] INVALID_INPUT_TYPE | x: table (not %s)"):format(type(x)))
231+
assert(istableobj(x or error("[CFLOOR] VOID_INPUT")), ("[CFLOOR] INVALID_INPUT_TYPE | x: table/%s (not %s)"):format(OBJECT_PROFILE, type(x)))
219232
return self._cfloor(x, length, true)
220233
end,
221234

222235
cround = function(self, x, length, center) -- Custom a `x` decimal part, with automatic round system. (`center` The number of rounding centers) *use ":" to call a function*
223236
assert(type(length) == "number", ("[CROUND] INVALID_INPUT_TYPE | length: number (not %s)"):format(type(length)))
224-
assert(type(x) == "table", ("[CROUND] INVALID_INPUT_TYPE | x: table (not %s)"):format(type(x)))
237+
assert(istableobj(x or error("[CROUND] VOID_INPUT")), ("[CROUND] INVALID_INPUT_TYPE | x: table/%s (not %s)"):format(OBJECT_PROFILE, type(x)))
225238
local x, endp, prlen = table.unpack(length == -1 and {x, x._dlen or 1} or {self._cfloor(x, length + 1)})
226239
if prlen and prlen >= 0 then
227240
x = self._refresh(x, tostring(x[endp]):match("(%d)0*$") > (center and tostring(center) or "5") and 1 or 0, endp)
@@ -266,6 +279,14 @@ master.equation = {
266279
}
267280

268281
master.concat = {
282+
_creq = function(self, x, y, force)
283+
assert(type(self) == "table" and self._seek and self._deep, "[CONCAT] BAD_FUNCTIONCALL | can't include required function")
284+
assert(x and y, ("[CONCAT] VOID_INPUT |%s%s"):format(not x and " x: nil (input-required)" or "", not y and " y: nil (input-required)" or ""))
285+
assert(istableobj(x), ("[CONCAT] INVALID_INPUT_TYPE | x: table/%s (not %s)"):format(OBJECT_CODENAME, type(x)))
286+
assert(force or (istableobj(y) and (y._dlen or 1) >= 1) or (not istableobj(y) and tonumber(y) % 1 == 0), "[CONCAT] INVALID_INPUT | y: integer (not decimal)")
287+
return true
288+
end,
289+
269290
_deep = function(var, reverse, dlen) -- Returns number of block, that are start first.
270291
-- BUILD 3
271292
local dlen = dlen or var._dlen or 1
@@ -300,7 +321,7 @@ master.concat = {
300321
end
301322
offset = tonumber(offset) or 0
302323
assert(offset % 1 == 0, "[SEEK] INVALID_INPUT | offset: integer (not decimal)")
303-
if type(var) == "table" then
324+
if istableobj(var) then
304325
local result = {}
305326
local size, dlen = (var._size or 1), (var._dlen or 1)
306327
local shift, skip = offset % size, floor(offset / size)
@@ -349,12 +370,10 @@ master.concat = {
349370

350371
left = function(self, x, y, ignore, shift, copy, force)
351372
-- BUILD 3
352-
assert(type(self) == "table" and self._seek and self._deep, "[CONCAT] BAD_FUNCTIONCALL | can't include required function")
353-
assert(x and y, ("[CONCAT] VOID_INPUT |%s%s"):format(not x and " x: nil (input-required)" or "", not y and " y: nil (input-required)" or ""))
354-
assert(force or (type(y) == "table" and (y._dlen or 1) >= 1) or (type(y) ~= "table" and tonumber(y) % 1 == 0), "[CONCAT] INVALID_INPUT | y: integer (not decimal)")
373+
assert(type(self) == "table" and self._creq and self:_creq(x, y, force), "[CONCAT] BAD_FUNCTIONCALL | can't include required function")
355374
x = copy and master.copy(x) or x
356-
shift = max(shift or 0, 0)
357-
local i, istable = (not ignore and #x or self._deep(x)), type(y) ~= "table"
375+
shift = max(tonumber(shift) or 0, 0)
376+
local i, istable = (not ignore and #x or self._deep(x)), istableobj(y)
358377
local size = x._size or 1
359378
local offset, ishift, skip = 0, shift % size, floor(shift / size)
360379
if shift > 0 and skip > 0 then
@@ -389,13 +408,11 @@ master.concat = {
389408

390409
right = function(self, x, y, ignore, shift, copy, force)
391410
-- BUILD 3
392-
assert(type(self) == "table" and self._seek and self._deep, "[CONCAT] BAD_FUNCTIONCALL | can't include required function")
393-
assert(x and y, ("[CONCAT] VOID_INPUT |%s%s"):format(not x and " x: nil (input-required)" or "", not y and " y: nil (input-required)" or ""))
394-
assert(force or (type(y) == "table" and (y._dlen or 1) >= 1) or (type(y) ~= "table" and tonumber(y) % 1 == 0), "[CONCAT] INVALID_INPUT | y: integer (not decimal)")
411+
assert(type(self) == "table" and self._creq and self:_creq(x, y, force), "[CONCAT] BAD_FUNCTIONCALL | can't include required function")
395412
x = copy and master.copy(x) or x
396-
shift = max(shift or 0, 0)
413+
shift = max(tonumber(shift) or 0, 0)
397414
local dlen = x._dlen or 1
398-
local i, istable = (not ignore and min(dlen, 0) or self._deep(x, true)), type(y) ~= "table"
415+
local i, istable = (not ignore and min(dlen, 0) or self._deep(x, true)), istableobj(y)
399416
local size, dhead, xlogic = x._size or 1, i, (dlen < 1 and #x <= 1)
400417
local offset, ishift, skip = 0, shift % size, floor(shift / size)
401418
if shift > 0 and skip > 0 then
@@ -437,7 +454,7 @@ master.concat = {
437454
master.calculate = {
438455
_verify = function(a, b, MAXIUMUM_SIZE, CODE_NAME)
439456
assert(a and b, ("[%s] VOID_INPUT |%s%s"):format(CODE_NAME or "UNKNOW", not a and " a: nil (input-required)" or "", not b and " b: nil (input-required)" or ""))
440-
assert(type(a) == "table" and type(b) == "table", ("[%s] INVALID_INPUT |%s%s"):format(CODE_NAME or "UNKNOW", type(a) == "table" and "" or (" a: table (not %s)"):format(type(a)), type(b) == "table" and "" or (" b: table (not %s)"):format(type(b))))
457+
assert(istableobj(a, b), ("[%s] INVALID_INPUT |%s%s"):format(CODE_NAME or "UNKNOW", istableobj(a) and "" or (" a: table/%s (not %s)"):format(OBJECT_PROFILE, type(a)), istableobj(b) and "" or (" b: table/%s (not %s)"):format(OBJECT_PROFILE, type(b))))
441458
assert((a._size or 1) == (b._size or 1), ("[%s] INVALID_SIZE_PERBLOCK | _size: (%s != %s)"):format(CODE_NAME or "UNKNOW", a._size or 1, b._size or 1))
442459
assert(not ((a._size or 1) > MAXIUMUM_SIZE), ("[%s] INVALID_SIZE_PERBLOCK | _size: (%s > %s)"):format(CODE_NAME or "UNKNOW", a._size or 1, MAXIUMUM_SIZE))
443460
end,
@@ -632,7 +649,7 @@ master.calculate = {
632649
return false, low
633650
end
634651
if d then
635-
if type(d) == "table" then
652+
if istableobj(d) then
636653
local fp, bp = d[2], d[1]
637654
accuracy = auto_acc and self.sub(accuracy, bp) or accuracy - masterD(bp)
638655
d = {0, _size = s, _dlen = 1}
@@ -747,14 +764,14 @@ local media = {
747764
end,
748765

749766
abs = function(x) -- Returns the absolute value of `x`.
750-
assert(type(x) == "table", ("[ABS] INVALID_INPUT_TYPE | x: table (not %s)"):format(type(x)))
767+
assert(istableobj(x), ("[ABS] INVALID_INPUT_TYPE | x: table/%s (not %s)"):format(OBJECT_PROFILE, type(x)))
751768
x.sign = "+"
752769
return setmetatable(x, master._metatable)
753770
end,
754771

755772
fact = function(n, s) -- Factorial function
756773
local result
757-
if type(n) == "table" then
774+
if istableobj(n) then
758775
result = setmetatable(masterC("1", n._size), master._metatable)
759776
result.sign, n.sign = n.sign or "+", "+"
760777
else
@@ -777,7 +794,7 @@ local media = {
777794
floor = function(x, length) -- Returns the largest integral value smaller than or equal to `x`, or Custom a `x` decimal part.
778795
if x.sign == "-" then
779796
if length then
780-
return setmetatable(length and custom:cround(x, length, 0), master._metatable)
797+
return setmetatable(custom:cround(x, length, 0), master._metatable)
781798
end
782799
return -((x._dlen or 1) < 1 and 1 or 0) + setmetatable(custom._floor(x), master._metatable)
783800
end
@@ -831,7 +848,7 @@ function assets.vtype(...) -- asset for vtype function.
831848
local SOFT, INTEGER = {table = 1}, master._config.SETINTEGER_PERBLOCK.DEFAULT
832849
table.sort(v, function(a, b) return (SOFT[type(a)] or 0) > (SOFT[type(b)] or 0) end)
833850
for _, s in ipairs(v) do
834-
if type(s) == "table" then
851+
if istableobj(s) then
835852
INTEGER = s._size or INTEGER
836853
else
837854
break
@@ -841,7 +858,7 @@ function assets.vtype(...) -- asset for vtype function.
841858
local ty = type(s)
842859
if ty == "string" or ty =="number" then
843860
stack[i] = media.convert(s, INTEGER)
844-
elseif ty == "table" then
861+
elseif istableobj(s) then
845862
stack[i] = s
846863
else
847864
error(("[VTYPE] attempt to perform arithmetic on a (%s) value"):format(ty))
@@ -1093,7 +1110,7 @@ do
10931110
-- Misc --
10941111
__tostring = media.tostring,
10951112
__mode = "v",
1096-
__name = "int object",
1113+
__name = OBJECT_CODENAME,
10971114

10981115
-- Index --
10991116
__index = mediaobj,

0 commit comments

Comments
 (0)