Difference between revisions of "User:Hajo/test1"

From Minetest Wiki
Jump to navigation Jump to search
(→‎Lua: <source lang="lua">)
 
Line 27: Line 27:
 
|}
 
|}
  
===Lua===
+
===Lua - Online-IDEs===
https://www.lua.org/cgi-bin/demo
+
* https://www.lua.org/cgi-bin/demo
 +
* http://ideone.com/
 +
 
 +
Example - Formatting a table:
  
 
====Prog1====
 
====Prog1====
 +
<source lang="lua">
 
  for y = -200, 200, 20 do
 
  for y = -200, 200, 20 do
 
   for x = -200, 200, 20 do
 
   for x = -200, 200, 20 do
Line 36: Line 40:
 
   end
 
   end
 
  end
 
  end
 +
</source>
  
 
====Prog2====
 
====Prog2====
 +
<source lang="lua">
 
  n1,n2,step=-200, 200, 50
 
  n1,n2,step=-200, 200, 50
 
  n1,n2,step=-150, 150, 50
 
  n1,n2,step=-150, 150, 50
Line 51: Line 57:
 
  end
 
  end
 
  print("--")
 
  print("--")
 +
</source>
  
 
=====Output=====
 
=====Output=====
Line 65: Line 72:
 
====Prog3====
 
====Prog3====
 
Task:
 
Task:
 +
formatting a table for the wiki
 +
 
====Wiki-Table====
 
====Wiki-Table====
 
{| class="wikitable"
 
{| class="wikitable"
Line 78: Line 87:
  
 
====Code====
 
====Code====
 
+
<source lang="lua">
n1,n2,step=-200, 200, 50
+
--n1,n2,step=-200, 200, 50
n1,n2,step=-150, 150, 50
+
  n1,n2,step=-150, 150, 50
print('{| class="wikitable"')
+
  print('{| class="wikitable"')
--
+
  --
print('|-\n! X,Y !! ...')
+
  print('|-\n! X,Y !! ...')
--
+
  --
for y = n1,n2,step do
+
  for y = n1,n2,step do
  s=string.format("|-\n| y=%4d : ",y)
+
  s=string.format("|-\n| y=%4d : ",y)
  for x = n1,n2,step do
+
  for x = n1,n2,step do
  s = s..string.format("|| %4d,%4d ", x,y)
+
    s = s..string.format("|| %4d,%4d ", x,y)
 +
  end
 +
  print(s); s=""
 
   end
 
   end
   print(s); s=""
+
   print("|}")
end
+
</source>
print("|}")
 
  
 
=====Output=====
 
=====Output=====

Latest revision as of 04:52, 11 March 2017

Table-test

10x10

__ AA BB CC DD EE FF GG HH II JJ
:: a1 b1 c1 d1 e1 f1 g1 h1 i1 j1
:: a2 b2 c2 d2 e2 f2 g2 h2 i2 j2
:: a3 b3 c3 d3 e3 f3 g3 h3 i3 j3
:: d4 d1 d1 d1 d1 d1 d1 d1 d1 d4
:: e5 e1 e1 e1 e1 e1 e1 e1 e1 e5
:: f6 f1 f1 f1 f1 f1 f1 f1 f1 f6
:: g7 g1 g1 g1 g1 g1 g1 g1 g1 g7
:: h8 h1 h1 h1 h1 h1 h1 h1 h1 h8
:: i9 i1 i1 i1 i1 i1 i1 i1 i1 i9
:: j0 j1 j1 j1 j1 j1 j1 j1 j1 j0

Lua - Online-IDEs

Example - Formatting a table:

Prog1

 for y = -200, 200, 20 do
  for x = -200, 200, 20 do
    print(x,y)
  end
 end

Prog2

 n1,n2,step=-200, 200, 50
 n1,n2,step=-150, 150, 50
 print("===Table===")
 for y = n1,n2,step do
  --print(y..": ")
  s=string.format("y=%4d : ",y)
  for x = n1,n2,step do
   s = s..string.format("%4d,%4d ", x,y)
   --print(x,y)
  end
  print(s); s=""
 end
 print("--")
Output
===Table===
y=-150 : -150,-150 -100,-150  -50,-150    0,-150   50,-150  100,-150  150,-150 
y=-100 : -150,-100 -100,-100  -50,-100    0,-100   50,-100  100,-100  150,-100 
y= -50 : -150, -50 -100, -50  -50, -50    0, -50   50, -50  100, -50  150, -50 
y=   0 : -150,   0 -100,   0  -50,   0    0,   0   50,   0  100,   0  150,   0 
y=  50 : -150,  50 -100,  50  -50,  50    0,  50   50,  50  100,  50  150,  50 
y= 100 : -150, 100 -100, 100  -50, 100    0, 100   50, 100  100, 100  150, 100 
y= 150 : -150, 150 -100, 150  -50, 150    0, 150   50, 150  100, 150  150, 150 
--

Prog3

Task: formatting a table for the wiki

Wiki-Table

Y \ X x=-100 x=-50 x=0 X=50 x=100
y=-150 : -100,-150 -50,-150 0,-150 50,-150 100,-150
y= 0 : -100, 0 -50, 0 0, 0 +50, 0 100, 0
y= 150 : -100, 150 -50, 150 0, 150 +50, 150 +100, 150

Code

--n1,n2,step=-200, 200, 50
  n1,n2,step=-150, 150, 50
  print('{| class="wikitable"')
  --
  print('|-\n! X,Y !! ...')
  --
  for y = n1,n2,step do
   s=string.format("|-\n| y=%4d : ",y)
   for x = n1,n2,step do
    s = s..string.format("|| %4d,%4d ", x,y)
   end
   print(s); s=""
  end
  print("|}")
Output
X,Y ...
y=-150 : -150,-150 -100,-150 -50,-150 0,-150 50,-150 100,-150 150,-150
y=-100 : -150,-100 -100,-100 -50,-100 0,-100 50,-100 100,-100 150,-100
y= -50 : -150, -50 -100, -50 -50, -50 0, -50 50, -50 100, -50 150, -50
y= 0 : -150, 0 -100, 0 -50, 0 0, 0 50, 0 100, 0 150, 0
y= 50 : -150, 50 -100, 50 -50, 50 0, 50 50, 50 100, 50 150, 50
y= 100 : -150, 100 -100, 100 -50, 100 0, 100 50, 100 100, 100 150, 100
y= 150 : -150, 150 -100, 150 -50, 150 0, 150 50, 150 100, 150 150, 150