calculation = "1+1" print(calculation) --output: 1+1
How do I unstringify this in Roblox Lua? I don't want to use loadstring due to security issues nor does math.eval work...
What are my options to make this work?
I've tried to format it like this but it doesn't work, it outputs nil:
--I used string.byte to get the values of 1 and + and then I did this: print(tonumber(string.char(49)) .. string.char(43)) .. tonumber(string.char(49))) --I want to calculate it in a print but it doesn't work.
The characters + and -, are they strings or numbers???
I have made a new script to calculate it.
local calculate = "3+31" print(calculate) print() local num1 = nil local numA = nil local symbol = nil local num2 = nil for i = 1,100,1 do local sub = calculate:sub(1,i) if tonumber(sub) ~= nil then num1 = sub numA = i end end symbol = calculate:sub(numA+1,numA+1) for i = numA+2,100,1 do local sub = calculate:sub(numA+2,i) if tonumber(sub) ~= nil then num2 = sub end end if symbol == "+" then print(num1 + num2) elseif symbol == "-" then print(num1 - num2) elseif symbol == "*" then print(num1 * num2) elseif symbol == "/" then print(num1 / num2) elseif symbol == "^" then print(num1 ^ num2) elseif symbol == "%" then print(num1 % num2) end
idk what unstring mean so i just be dumb and put this
print(1 + 1) -- output: 2