LUA studying Note

tags: LUA

introduction

LUA is a widely used programming language.

It can control the base level of component, can control the lower level language (e.g. C, JAVA…).

It can be used in app implementation.

basic syntax

  • print(‘’) / print(“”)
  • print(1==1)
    • return true
  • print(1~=1)
    • return false (not !=)
  • can multiply set value for parameters
    • a,b,c,d = 1,2
    • print(a,b,c,d)
    • return 1,2,nil,nil
  • and or not
    • print(1 and 1)
      • return 1
    • print(1 or nil)
      • return 1
    • print(not nil)
      • return true
  • print(‘Hello’..’world’)
    • return Helloworld
  • count length
    • print(#’abcd’)
      • return 4
    • aa = ‘Hello, world!’
    • print(#aa)
      • return 13
    • print(string.len(aa))
      • return 13
  • comment –[[long comment here]]
  • if
    • if 1==1 then
    • print(‘aa’)
    • end
  • while
    • while 1==2 do
    • print(‘should never print’)
    • end
  • for
    • for i=1,3 do print(i) end
      • 1,2,3
    • for i=1,10,2 do print (i) end
      • 1,3,5,7,9
  • repeat
    • repeat will at least execute once
    • repeat print(‘aa’) until 1<10 (成立的情況就跳出去)
      • aa
  • break

  • function declaration

    • function echo_aa()
    • print(aa)
    • end
  • l