Advertisement
fuxoft

Lua lekce 1

Dec 6th, 2012
1,193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.87 KB | None | 0 0
  1. Lua 5.2.0 Copyright (C) 1994-2011 Lua.org, PUC-Rio
  2. > 1+1
  3. stdin:1: unexpected symbol near '1'
  4. > =1+1
  5. 2
  6. > jmeno=muficek
  7. > =jmeno
  8. nil
  9. > =fhgrgfhg
  10. nil
  11. > jmeno="muficek"
  12. > return jmeno
  13. muficek
  14. > =jmeno>"ahoj"
  15. true
  16. > =28<35
  17. true
  18. > =34<23
  19. false
  20. > =jmeno == "muficek"
  21. true
  22. > return jmeno == "mufic"
  23. false
  24. > return jmeno ~= "mufic"
  25. true
  26. > nasobim3=function(n) return(n*3) end
  27. > nasobim3 (3)
  28. > =nasobim3 (3)
  29. 9
  30. > print (nasobim3(5))
  31. 15
  32. > print (nasobim3)
  33. function: 0x852e698
  34. > print (nasobim3(jmeno))
  35. stdin:1: attempt to perform arithmetic on local 'n' (a string value)
  36. stack traceback:
  37. stdin:1: in function 'nasobim3'
  38. stdin:1: in main chunk
  39. [C]: in ?
  40. > print(function(n) return(n*3) end)
  41. function: 0x852d2c0
  42. > print(function(n) return(n*3) end (5))
  43. stdin:1: ')' expected near '('
  44. > print((function(n) return(n*3) end) (5))
  45. 15
  46. > print (nasobim3(9))
  47. 27
  48. > print (n)
  49. nil
  50. > n="prdel"
  51. > print (n)
  52. prdel
  53. > print (nasobim3(9))
  54. 27
  55. > print (n)
  56. prdel
  57. > plnolety=function(vek) return(vek<18)
  58. >>
  59. >> )
  60. stdin:3: 'end' expected (to close 'function' at line 1) near ')'
  61. > print (not true)
  62. false
  63. > print not false
  64. stdin:1: '=' expected near 'not'
  65. > print (not false)
  66. true
  67. > print (not 2>1)
  68. stdin:1: attempt to compare number with boolean
  69. stack traceback:
  70. stdin:1: in main chunk
  71. [C]: in ?
  72. > print (not (2>1))
  73. false
  74. > print (not (2>1))
  75. false
  76. > plnolety=function(vek) return(vek>=18) end
  77. > print (plnolety(23))
  78. true
  79. > print (plnolety(17.9999)
  80. >> )
  81. false
  82. > for(i=17,19,0.2
  83. stdin:1: <name> expected near '('
  84. > for(i=17,19,0.2)
  85. stdin:1: <name> expected near '('
  86. > for (i in 17,19,0.2)
  87. stdin:1: <name> expected near '('
  88. > for i in 17,19,0.2 do
  89. >> print(i,plnolety(i))
  90. >> end
  91. stdin:1: attempt to call a number value
  92. stack traceback:
  93. stdin:1: in main chunk
  94. [C]: in ?
  95. > for (i = 17,19,0.2)
  96. stdin:1: <name> expected near '('
  97. > for i=17,19,0.2
  98. >> for i = 17,19,0.2 do
  99. print(i,plnolety(i))
  100. end
  101. stdin:2: 'do' expected near 'for'
  102. > for i=17,19,0.2
  103. for i in 17,19,0.2 do
  104. print(i,plnolety(i))
  105. end
  106. stdin:2: 'do' expected near 'for'
  107. > for i=17,19,0.2 do print(i,plnolety(i)) end
  108. 17 false
  109. 17.2 false
  110. 17.4 false
  111. 17.6 false
  112. 17.8 false
  113. 18 false
  114. 18.2 true
  115. 18.4 true
  116. 18.6 true
  117. 18.8 true
  118. 19 true
  119. > for i=17,19,1 do print(i,plnolety(i)) end
  120. 17 false
  121. 18 true
  122. 19 true
  123. > for i=17,19,0.1 do print(i,plnolety(i)) end
  124. 17 false
  125. 17.1 false
  126. 17.2 false
  127. 17.3 false
  128. 17.4 false
  129. 17.5 false
  130. 17.6 false
  131. 17.7 false
  132. 17.8 false
  133. 17.9 false
  134. 18 true
  135. 18.1 true
  136. 18.2 true
  137. 18.3 true
  138. 18.4 true
  139. 18.5 true
  140. 18.6 true
  141. 18.7 true
  142. 18.8 true
  143. 18.9 true
  144. > twilight=function(vek) return((vek>=8) and (vek<=15)) end
  145. > print (twilight(13))
  146. true
  147. > for i=7,17,0.5 do print(i,twilight(i)) end
  148. 7 false
  149. 7.5 false
  150. 8 true
  151. 8.5 true
  152. 9 true
  153. 9.5 true
  154. 10 true
  155. 10.5 true
  156. 11 true
  157. 11.5 true
  158. 12 true
  159. 12.5 true
  160. 13 true
  161. 13.5 true
  162. 14 true
  163. 14.5 true
  164. 15 true
  165. 15.5 false
  166. 16 false
  167. 16.5 false
  168. 17 false
  169. > print ({})
  170. table: 0x852f190
  171. > tabulka = {100,200,300,400,500}
  172. > =tabulka
  173. table: 0x852f3e0
  174. > dofile("zaklad.lua")
  175. {
  176. [1] = 1
  177. [2] = 2
  178. [3] = 3
  179. [4] = 4
  180. [5] = 5
  181. [6] =
  182. {
  183. [1] = "a"
  184. [2] = "b"
  185. }
  186. [7] = 7
  187. [8] = 8
  188. fn = function: 0x852dc48
  189. mrd = "prd"
  190. pravda = true
  191. }
  192. >
  193. >
  194. >
  195. >
  196. >
  197. >
  198. >
  199. >
  200. >
  201. >
  202. >
  203. >
  204. >
  205. >
  206. >
  207. >
  208. >
  209. >
  210. >
  211. >
  212. >
  213. >
  214. >
  215. >
  216. > print (tab(tabulka))
  217. {
  218. [1] = 100
  219. [2] = 200
  220. [3] = 300
  221. [4] = 400
  222. [5] = 500
  223. }
  224. > tabulka [5]="petset"
  225. > print (tab(tabulka))
  226. {
  227. [1] = 100
  228. [2] = 200
  229. [3] = 300
  230. [4] = 400
  231. [5] = "petset"
  232. }
  233. > tabulka [5]=nil
  234. > print (tab(tabulka))
  235. {
  236. [1] = 100
  237. [2] = 200
  238. [3] = 300
  239. [4] = 400
  240. }
  241. > tabulka [99]="hovinko"
  242. > print (tab(tabulka))
  243. {
  244. [1] = 100
  245. [2] = 200
  246. [3] = 300
  247. [4] = 400
  248. [99] = "hovinko"
  249. }
  250. > print (tabulka[4]-tabulka[1])
  251. 300
  252. > tabulka ["hovno"]=true
  253. > print (tab(tabulka))
  254. {
  255. [1] = 100
  256. [2] = 200
  257. [3] = 300
  258. [4] = 400
  259. [99] = "hovinko"
  260. hovno = true
  261. }
  262. > tabulka [5]={}
  263. > print (tab(tabulka))
  264. {
  265. [1] = 100
  266. [2] = 200
  267. [3] = 300
  268. [4] = 400
  269. [5] =
  270. {
  271. }
  272. [99] = "hovinko"
  273. hovno = true
  274. }
  275. > tabulka[5] [7]="sedm"
  276. > tabulka[5] [8]="osm"
  277. > print (tab(tabulka))
  278. {
  279. [1] = 100
  280. [2] = 200
  281. [3] = 300
  282. [4] = 400
  283. [5] =
  284. {
  285. [7] = "sedm"
  286. [8] = "osm"
  287. }
  288. [99] = "hovinko"
  289. hovno = true
  290. }
  291. > tabulka[5] ["vykal"]="chcanky"
  292. > print (tab(tabulka))
  293. {
  294. [1] = 100
  295. [2] = 200
  296. [3] = 300
  297. [4] = 400
  298. [5] =
  299. {
  300. [7] = "sedm"
  301. [8] = "osm"
  302. vykal = "chcanky"
  303. }
  304. [99] = "hovinko"
  305. hovno = true
  306. }
  307. > tabulka[5].vykal="chcanky"
  308. > =tabulka[5].vykal
  309. chcanky
  310. > return tabulka[5].7
  311. stdin:1: <eof> expected near '.7'
  312. > tabulka.tw=twilight
  313. > print (tab(tabulka))
  314. {
  315. [1] = 100
  316. [2] = 200
  317. [3] = 300
  318. [4] = 400
  319. [5] =
  320. {
  321. [7] = "sedm"
  322. [8] = "osm"
  323. vykal = "chcanky"
  324. }
  325. [99] = "hovinko"
  326. hovno = true
  327. tw = function: 0x852d508
  328. }
  329. > tabulka.tw (25)
  330. > print tabulka.tw (25)
  331. stdin:1: '=' expected near 'tabulka'
  332. > print (tabulka.tw(25))
  333. false
  334. > print (string)
  335. table: 0x8519018
  336. > print (tab(string))
  337. {
  338. byte = function: 0x8066080
  339. char = function: 0x8065610
  340. dump = function: 0x80663e0
  341. find = function: 0x8066ce0
  342. format = function: 0x8065740
  343. gmatch = function: 0x8065590
  344. gsub = function: 0x8066cf0
  345. len = function: 0x8065280
  346. lower = function: 0x80652c0
  347. match = function: 0x8066cd0
  348. rep = function: 0x80650f0
  349. reverse = function: 0x8065040
  350. sub = function: 0x8065fa0
  351. upper = function: 0x8064f90
  352. }
  353. > print (tab(math))
  354. {
  355. abs = function: 0x8063ba0
  356. acos = function: 0x8064490
  357. asin = function: 0x8064450
  358. atan = function: 0x80643b0
  359. atan2 = function: 0x80643f0
  360. ceil = function: 0x8063b50
  361. cos = function: 0x8064330
  362. cosh = function: 0x8064370
  363. deg = function: 0x8063b10
  364. exp = function: 0x80642f0
  365. floor = function: 0x8063ac0
  366. fmod = function: 0x8064280
  367. frexp = function: 0x8064230
  368. huge = inf
  369. ldexp = function: 0x80641d0
  370. log = function: 0x80640e0
  371. log10 = function: 0x8064190
  372. max = function: 0x8063dc0
  373. min = function: 0x8063d50
  374. modf = function: 0x8064080
  375. pi = 3.1415926535898
  376. pow = function: 0x8064020
  377. rad = function: 0x8063a80
  378. random = function: 0x8063e30
  379. randomseed = function: 0x8063d20
  380. sin = function: 0x8063ca0
  381. sinh = function: 0x8063ce0
  382. sqrt = function: 0x8063c50
  383. tan = function: 0x8063bd0
  384. tanh = function: 0x8063c10
  385. }
  386. >
  387. >
  388. > =math.log (123)
  389. 4.8121843553724
  390. > print (math["log"](123))
  391. 4.8121843553724
  392. > print(print)
  393. function: 0x805fb60
  394. > print = nil
  395. > print (tab(string))
  396. stdin:1: attempt to call global 'print' (a nil value)
  397. stack traceback:
  398. stdin:1: in main chunk
  399. [C]: in ?
  400. >
  401. hana@hana-laptop:~/Desktop/Programovani$ lua
  402. Lua 5.2.0 Copyright (C) 1994-2011 Lua.org, PUC-Rio
  403. > print(print)
  404. function: 0x805fb60
  405. > tabulka={klic1=100,klic2=200}
  406. > print (tabulka.klic1)
  407. 100
  408. > dofile("zaklad.lua")
  409. {
  410. [1] = 1
  411. [2] = 2
  412. [3] = 3
  413. [4] = 4
  414. [5] = 5
  415. [6] =
  416. {
  417. [1] = "a"
  418. [2] = "b"
  419. }
  420. [7] = 7
  421. [8] = 8
  422. fn = function: 0x9d86c30
  423. mrd = "prd"
  424. pravda = true
  425. }
  426. > print (tab(tabulka))
  427. {
  428. klic1 = 100
  429. klic2 = 200
  430. }
  431. > psi={
  432. >> {jmeno="Albert", narozen=2002, vaha=6},
  433. >> {jmeno="Chucky", narozen=2003, vaha=2.5}
  434. >> }
  435. > print (tab(psi))
  436. {
  437. [1] =
  438. {
  439. jmeno = "Albert"
  440. narozen = 2002
  441. vaha = 6
  442. }
  443. [2] =
  444. {
  445. jmeno = "Chucky"
  446. narozen = 2003
  447. vaha = 2.5
  448. }
  449. }
  450. > psi[1].vaha=6.2
  451. > print (tab(psi))
  452. {
  453. [1] =
  454. {
  455. jmeno = "Albert"
  456. narozen = 2002
  457. vaha = 6.2
  458. }
  459. [2] =
  460. {
  461. jmeno = "Chucky"
  462. narozen = 2003
  463. vaha = 2.5
  464. }
  465. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement