Fireship · @fireship

Lua in 100 Seconds

Uploaded February 14, 2022 · Length 2:24

Lua in 100 Seconds

Summary

Lua language tutorial: fast, lightweight, and easy to learn scripting language for beginners.

  • lua language
  • scripting language
  • programming language
  • beginner tutorial
  • fast scripting

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    Lua a fast multi-paradigm scripting

  2. 0:02

    language famous for being so underrated

  3. 0:04

    imagine a language that's easier to

  4. 0:06

    learn than python while also being

  5. 0:08

    faster and more portable than python Lua

  6. 0:10

    was named after the moon when it was

  7. 0:11

    designed by a team of computer

  8. 0:13

    scientists in Brazil in 1993 it's

  9. 0:15

    lightweight and extremely fast because

  10. 0:17

    its virtual machine Maps very closely to

  11. 0:19

    see and when used with its Justin Time

  12. 0:20

    compiler it's widely considered the

  13. 0:22

    fastest scripting language in the world

  14. 0:24

    this makes it ideal for embedding into

  15. 0:26

    other applications like World of

  16. 0:27

    Warcraft or Roblox for example where

  17. 0:30

    users can write Lua to build their own

  18. 0:31

    games and features because the language

  19. 0:33

    is embedded into the base game it's easy

  20. 0:35

    to learn because it has only 21 reserved

  21. 0:37

    words and has only one data structuring

  22. 0:39

    mechanism called a table that can

  23. 0:41

    represent arrays dictionaries graphs

  24. 0:43

    trees and more it also supports

  25. 0:45

    collaborative multitasking with co-

  26. 0:47

    routines its standard library is very

  27. 0:48

    minimal but it does have a large

  28. 0:50

    ecosystem of packages with the Lu Rock

  29. 0:52

    package manager to get started install

  30. 0:54

    it then create a file ending in Lua

  31. 0:57

    declare a variable by providing a name

  32. 0:59

    and value by default variables are

  33. 1:01

    Global but make them local with the

  34. 1:02

    local keyword it's a dynamic language so

  35. 1:04

    no type annotations are required we can

  36. 1:06

    then use print to Output the value to

  37. 1:08

    the standard output there are no classes

  38. 1:10

    in Lua but anything you can imagine can

  39. 1:12

    be done with functions and tables a

  40. 1:14

    function is declared with the function

  41. 1:15

    keyword then closed with the nend

  42. 1:17

    keyword functions are first class

  43. 1:18

    objects which means they can be passed

  44. 1:20

    around to other functions to support

  45. 1:22

    functional programming patterns now to

  46. 1:23

    structured data you create tables with

  47. 1:25

    braces a table is actually an associate

  48. 1:28

    of array which means the index in the

  49. 1:29

    the array can be replaced with different

  50. 1:31

    values by default it uses integer values

  51. 1:34

    and the craziest thing about this

  52. 1:35

    language is that it starts the index at

  53. 1:36

    one instead of zero like most languages

  54. 1:39

    that gives us a conventional array but

  55. 1:40

    we can also easily create a dictionary

  56. 1:42

    by giving the keys a string value now we

  57. 1:44

    can use four to Loop over every key

  58. 1:46

    value pair in the table the language is

  59. 1:48

    single threaded but we can use co-

  60. 1:50

    routines to pause and resume a function

  61. 1:52

    create a co- routine then use yield to

  62. 1:54

    suspend its execution now somewhere else

  63. 1:56

    in the code use co-routine resume to

  64. 1:59

    continue execution until you get to the