mj41374

AbbreviatedLUAforComputerCraft

Jul 20th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | None | 0 0
  1. -- Two dashes start a one-line comment.
  2.  
  3. num = 42 -- All numbers are doubles.
  4. s = "walternate" -- Immutable strings like Python.
  5. t = nil -- Undefines t;
  6.  
  7. -- Blocks are denoted with keywords like do/end:
  8. while num < 50 do
  9.   num = num + 1 -- No ++ or += type operators.
  10. end
  11.  
  12. -- An infinite loop that doesn’t end until Ctrl-R or Ctrl-T
  13. while true do
  14.   --do stuff over and over
  15. end
  16.  
  17. -- If statement:
  18. if num > 40 then
  19.   print("over 40")
  20. elseif s ~= "walternate" then  -- ~= is not equals.
  21.   -- Equality check is == like Python; ok for strings.
  22.   write("not over 40\n")  -- Another way to write out to print.
  23. else
  24.   -- Variables are global by default.
  25.   thisIsGlobal = 5
  26.  
  27.   -- How to make a variable local:
  28.   local line = read()  -- Reads next input line.
  29.  
  30.   -- String concatenation uses the .. operator:
  31.   print("Winter is coming, "..line)
  32.  
  33.   -- Replace/Hide the input characters the user types with *
  34.   local password = read("*")
  35. end
  36.  
  37. -- An undefined variable return “nil”
  38. -- This is not an error:
  39. foo = anUnknownVariable  -- Now foo = nil.
  40.  
  41. karlSum = 0
  42. for i = 1, 100 do  -- The range includes both ends (“1” and “100”)
  43.   karlSum = karlSum + i
  44. end
  45.  
  46. -- Use "100, 1, -1" as the range to count down:
  47. fredSum = 0
  48. for j = 100, 1, -1 do
  49.   fredSum = fredSum + j
  50. end
  51. function fib(n)
  52. if n < 2 then return 1 end
  53.   return fib(n - 2) + fib(n - 1)
  54. end
Advertisement
Add Comment
Please, Sign In to add comment