'Sup! This is my linear (non-MDAS ig?) basic calculator that takes string expressions! Is there any way this could be done better or more efficiently? I’m also wondering if how I can it MDAS compatible. Advices and tips are greatly appreciated!!!
local expression = "65 / 8 + 34 - 9 * 03"
local contents = string.split(expression," ")
local n = contents[1]
local operators = {
["+"] = function(x)
n += x
end,
["-"] = function(x)
n -= x
end,
["*"] = function(x)
n *= x
end,
["/"] = function(x)
n /= x
end,
}
for i, v in ipairs(contents) do
if i % 2 == 0 then
operators[v](tonumber(contents[i+1]))
end
end
print(n) --> 99.375