moonledger

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/moonledger
Log | Files | Refs

commit 3587d7009072d056cefe384f680d3d75470453f2
parent b6f5efed0f2ab14712c0abd933a83893632cb3d4
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Fri, 19 Aug 2022 12:15:45 -0500

decmath: call D.new when D is called

Diffstat:
Mdecmath.lua | 43++++++++++++++++++++++++++-----------------
1 file changed, 26 insertions(+), 17 deletions(-)

diff --git a/decmath.lua b/decmath.lua @@ -41,23 +41,32 @@ local meta = { end } -return { - new = function (val) - if type(val) == "string" then - -- todo normalize - local asint, count = string.gsub(val, "%.", "") - local pos = string.find(val, "%.") - local dec = {} - setmetatable(dec, meta) - if count == 1 then - dec.sig = imath.new(asint) - dec.exp = pos - #val - elseif count == 0 then - dec.sig = imath.new(asint) - dec.exp = 0 - end - return dec +function new(val) + if type(val) == "string" then + -- todo normalize + local asint, count = string.gsub(val, "%.", "") + local pos = string.find(val, "%.") + local dec = {} + setmetatable(dec, meta) + if count == 1 then + dec.sig = imath.new(asint) + dec.exp = pos - #val + elseif count == 0 then + dec.sig = imath.new(asint) + dec.exp = 0 end - end, + return dec + end +end + +local mod = { + new = new, tostring = asstring } + +setmetatable(mod, {__call = function(tab, val) + return mod.new(val) +end +}) + +return mod