Download
(4 Kb)
Download
Updated: 02/05/24 05:50 AM
Compatibility:
Endless Archive (9.2.5)
Updated:02/05/24 05:50 AM
Created:01/31/24 10:33 AM
Monthly downloads:1,295
Total downloads:3,128
Favorites:2
MD5:
LibLuaInts
Version: 1.1
by: akamatsu02 [More]
This library adds specific number types to lua.

Supported types:
  • Signed: sbyte (Int8), short (Int16), int (Int32), long (Int64)
  • Unsigned: byte (uInt8), ushort (uInt16), uint (uInt32), ulong (uInt64)

Create a new number:
value: Any value as number, string or hex
bits: Amount of bits that the number should have
isSigned: defines if the number has negative values or not
bitArray: An array of bits (either 0 or 1)
Code:
-- 1:
local <Int> num = sbyte(<number/string/hex> value) -- works with all supported types

-- 2:
local <Int> num = Int8(<number/string/hex> value) -- works with all supported types

-- 3:
local <Int> num = Int:new(<positive number> bits, <boolean> isSigned, <number/string/hex> value)

-- 4:
local <Int> num = Int:fromArray(<table> bitArray, <boolean> isSigned)
Get the value:
Code:
local <Int> resultInt = int(<number/string/hex> value)-- this returns the Int object
local <number> value = resultInt:GetValue() -- this returns the number value of the object
Math Calculations:
Currently supported: Add, Sub, Mul, Div
Code:
local <Int> value1 = int(<number/string/hex> value1)
local <Int> value2 = int(<number/string/hex> value2)

-- Addition:
local <Int> result = value1:Add(value2)

-- Subtraction:
local <Int> result = value1:Sub(value2)

-- Multiplication:
local <Int> result = value1:Mul(value2)

-- Division:
local <Int> result = value1:Div(value2)

-- Increase by 1:
local <Int> result = value1:Increase()

-- Decrease by 1:
local <Int> result = value1:Decrease()

-- Increase by 1:
local <Int> result = value1:Increase()

-- Get the absolute value:
local <Int> result = value1:Abs()

-- Get the negative value:
local <Int> result = value1:Neg()
Comparators:
Code:
local <Int> value1 = int(<number/string/hex> value1)
local <Int> value2 = int(<number/string/hex> value2)

-- check if value is 0
local <boolean> result = value1:IsNull()

-- check if value is a negative signed number
local <boolean> result = value1:IsSignedNegative()

-- check if value1 is smaller than value2
local <boolean> result = value1:IsSmallerThan(value2)

-- check if value1 is greater than value2
local <boolean> result = value1:IsGreaterThan(value2)

-- check if value1 is equal to value2
local <boolean> result = value1:IsEqualTo(value2)
Conversions:
Code:
local <Int> value = int(<number/string/hex> value)

-- signed to unsigned
local <Int> result = value:ToUnsigned()

-- unsigned to signed
local <Int> result = value:ToSigned()

-- copy the value without object reference
local <Int> result = value:Copy()

-- create a new value (default 0) with the same type
local <Int> result = value:CopyType(<number/string/hex/nil> optionalValue)

-- set value to the maximum value
local <Int> result = value:ToMaxValue()

-- set value to the minimum value
local <Int> result = value:ToMinValue()
Bit Operations:
Code:
local <Int> value1 = int(<number/string/hex> value1)
local <Int> value2 = int(<number/string/hex> value2)

-- Rshift: 
-- uses the standard shift for signed (arithmetic shift)/unsigned (logical shift) numbers
local <Int> result = value1:Rshift(<positive number> shifts)

-- Lshift: 
-- uses the standard shift for signed (arithmetic shift)/unsigned (logical shift) numbers
local <Int> result = value1:Lshift(<positive number> shifts)

-- LogicalRshift: 
local <Int> result = value1:LogicalRshift(<positive number> shifts)

-- LogicalLshift: 
local <Int> result = value1:LogicalLshift(<positive number> shifts)

-- ArithmeticRshift: 
local <Int> result = value1:ArithmeticRshift(<positive number> shifts)

-- ArithmeticLshift: 
local <Int> result = value1:ArithmeticLshift(<positive number> shifts)

-- CircularRshift: 
local <Int> result = value1:CircularRshift(<positive number> shifts)

-- CircularLshift: 
local <Int> result = value1:CircularLshift(<positive number> shifts)

-- And: 
local <Int> result = value1:And(value2)

-- Or: 
local <Int> result = value1:Or(value2)

-- Xor: 
local <Int> result = value1:Xor(value2)

-- Not: 
local <Int> result = value1:Not()
1.1: Added some new functions and implemented bitwise multiplication
Archived Files (1)
File Name
Version
Size
Uploader
Date
1.0
8kB
akamatsu02
01/31/24 10:39 AM


There have been no comments posted to this file.
Be the first to add one.



Category Jump: