|
| 24 Feb 2014 11:15 PM |
Could be shorter, but I made it loop :P
function f(str) loadstring(([[a = %s]]):format(str))() return a end function get() local x = io.read() tostring(x) print(f(x)) get() end get() |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2014 11:21 PM |
| repeat print(loadstring('return ' .. io.read())()) until false |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2014 11:23 PM |
| it errors about io..what is io? |
|
|
| Report Abuse |
|
|
|
| 24 Feb 2014 11:24 PM |
This is standard Lua, not Rbx.Lua. io is a library(?) used to retrieve input and spit output from command line or file system. |
|
|
| Report Abuse |
|
|
|
| 25 Feb 2014 05:56 PM |
Well, I turned it into this:
repeat loadstring(([[print(%s)]]):format(io.read()))() until false |
|
|
| Report Abuse |
|
|
|
| 25 Feb 2014 06:20 PM |
@island
If you have an iPod/iPhone/iPad get the app TouchLua, io.read() is a way of getting input, example;
print("Calculator, input number 1;") n1 = io.read() n1 = tonumber(n1) --Not sure if this is nessecary if they input a number, but who cares. print("Input number 2;") n2 = io.read() n2 = tonumber(n2) --Not sure if this is nessecary if they input a number, but who cares. print("Operator +, -, /, *") Op = io.read() if Op == "+" then ans = n1 + n2 elseif Op == "-" then ans = n1 - n2 elseif Op == "/" then ans = n1 / n2 elseif Op == "*" then ans = n1 * n2 end print(ans)
--Yes I know this is inefficient, Your calculator works better I'd say. |
|
|
| Report Abuse |
|
|
wazap
|
  |
| Joined: 29 Jun 2007 |
| Total Posts: 23234 |
|
|
| 25 Feb 2014 06:26 PM |
| if you make until false into until nil it becomes 2 characters shorter. |
|
|
| Report Abuse |
|
|
|
| 25 Feb 2014 06:35 PM |
Here's a short calculator, type this into command line;
print(n1 operator n2)
Example;
print(5 + 6)
Do I get extra points for stating the obvious!?!? Lol |
|
|
| Report Abuse |
|
|
|
| 25 Feb 2014 09:53 PM |
lol,its rather easy.. ive used roblox for calculator b4 print (1+685478954/576) lol |
|
|
| Report Abuse |
|
|