 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Nighthawyun Cheater
Reputation: 0
Joined: 21 Jan 2019 Posts: 27
|
Posted: Sat May 25, 2019 9:08 pm Post subject: how to make calculator with string like "213 + 42 - 124 |
|
|
how?
ex)
string "899 + 6 - 33" to result "872"
and ×, ÷ too
|
|
| Back to top |
|
 |
TheyCallMeTim13 Wiki Contributor
Reputation: 51
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Sat May 25, 2019 9:46 pm Post subject: |
|
|
| Code: | | print(loadstring("return " .. "899 + 6 - 33")()) |
_________________
|
|
| Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Sat May 25, 2019 10:28 pm Post subject: |
|
|
A bit safer way to accomplish this and more dynamic.
| Code: | local action = {['+']= function(a,b)return a + b;end;
['-']= function(a,b)return a - b;end;
['*']= function(a,b)return a * b;end;
['/']= function(a,b)return a / b;end;
['//']=function(a,b)return a// b;end; --> math.floor equivalent
['%']= function(a,b)return a % b;end;
['^']= function(a,b)return a ^ b;end;
};
debug.setmetatable(0, {
__call = function(a, op)
if(action[op]) then
return function(b)
return action[op](a,b)
end
else
error("Wrong syntax", 2)
end
end
})
function calculate(Param1,Op,Param2,...)
if (tonumber(Param1) and action[Op] and tonumber(Param2)) then
return calculate(((Param1) (Op) (Param2)),...);
end
return Param1;
end
local a = calculate(1,'+',2) --> 3
local b = calculate(3,'+',1,'*',2,'%',3) --> ((3+1) * 2 ) % 3 --> 2 Operations priority do not apply here!
|
_________________
I'm rusty and getting older, help me re-learn lua. |
|
| Back to top |
|
 |
Corroder Grandmaster Cheater Supreme
Reputation: 75
Joined: 10 Apr 2015 Posts: 1668
|
Posted: Sun May 26, 2019 12:10 am Post subject: |
|
|
Here is my Calculator made using CE Lua script.
It's 95% finish. Some parts did not finish yet:
1. Radix for hex, oct, bin calculation environment
2. Date calculation / manipulating under 'Date/Time Unit Calculation Menu'
3. Offset and AOB manipulation if possible.
Plan to publish it if the project is done.
EDIT:
Next, explanation for your question:
| Code: | x = "899 + 6 - 33"
func = assert(load("return " .. x))
y = func()
print(y) --> 872
x = "100 + 6 / 2"
func = assert(load("return " .. x))
y = func()
print(y) --> 103 because 6/2 doing first then + 100
x = "(100 + 6) / 2"
func = assert(load("return " .. x))
y = func()
print(y) --> 53 because (100+6) / 2
x = "100 + 6 * 2 - 2 / 2" --- potensial confusion
func = assert(load("return " .. x))
y = func()
print(y) --> 111
note = [[
Remember math logic rules for math operator:
highest is PARENTHESES / BRACKET
then is EXPONENT / SQUARE ROOT
next is MULTIPLICATION / DIVISION
lowest is ADDITION / SUBTRACTION
So, the correct answer for "100 + 6 * 2 - 2 / 2" is
level 1 = 6 x 2 = 12
level 2 = 2 / 2 = 1
level 3 = 100
result = 100 + 12 - 1 = 111
]] |
| Description: |
| Corroder CE Lua Calculator |
|
| Filesize: |
42.87 KB |
| Viewed: |
2379 Time(s) |

|
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|