Lua Tutorial

Поделиться
HTML-код
  • Опубликовано: 10 янв 2025

Комментарии • 1,9 тыс.

  • @derekbanas
    @derekbanas  5 лет назад +209

    Learn in One Videos for Every Programming Language
    Subscribe to Bookmark them: bit.ly/2FWQZTx
    C++ : ruclips.net/video/Rub-JsjMhWY/видео.html
    Python : ruclips.net/video/N4mEzFDjqtA/видео.html
    Java : ruclips.net/video/n-xAqcBCws4/видео.html
    PHP : ruclips.net/video/7TF00hJI78Y/видео.html
    MySQL : ruclips.net/video/yPu6qV5byu4/видео.html
    JavaScript : ruclips.net/video/fju9ii8YsGs/видео.html
    C# : ruclips.net/video/lisiwUZJXqQ/видео.html
    HTML5 : ruclips.net/video/kDyJN7qQETA/видео.html
    CSS3 : ruclips.net/video/CUxH_rWSI1k/видео.html
    JQuery : ruclips.net/video/BWXggB-T1jQ/видео.html
    TypeScript : ruclips.net/video/-PR_XqW9JJU/видео.html
    ECMAScript : ruclips.net/video/Jakoi0G8lBg/видео.html
    Swift : ruclips.net/video/dKaojOZ-az8/видео.html
    R : ruclips.net/video/s3FozVfd7q4/видео.html
    Haskell : ruclips.net/video/02_H3LjqMr8/видео.html
    Handlebars : ruclips.net/video/4HuAnM6b2d8/видео.html
    Bootstrap : ruclips.net/video/gqOEoUR5RHg/видео.html
    Rust : ruclips.net/video/U1EFgCNLDB8/видео.html
    Matlab : ruclips.net/video/NSSTkkKRabI/видео.html
    Arduino : ruclips.net/video/QO_Jlz1qpDw/видео.html
    Crystal : ruclips.net/video/DxFP-Wjqtsc/видео.html
    Emacs : ruclips.net/video/Iagbv974GlQ/видео.html
    Clojure : ruclips.net/video/ciGyHkDuPAE/видео.html
    Shell : ruclips.net/video/hwrnmQumtPw/видео.html
    Perl : ruclips.net/video/WEghIXs8F6c/видео.html
    Perl6 : ruclips.net/video/l0zPwhgWTgM/видео.html
    Elixir : ruclips.net/video/pBNOavRoNL0/видео.html
    D : ruclips.net/video/rwZFTnf9bDU/видео.html
    Fortran : ruclips.net/video/__2UgFNYgf8/видео.html
    LaTeX : ruclips.net/video/VhmkLrOjLsw/видео.html
    F# : ruclips.net/video/c7eNDJN758U/видео.html
    Kotlin : ruclips.net/video/H_oGi8uuDpA/видео.html
    Erlang : ruclips.net/video/IEhwc2q1zG4/видео.html
    Groovy : ruclips.net/video/B98jc8hdu9g/видео.html
    Scala : ruclips.net/video/DzFt0YkZo8M/видео.html
    Lua : ruclips.net/video/iMacxZQMPXs/видео.html
    Ruby : ruclips.net/video/Dji9ALCgfpM/видео.html
    Go : ruclips.net/video/CF9S4QZuV30/видео.html
    Objective C : ruclips.net/video/5esQqZIJ83g/видео.html
    Prolog : ruclips.net/video/SykxWpFwMGs/видео.html
    LISP : ruclips.net/video/ymSq4wHrqyU/видео.html
    Express : ruclips.net/video/xDCKcNBFsuI/видео.html
    Jade : ruclips.net/video/l5AXcXAP4r8/видео.html
    Sass : ruclips.net/video/wz3kElLbEHE/видео.html

  • @cazulon1122
    @cazulon1122 5 лет назад +557

    Data Types 3:43
    Math 6:58
    Conditionals 10:53
    Ternary Operator 15:20
    Strings 16:35
    Looping 19:11
    Repeat Until 20:44
    User Input 20:56
    For 22:00
    For In 22:29
    Tables 23:41
    Functions 28:26
    Return Multiple Values 29:25
    Variadic Functions 33:13
    Closure 34:27
    Coroutines 36:46
    File I/O 40:10
    Modules 43:32
    Metatables 45:30
    OOP 51:00
    Inheritance 55:04

  • @Tetratronic
    @Tetratronic 9 лет назад +1083

    I just discovered I had magical powers. A couple of days ago I was thinking "Man, I need to learn Lua... I wish Derek made one of his "learn X in an hour" videos. I wonder what else I can make happen...

    • @derekbanas
      @derekbanas  9 лет назад +150

      ***** That's funny :) I'm wondering what my puppet master will have me do next?

    • @januszkowal5545
      @januszkowal5545 9 лет назад +16

      ***** Actually, I think you need more people to cast this spell/ritual, since I also thought of this :)

    • @edgykid4226
      @edgykid4226 9 лет назад +11

      +Gray Fox Make my dad win the lottery. For 1 million dollars.

    • @vainfm
      @vainfm 7 лет назад +1

      make me will lottery

    • @roze942
      @roze942 7 лет назад

      Gray Fox I

  • @ke9n
    @ke9n 4 года назад +20

    30:11 Just a note: after fiddling around with this, I've come to the conclusion that the caret (^) actually denotes NOT when it is the first character in the brackets. So [^%s] means character that is NOT a space.
    The brackets themselves group the character search together, so [^%A%s]+ would be a pattern that matches characters that are NOT a non-alphabetic character or space, while + keeps matching the search as much as it can until returned nil! :)

  • @jaspertanmusic
    @jaspertanmusic 8 лет назад +175

    Great tutorial, thank you! Not sure if pointed out already, but you have 5%3 instead of 5.2%3 at 7:10, which is why you get 2 instead of 2.2 . 5.2%3 gives 2.2 in Lua.

    • @derekbanas
      @derekbanas  8 лет назад +56

      Thank you :) Thank you for pointing out my error and for explaining the results for others that may have been confused.

    • @colefisher4278
      @colefisher4278 8 лет назад +5

      that's explaining! man I'm still confused XD

    • @ryanhart5454
      @ryanhart5454 7 лет назад +2

      he means that % is a remainder in lua so 5.2%3 will returnm 2.2 because its the remainder from 5 / 3

    • @ryanhart5454
      @ryanhart5454 7 лет назад

      he means that % is a remainder in lua so 5.2%3 will returnm 2.2 because its the remainder from 5 / 3

    • @fortuneodesanya
      @fortuneodesanya 6 лет назад

      Sublime Text

  • @MrBrenm84
    @MrBrenm84 6 лет назад +11

    This is the perfect tutorial for anyone who is already familiar with a language and can keep up. It is refreshing to have a tutorial that dives straight in and lets me know what I need, and provides a cheat sheet. Fantastic! Well Done and Thank you!!!

    • @derekbanas
      @derekbanas  6 лет назад +1

      Thank you :) I'm happy it was useful

    • @Player-9
      @Player-9 Год назад

      Yes indeed!

  • @kwikb
    @kwikb 3 года назад +10

    I love the fast pace of your video. I just wanted a quick overview and this delivers. Your presentation is clear and accurate. Your video was posted 6 years ago and I just found it! Cheers and thank you very much.

  • @jackmanjls
    @jackmanjls 6 лет назад +8

    Any time I goto youtube and search for an item and see that it's by "Derek Banas" I immediately select it. These presentation are precise, well explained and accurate. I have NEVER been disappointed.

  • @yabashe
    @yabashe 4 года назад +15

    This is great, I love how your explanation goes in depth enough and at a very nice rate, not too fast, not too slow :)

  • @bigmaxporter
    @bigmaxporter Год назад +1

    If you care, you can slap a 00:00 timestamp in the description to set chapters up to make the video more easily navigable

    • @densket_
      @densket_ 11 месяцев назад

      vid was 8yrs ago chill

    • @bigmaxporter
      @bigmaxporter 11 месяцев назад

      @@densket_ they appear to still be active, and it’s basically already set up

  • @Honda_Africa_Twin
    @Honda_Africa_Twin 9 лет назад +5

    I can't thank you enough for all your videos. Your approach on topics, the way you make it all look like a piece of cake is amazing. I'm just so happy I've find your channel, and yours is the only one I get notifications on upload. Thanks a bunch.

    • @derekbanas
      @derekbanas  9 лет назад

      Mike Litorris Thank you for the nice compliments :) I'm very happy that you enjoy my channel.

  • @przemysawkukulski7342
    @przemysawkukulski7342 4 года назад +2

    4:33
    The precision of floating point numbers decreases as their value increases. That's why they are FLOATING point. Try this:
    a = 9999999999999.0001
    b = a + 0.0001
    print(b == a)
    This prints true. You don't have 13 digits of precision.

  • @Bennett_Hart
    @Bennett_Hart 5 лет назад +319

    I'm just commenting so I remember where I was: 14:20

  • @cjm_94
    @cjm_94 7 лет назад

    Great and straight-to-the point tutorial! I just have a couple of questions:
    15:50 "age > 13 and true or false" | What is actually happening here? How does this work?
    33:38 "for k, v in pairs{...} do" | What is k and what is pairs? Where are they defined?

    • @sweetberries4611
      @sweetberries4611 5 лет назад

      1. As he said, it looks like a ternary operator, so equivalent of this will be like:
      if (age > 18)
      {
      canvote = true;
      }
      else
      {
      canvote = false;
      }
      2. Seems like pairs{} is an operator, and three dots is a function parameter above.

  • @josh.c3457
    @josh.c3457 4 года назад +75

    I know this video's old, but just want to point out: your OOP example doesn't work! It works for a single instance of that object, but not for consecutive instances. If you create a second Animal, then BOTH animals will have the exact same values, as it basically just creates two aliases to the global Animal object.
    This is because inside the constructor, "self" is referring to the global instance of Animal, not the new instance. The constructor needs to create a new table, assign "self" (the global Animal table) as its metatable index, and then return that new table. Your setmetatable() method at the beginning is a no-op, it does nothing without capturing its result into a variable.
    Here's a working example:
    function Animal:new(height, weight, name, sound)
    newAnimal = setmetatable({}, { __index = self })
    newAnimal.height = height
    newAnimal.weight = weight
    newAnimal.name = name
    newAnimal.sound = sound
    return newAnimal
    end

    • @jacuzzijets
      @jacuzzijets 3 года назад

      this should have more likes lol i guess not many people checked if it works? :p thanks for the correction @Josh.c

  • @kimphuongtran7279
    @kimphuongtran7279 3 года назад +3

    i'm watching this this video in 2022 and it is still perfect. no need to watch 10 hour long videos if you already understand programming and or know other languages

    • @derekbanas
      @derekbanas  3 года назад

      Thank you for taking the time to tell me you like them :)

  • @jckaicedo
    @jckaicedo 9 лет назад +54

    45:20 I think the answer in cm should be 365.760 cm. You used + instead of * in the convert.lua module. Anyway, great video!

    • @laykefindley6604
      @laykefindley6604 5 лет назад +7

      Came here to say this. I'm glad I'm not the only one to catch it.

  • @biswanathbasak9843
    @biswanathbasak9843 7 лет назад +23

    18:12 String indices in Lua start at 1.

  • @aaronparr474
    @aaronparr474 6 лет назад +9

    Thanks for the great tutorial!
    One minor issue @~32:42: The extra 'nil' value printed is because at the very end of our loop, we've accessed an index that doesn't exist in 'splitStrTable'. If we modify line 10 to start i at 0, this problem goes away.

    • @derekbanas
      @derekbanas  6 лет назад +2

      Whoops sorry about that. Thanks for pointing that out for others :)

  • @Sccoropio
    @Sccoropio 9 лет назад

    This, for me, is what I exactly need! It's straight to the point with no incessant talking! You are amazing, bro!

  • @SkyyySi
    @SkyyySi 3 года назад +6

    If I'm not mistaken, if you put your timestamps before the chapter title, youtube will show them on the progressbar in the player.
    (So formatted like:
    23:24 Chapter name
    instead of
    Chapter name 23:24
    )

  • @k98killer
    @k98killer Год назад +1

    Correction: around 7:20, the claim was made that the modulus operator "automatically cuts off" decimals, but the actual code being ran did not include a decimal -- only the string portion describing the operation had the decimal. As of Lua 5.1, executing `5.2 % 3` will give the result 2.2, not just the integer portion.

  • @xavierreardon5580
    @xavierreardon5580 8 лет назад +276

    I was trying to code but this one coding language keeps kicking my ass.

    • @derekbanas
      @derekbanas  8 лет назад +44

      Keep at it and you'll get it :)

    • @inarisound
      @inarisound 8 лет назад +71

      The Language27 ?

    • @xavierreardon5580
      @xavierreardon5580 8 лет назад +42

      Inari Kami Yeah, The Language27!

    • @inarisound
      @inarisound 8 лет назад +37

      Some say that The Language27 is the first language that programmed itself and it was born from fire !

    • @xavierreardon5580
      @xavierreardon5580 8 лет назад +39

      Inari Kami I heard The Language27 can code a chunk longer than a professional programmer!

  • @thestaffengineer
    @thestaffengineer 11 месяцев назад

    I rather pause to think and rewatch a fast paced video than to keep fast forwarding through bloat. This is gold.

  • @DreadDoom
    @DreadDoom 8 лет назад +95

    Scripting languages always creeps me out... not pre-defining variable types and not having to use curly brackets and semicolons feels really strange to me. Really awesome tutorial tough, I really like the speed especially for someone that already has a basic understanding of programming, since the basics are often very similar to other programming languages.

    • @derekbanas
      @derekbanas  8 лет назад +18

      Yes they are something to get used to. I'm glad you found the video useful :)

    • @awp700
      @awp700 8 лет назад +1

      hhhhjkk

    • @MrPDTaylor
      @MrPDTaylor 4 года назад +2

      Not pre defining variable types has little to do with the fact that it's a "scripting" language

    • @graphitic5578
      @graphitic5578 4 года назад +1

      @Nicholas Negron lua is basically just game configuration or modding not like game design

    • @tuananhdo1870
      @tuananhdo1870 2 года назад

      Look at python: no semicolon, no curly bracket. It is one of the most readable language

  • @kensleylewis
    @kensleylewis 2 года назад

    Thank you for not getting lost in scientific web machine code language when explaining all of these methods, objects, tables, functions and modules. Super easy to understand.
    This was the best explanation on lua meta-tables I have found on the web.
    Awesome job

    • @derekbanas
      @derekbanas  2 года назад

      Thank you very much :) Happy to be of help

  • @jamaisnunca
    @jamaisnunca 7 лет назад +34

    A linguagem que me enche de orgulho, apesar de nós brasileiros sermos muito explorados, existem muitas pessoas inteligentes nesse país Lua é só mais um exemplo disso, não podemos desvalorizar essas pessoas, e não podemos viver nas sombras dos países desenvolvidos temos que encontrar nosso próprio caminho, porque somos todos iguais, um dia ainda veremos nosso país brilhar.

    • @warx1680
      @warx1680 3 года назад +1

      Seu nome deixa o comentario melhor ainda. KKK

    • @LordAlgumaCoisa
      @LordAlgumaCoisa 3 года назад

      @@warx1680 psé

    • @rbda8921
      @rbda8921 2 года назад

      Po ... eh tiquo

    • @calengo454
      @calengo454 Год назад

      isso dificilmente vai acontecer com o D.I.T e o imperialismo

  • @nickwright330
    @nickwright330 7 лет назад

    This was a fantastic video. To those complaining about the speed, I really enjoy the no BS pace, and I paused after each section to work thru the code myself and see it in action on my machine.

    • @derekbanas
      @derekbanas  7 лет назад

      Thank you :) I'm happy it was useful

  • @okandme
    @okandme 4 года назад +219

    Game programming with lua is extremely easy

    • @csongorkertesi976
      @csongorkertesi976 4 года назад +16

      You mean scripting?

    • @okandme
      @okandme 4 года назад +3

      @@csongorkertesi976 yes

    • @edwingarcia5043
      @edwingarcia5043 4 года назад +16

      @@csongorkertesi976 Programming.

    • @edwingarcia5043
      @edwingarcia5043 4 года назад +15

      @@okandme You are right, you are *programming* my dude.

    • @w5e
      @w5e 4 года назад +16

      Can vouch, especially with Roblox and Love.

  • @haiyun77
    @haiyun77 5 лет назад

    31:25 the total number of words should be “i-1”, instead of i, since you did “i=i+1” at the end of each loop. That’s also the reason you got the last line output of “nil” when you tried to print out each word.

  • @Max-bh8tg
    @Max-bh8tg 9 лет назад +309

    How to you manage to learn so many languages?

    • @zKite00
      @zKite00 9 лет назад +161

      +Max L. learning 1 language will make another 1 easy to learn

    • @victornaut
      @victornaut 9 лет назад +83

      +Maximilian Lloyd If you learn C++ you can easily lean C#, Java, F# and even Python, *Lua*, Perl, Ruby ans so on

    • @victornaut
      @victornaut 9 лет назад +8

      ***** I think so. It's a pretty weird language for me as well, but you just need some time to get familiar with the "alien" side of it and you're ready to go.

    • @victornaut
      @victornaut 9 лет назад +1

      ***** Nah, it's not that complex, it's just confusing... Alright! know what? You win LOL

    • @WozzSWE
      @WozzSWE 9 лет назад

      +Vededron use jQuery. They say it's better than JS. :)

  • @thenottakenone
    @thenottakenone 3 года назад +1

    Best hour I spent on Lua tuts thank.
    @Derek Banas 16:18 why not canVote = age > 18
    oor another example for ternary ops (because „? true : false“ should be cut imho)

  • @HansonJ
    @HansonJ 6 лет назад +60

    The problem I keep having with learning LUA is that it’s so simple, I just don’t know what words to use.

    • @ewowoi
      @ewowoi 6 лет назад +1

      what do you mean by word ?

    • @vital1ty548
      @vital1ty548 6 лет назад +3

      NerdgineerTV Im pretty sure he meant he cant find out what to put in the procedures; parts of the procedures.

    • @gaieok7899
      @gaieok7899 6 лет назад

      Yes ikr

    • @cracklelacquer5602
      @cracklelacquer5602 6 лет назад +1

      becareful with caps and word

    • @user-es4vu9sf9l
      @user-es4vu9sf9l 4 года назад +1

      Doesn’t make sense. How can something “simple” be hard to learn

  • @MrGustaphe
    @MrGustaphe 6 лет назад +1

    You're wrong about the regex you use. [^...] means "any character not in set ...", \s is whitespace and + means "one or more times (greedy)", so whitespace-delimited words match /[^\s]+/. ^ can mean "beginning of line", but not inside the class structure.

  • @masterride3604
    @masterride3604 5 лет назад +87

    Me at 2:00 : “kinda similar to python“
    Also me at 2:10 : "nope"

    • @xeome5596
      @xeome5596 5 лет назад +3

      you can use print too

    •  5 лет назад +3

      very similar to python except to oop & classes, but meta makes its work

    • @sh4-p339
      @sh4-p339 5 лет назад +1

      haha

    • @primeroyal7434
      @primeroyal7434 4 года назад

      No programming language(except Python) suits me nor it is easy to me. Java and C+(And it's brothers) eats my brain off. I tried Ruby because it is like the best and easiest static language but it also confuse me. so guess what, I will stick to my Python and possibly do AI interaction.
      Edit: I accidently typed Ruby instead of Rust.

    • @MrPDTaylor
      @MrPDTaylor 4 года назад

      @@primeroyal7434 Ruby is a dynamically typed language

  • @shamirgeorge
    @shamirgeorge 4 года назад

    Soooo, I can say that, I'm 85% done with this tutorial. As in, I followed along with the video and cheat sheet, ran all the code, tried different things with it, and followed up with lua documentation when I wanted to know more. This is a really great tutorial. I'm still getting the hang of loops, closures, and fucntions, but I'll get there. After this one, I'm going to go for Julia, Clojure, Rust, and F#. Hopefully, soon, I'll know 10 different programming languages.
    "If I can do it, anyone can."
    -Derek Banas
    After that, I'm going to complete the data science and math videos. I'm currently learning this stuff solely to stay sharp. Perhaps some time in the future, it'll all come together and I'll know what to do with the knowledge. Until then, I"m just happy learning.

    • @derekbanas
      @derekbanas  4 года назад +1

      I love learning new things everyday as well. That great thing is that once you learn data science you’ll see the world in all new ways. All of a sudden that which was once confusing will now make sense. It is almost like being able to see you future.

  • @mrmaxwell0701
    @mrmaxwell0701 3 года назад +4

    Wow, thanks a lot for this very complete demonstration of lua's basics, it is a goldmine !

  • @piorism
    @piorism 7 лет назад +2

    Absolutely loving the format (layout and speed). Fantastic stuff.

  • @stalepalemale
    @stalepalemale 7 лет назад +4

    great tutorial.
    One thing though the inheritance isn't quite OO. Typical in an OO language your descendant class would not need to define all the class members, you could simply call the inherited constructor and then simply add anything you wanted, so in your example the favfood for the cat is would you need to add.

    • @opposite4893
      @opposite4893 5 лет назад +2

      Yeah, I came to the comments looking for an answer for this.
      Is it safe to assume that inheritance can be achieved by calling Animal:new() inside Cat's constructor, then adding any additional Cat functionality, and returning the extended Animal table?

  • @mateusoliveira2776
    @mateusoliveira2776 5 лет назад +2

    is it just me, or is this one of the most fun and beginner friendly languages out there? it is so "readable", it really gives the sense of talking to the computer, so much fun. it must be great to teach programming. idk it's so cute like "if this is true then do this" lol.

    • @derekbanas
      @derekbanas  5 лет назад +1

      Lua is a fun language I agree

  • @ViewBothSides
    @ViewBothSides 5 лет назад +3

    Good video. Lua quirks: arrays & strings index from 1, not 0.
    Your ternary example with booleans is misleading "foo = (condition) and true or false" as that is identical to "foo = condition"
    Better example, showing wierd Lua quirk, would be:
    age = 13
    foo = (age

  • @rooneyjohn
    @rooneyjohn 4 года назад +1

    Thank you for making a no nonsense video. It is refreshing to have information without all the extra junk and funk everyone puts into tutorials. THANK YOU.

    • @derekbanas
      @derekbanas  4 года назад

      Thank you very much :) I'm happy you liked it

  • @V1c7ori0us
    @V1c7ori0us 8 лет назад +8

    @18:16
    I thought lua starts with the index of 1 and not 0

    • @hari.7679
      @hari.7679 3 года назад

      it does start at 1

  • @fragmister
    @fragmister 3 года назад +2

    It has been forever since I've watched Derek and when he said "Well hello internet", I felt that.

    • @derekbanas
      @derekbanas  3 года назад

      That's cool! Thanks for stopping back

  • @TheDebare
    @TheDebare 9 лет назад +10

    I had to see what I would use Lua for. It can be used for making World of Warcraft addons. Another great video Derek Banas

    • @derekbanas
      @derekbanas  9 лет назад +4

      Allen Law Thank you :) Yes many people learn it just for that reason

    • @austinrau6051
      @austinrau6051 9 лет назад +2

      Allen Law Corona SDK.

    • @TheDebare
      @TheDebare 9 лет назад +1

      Checking it out Austin rau thank you

    • @Threebow
      @Threebow 9 лет назад +2

      +PrankCentral Garry's Mod is what I seek to learn it for.

    • @sswanky3200
      @sswanky3200 9 лет назад

      +Allen Law MTA:San Andreas,cocos 2d

  • @admiralagk922
    @admiralagk922 4 месяца назад

    What a mouthful. Now, while this tutorial touched upon the very basic topics of lua, it's still a great tutorial and I appreciate your work!

  • @redps8611
    @redps8611 6 лет назад +3

    wow! it's like having half a semester's classes in an hour lol. I learnt a lot thanks!

    • @derekbanas
      @derekbanas  6 лет назад +1

      I try not to waste time :)

  • @xGuidoM
    @xGuidoM 6 лет назад

    I wonder why nobody pointed out the mistake at 31:20? You should switch lines 13 and 14, and change line 10 to "local = 0" to make the function really return the number of words.
    That is the reason you have to fix the loop later on by subtracting 1 from numOfStr... 32:44: there is not always am extra nil. It means you accessed an uninitialized element in the table...
    But other than that, I really liked the video! The speed is just perfect!

    • @derekbanas
      @derekbanas  6 лет назад

      Thank you for pointing that out :) Sorry about the error

  • @damienk777
    @damienk777 8 лет назад +133

    It feels so weard and wrong not to use '';'' in lua code :(

    • @Verodoxys
      @Verodoxys 8 лет назад +7

      +Damien K Lots of languages don't conclude statements with semicolons, like Python and Ruby, to name a couple.

    • @ghostpunk3159
      @ghostpunk3159 8 лет назад +10

      +Damien K It's honestly easier for me, lol. I for some reason have a hard time remembering to end every line.

    • @tentergram4259
      @tentergram4259 8 лет назад +9

      I'm the opposite, I started off with Lua and once I've started C++, it felt unusual.

    • @audiemurphy7421
      @audiemurphy7421 8 лет назад +4

      Well, if it confuses you that much just use it xD

    • @flagkdsa180
      @flagkdsa180 8 лет назад

      and GML (game maker language)

  • @ricsmith5085
    @ricsmith5085 7 лет назад

    I was told I needed to learn Lua in a day for a client project and this really helped me nail the syntax and fundamentals down. Thanks!

    • @derekbanas
      @derekbanas  7 лет назад

      That's great :) I'm happy it helped

  • @timhawthorn7903
    @timhawthorn7903 7 лет назад +4

    Great tutorial, although I think it's confusing to compare Lua tables to arrays - they are more like mappings or Python dictionaries. The info about metatables is really useful. Thanks!

    • @ReeSoo_
      @ReeSoo_ Год назад +2

      Lua tables are hard to understand but can be much more logical and easy to use once you get familiar with them!!!

  • @Gruby7C1h
    @Gruby7C1h Месяц назад

    Tip: don't return the i variable at 31:20, it will be off by one. #stringTable will contain proper length.

  • @LK-zn4cl
    @LK-zn4cl 8 лет назад +4

    I was watching this video to learn lua so I can get better at using unitale... I can be a boss in it now :D thnx...

  • @unusedacount410
    @unusedacount410 5 лет назад +1

    Nice, By the way If you are totally new to programing, and never used any type of language, here is the list of languages to learn in order!;
    Python - Easy to learn is similar to others - 1
    Lua - Nice, and powerful and easy to understand if you learned a mother language - 2
    Java - well, this is a popular game language but just get to under stand it and you will be good ;) - 3 1/2
    C# - A very popular game language ProIsh language... You can easily find a job with this one its also very complex, but once you get use to it you will be in love with this one - 4
    Language of Choice - NICE, you are a pro now, Have fun make some money or have a useful hobby! - 5

  • @w00tyd00d
    @w00tyd00d 8 лет назад +11

    This was a great tutorial, it taught me a lot about LUA so thank you :) I do have one question tho and that's at the end when you started talking about pseudo-OOP with LUA, you initially defined the "Animal" table with default values (height, weight, etc) and then used that as your metatable in the initialization function for your Animal object, but then later when making the Cat object you were able to pass a different value (favFood) through the previously inherited metatable without it having a default value already defined within it.
    So my question is why is it necessary to set up your initial metatable with default values if you're able to add values in on the fly?

    • @JohnSmith-ix8ob
      @JohnSmith-ix8ob 8 лет назад +4

      rule #1: "Lua not LUA"

    • @w00tyd00d
      @w00tyd00d 8 лет назад +2

      lol little pedantic but ok ;) any thought on my question tho?

    • @geogreenmanu
      @geogreenmanu 6 лет назад

      inheritance?

    • @Davi_Dash
      @Davi_Dash 3 года назад

      I know diss commentary is old but, if you do put the setmetatable in the beginning , i know... you can also charge the values on the fly, but you can use the values you didn't change to use them to be part of the class itself, diss what we call static values , you can use diss for some cool stuff like count how many instances of the class you have , you can modify a value based on certain instances and other cool and useful things.

    • @theeox
      @theeox 2 года назад

      I am pretty sure he did that only to show you a reference as to what is going to be in the table. defining it up front is not necessary. Just being repetitive to show you what is in it.

  • @SuperFerz
    @SuperFerz 2 месяца назад

    One of the features I like from Lua is that is tolerate various coding practices. For example, no need to adhere to indentation convention, whitespacing, etc. And in this video Derek used camelCase and not underscore_naming practice.
    Which reminds me of the Pascal programming language! Maybe Lua is Pascal's case-sensitive version (but without semicolons)!!

  • @CorporaMedicina
    @CorporaMedicina 5 лет назад +17

    10 Print "Hello world"
    20 If inkey$ " " GoTo 40
    30 GoTo 10
    40 End
    Run

  • @Maxxermaximus
    @Maxxermaximus 2 года назад

    12:20 the "elseif" statement checks (age=16).
    If you leave it like it is in the video it checks:
    elseif age is smaller or equal 16. Smaller 16 you checked already in the "if" statement, so you get her only equal 16. and (age

  • @unperrier
    @unperrier 2 года назад +3

    Thanks, I didn't know a thing about Lua, but it's quite simple. Not a complicated language at all.
    That said, I wished you had picked better examples. For instance the first table at 25:30 is confusing to me because you kept using index 1. What is confusing is that we don't know if there is an element zero at all, and if so why it's not reported in the length calculation. A bit more explanations of what actually happens to index zero would have been very useful. As it turns out there is an element zero and it contains nil (I've checked).
    And the other issue is at 31:30 when you return the wrong number of words (one too many), but when you get an extra "nil" you then explain it by saying that tables are always nil-terminated, which isn't true at all (I've checked too).
    Barring those two confusing points (well the second is real easy to spot to someone with programming experience), the pace is good and the content is really practical. Thanks again.

    • @lunchbox1553
      @lunchbox1553 2 года назад

      No, there is no element 0. All tables in Lua start with an index of 1. The only reason you are getting nil is simply because it doesn't exist. And, also, all tables really should be nil-terminated. If your result showed that to be false, then please explain what you did to test it because I would love to know how that could be possible.

  • @peterbezak5204
    @peterbezak5204 6 лет назад +1

    This video is perfect for people who already know some other language and want to learn Lua.

  • @oliverbenson83
    @oliverbenson83 8 лет назад +3

    If you're having trouble installing Lua, here's how I did it:
    Install Lua 5.1.4 here. code.google.com/archive/p/luaforwindows/downloads. Yoiu can then run that version of Lua in your command line. On your pc, look up "cmd". Open that up and then type "lua". You can now write Lua code :)
    If you want to use an IDE then I recommend downloading an IDE called ZeroBrane Studio. That's what I'm using at the moment and it's working decently well. Hope that helps. It's definitely a frustrating experience doing it the "right" way. Let me know if you need any help!

    • @derekbanas
      @derekbanas  8 лет назад

      +Oliver Benson Thank you for helping :) I downloaded using the sources I showed in the video. You may have to put lua in your path if you are on Windows. Maybe that was the problem people were having?

    • @oliverbenson83
      @oliverbenson83 8 лет назад

      +Derek Banas Hi Derek. Thanks for replying. That's how I did it as well. However on www.lua.org/download.html you can download version 5.3.2 which I had a lot of trouble downloading. Got there in the end though and just did it the way you did! The other question I have is how I can get the same software you're using. What I mean is on my pc, I'm using Windows 10. I can program in Lua on the cmd, but I'd prefer programming in the same format you are i.e. use Sublime Text (which I've heard it pretty good) and the terminal. I'm not sure how to go about doing that though. I hope that makes sense and you can help me out. Thanks for all the videos you make!

    • @derekbanas
      @derekbanas  8 лет назад

      +Oliver Benson Sublime Text works on every OS and you can get it here www.sublimetext.com/3 If you want a free IDE that is almost exactly the same take a look at Atom atom.io/ Yes you can use your command line just like I use the terminal. Everything works pretty much the same. I hope that helps :)

    • @OliverBenson2024
      @OliverBenson2024 8 лет назад

      +Derek Banas Do you know a way of downloading the latest version because my pc doesn't seem able to open tar.gz files? Thanks for recommending Atom :) Is the terminal the same thing as the command line? It's just I don't quite understand it. How do I get Sublime Text to interact with the terminal?

    • @derekbanas
      @derekbanas  8 лет назад +1

      +Oliver Benson You can use the install program on Windows for Atom and Sublime text. You don't need the tar file. I just recompile in the terminal. You can run the terminal in both IDEs, but I have never done that.

  • @jorajungs1413
    @jorajungs1413 4 года назад

    If you put a 0:00 at the beginning of the timestamps and the time in front of the title like this:
    Data Types 3:43 -> 3:43 Data Types
    You get nice chapters in the timeline

  • @awesomepwner0930
    @awesomepwner0930 9 лет назад +9

    I'm on windows and this looks a lot different then it does on mac, I can't even get the bar to come up

    • @mysteretsym
      @mysteretsym 8 лет назад +2

      open SciTE, not the command prompt thing if you haven't already. That's your IDE. Click view and select output for a place where the output can show and you need to save a script before you can run it.

    • @SecretAgentPaul
      @SecretAgentPaul 4 года назад +1

      tried Viagra?

  • @DerHozzy
    @DerHozzy 2 года назад +2

    Time goes by so fast. I watched this video around a month after it came out to help me learn it for roblox. I stopped playing roblox 4 years ago.

    • @Exe_Aiden
      @Exe_Aiden 2 месяца назад

      Jeez so u watched this 9 years ago

  • @serhiy2020
    @serhiy2020 4 года назад +5

    16:04 that seems a bit redundant, can't you just say:
    canvote = age > 18

    • @michielarkema
      @michielarkema 4 года назад +1

      Not if you want to return a different value that's not an boolean

    • @Epoxydeable
      @Epoxydeable 4 года назад

      Yeah, strings probably would fit more naturally to illustrate ternary operator, but my concern is that lua version of it is pretty weird in itself.

    • @serhiy2020
      @serhiy2020 2 года назад

      @@michielarkema that's kind of my point. ternary operator is better illustrated with non-boolean types

  • @TheValvier
    @TheValvier 8 лет назад

    omg! first of all thank you! most videos just throwed me to the os x website and I did complete a mess because I did not understood what was wrong. It's really important to mention as much system as possible so the viewers could actually understand and follow and understand. Thank you so much!

    • @derekbanas
      @derekbanas  8 лет назад

      You're very welcome :) I'm glad I could help

  • @ryukshinigami5106
    @ryukshinigami5106 5 лет назад +6

    Nice now I can spend rest of my life ricing AwesomeWM.

  • @Raharth
    @Raharth 6 лет назад

    At 7:30 there is a mistake I think, at least if you compare it to the most current version of lua.
    io.write("5.2 % 3 = ", 5.2 % 3, "
    ") indeed gives back 2.2 but not 2
    (io.write("5.2 % 3 = ", 5 % 3, "
    ") actually gives back 2 but I guess that was not his point there?)

  • @cgktheking
    @cgktheking 4 года назад +6

    I feel like I’m the only one here that isn’t here for roblox and is here because my teacher forced to class to learn LUA

  • @MrAnonymoose
    @MrAnonymoose 7 лет назад

    I think indices start at 1 for Lua, despite the video saying it starts at 0 at 18:16. When it returned the index of password 18:47, it said 14, which is only possible if the string's index starts with 1.

    • @GregoryVinyard
      @GregoryVinyard 7 лет назад

      There was also a little oops at about 33:00 where he says that tables always have an extra nil. It's actually because he started with 1, then added 1 for each string found. So after finding 2 strings he returned 3. Still, overall awesome tutorial.

  • @StephJ-yn2sw
    @StephJ-yn2sw 8 лет назад +3

    That's just perfect. Thank you :-)

    • @derekbanas
      @derekbanas  8 лет назад +2

      +Stéphane JAILLIARD Thank you very much :)

  • @Glowing0v3rlord
    @Glowing0v3rlord 3 года назад +2

    Note: An error in the video says modulo operations cut off decimals, however *they do not*. He mistakenly typed 5%3 instead of 5.2%3 in the math area.

  • @franciscopdinis
    @franciscopdinis 8 лет назад +2

    Hey :D
    Do you know if that covers the "MTA Lua" ?? Its a bit different from original Lua

  • @boringchannel6313
    @boringchannel6313 3 года назад

    he explained everything so fast!
    THAT'S WHAT I WANT THANK YOU!!

  • @Holy-Terrorist
    @Holy-Terrorist 5 лет назад +3

    **=** Basic Lua codes can work on Roblox Studio?

    • @kierstyn3330
      @kierstyn3330 5 лет назад

      yes. Roblox is ran off of Lua and basic Lua codes.

    • @Holy-Terrorist
      @Holy-Terrorist 5 лет назад

      @@kierstyn3330 **=** Yes, but not all codes, and Roblox use Ogre3D engine.

  • @zh4ngx
    @zh4ngx 3 года назад +1

    Amazing how much I was able to absorb watching this at 1.5x! Great video :)

    • @derekbanas
      @derekbanas  3 года назад

      Thank you very much :) I'm happy I could help

  • @theultimatesr8119
    @theultimatesr8119 8 лет назад +3

    You go a little to fast but you explain very well :)

    • @derekbanas
      @derekbanas  8 лет назад +3

      Thank you :) Sorry about the speed

    • @nikhilghelani828
      @nikhilghelani828 8 лет назад +2

      go to setting and lower the speed. thats what i do when doing practice at same time.

    • @ConFusion
      @ConFusion 8 лет назад +1

      haha, then he sounds like drunk!

  • @adrianlewis7239
    @adrianlewis7239 3 года назад +2

    Excellent outline of Lua and I would be interested also in functional programming with Lua.

  • @thecodingevolution1182
    @thecodingevolution1182 9 лет назад +7

    Why are you using io.write, why not just print lol.

    • @PixelBytesPixelArtist
      @PixelBytesPixelArtist 6 лет назад +6

      L0gicz
      The difference is that io.write adds text to the most recently used line while print creates a new line
      Example:
      for I=1,4 do
      io.write(“cool”)
      End
      Terminal:
      coolcoolcoolcool
      Example:
      For I=1,4 do
      Print(“cool”)
      End
      Terminal:
      Cool
      Cool
      Cool
      Cool

    • @catdude2319
      @catdude2319 6 лет назад

      @@PixelBytesPixelArtist but you can also do print("coolcool") so yeah

    • @PixelBytesPixelArtist
      @PixelBytesPixelArtist 6 лет назад

      Well it's good for making text matrixies if you arnt using a 2d engine.
      example:
      for r=1,5 do
      print("")
      for i=1,5 do
      io.write(" 0 ")
      end
      end
      terminal:
      0 0 0 0 0
      0 0 0 0 0
      0 0 0 0 0
      0 0 0 0 0
      0 0 0 0 0
      --If you used varibles instead of text you could set each point to something other than " 0 "

    • @PixelBytesPixelArtist
      @PixelBytesPixelArtist 6 лет назад

      @@hydropage2855
      Sorry, i dont know the difference, i dont use the system library much.

  • @mareinstalator
    @mareinstalator 9 лет назад

    Ok, now you've officially beat Darth Vader as the most inspirational person on youtube! Thanks for your dedication, and if you had time unity3d.. been developing a game on android thanks to your tutorials, then decided to switch to unity, and for 2 weeks been digging in da' documentation...suuucks. Keep them coming, and Lynda should hire you!

    • @derekbanas
      @derekbanas  9 лет назад

      dilo00o That's funny :) Thank you I'll see what I can do about covering Unity

  • @kosinparuchabutr4007
    @kosinparuchabutr4007 3 года назад +8

    "aight imma learn to script for a school project"
    *2 hours later*
    what the fuk is this?

  • @sinnathambymahesan1268
    @sinnathambymahesan1268 6 лет назад

    Example @32 :40 i is increased after assigning value to StringTable, so to return the number of values in the table, you need to return i-1 rather than i. :-)

  • @BendApparatus
    @BendApparatus 6 лет назад +43

    Here let me fix that title for you...
    Lua tutorial for people with an extensive background in programming.
    There! You're welcome...

    • @hamzahahmad1670
      @hamzahahmad1670 5 лет назад +11

      Well, it's kind of dumb if anyone expects that a >1 hour tutorial will cover basic programming fundamentals. All of Derek's crash courses focus on syntax, not basic programming fundamentals

    • @yegorgribenuke6853
      @yegorgribenuke6853 5 лет назад +1

      @@garybrock8456 Sooooo, i want to learn Lua from zero. I only know some Pascal and no more, what should i do?

    • @설리-o2w
      @설리-o2w 5 лет назад

      @@yegorgribenuke6853 Look at a different tutorial mate. These tutorials are aimed for programmers meaning you should know how to program as in basics fundamentals of programming. These crash courses are literally him teaching you the syntax of a language I come from C++ so all of this is really easy to understand. I don't want to watch a Lua tutorial that explains to me what functions, loops, selections and so on are I already know what they are. Am here to learn the syntax of this scripting language.

    • @yegorgribenuke6853
      @yegorgribenuke6853 5 лет назад

      @@설리-o2w they teached us Pascal as programming language for us understand others.
      I understand how it works, i do not know any commands and any functions, thats my problem!

    • @설리-o2w
      @설리-o2w 5 лет назад

      @@yegorgribenuke6853 well watch the video then. That's the whole point of learning this language syntax :D.

  • @Ecotechnologist
    @Ecotechnologist 6 лет назад

    This is an old video but Derek makes a small mistake around 7:18 when discussing modulus operators.
    He writes 5%3 instead of 5.2%3. The former gives the output 2, as was shown. The latter does in fact return the remainder, which is 2.2.

  • @lenamoonvalley5495
    @lenamoonvalley5495 6 лет назад +7

    Legit Roblox's tutorial teaches you 'Hello World' in their tutorial and in Studio.

    • @fire-fx2ct
      @fire-fx2ct 5 лет назад

      eww roblox player

    • @JayRain
      @JayRain 5 лет назад

      @@fire-fx2ct why

    • @poisebuildbetter
      @poisebuildbetter 4 года назад +1

      Hello world is the most common text in tutorials. Of course you'd fins it there too

    • @hqgraphics1163
      @hqgraphics1163 4 года назад

      Lua is a language that roblox just happens to use. He is teaching normal lua for real programmers.

  • @dimitrisstoikou3815
    @dimitrisstoikou3815 5 лет назад

    Straight forward,no bs,just lua,excellent!

  • @Ihelpanytime
    @Ihelpanytime 6 лет назад +9

    I want to mod a server in mta sa... but god my head hurts

  • @gabe8168
    @gabe8168 6 лет назад +2

    just btw you can say print("hi"); if you want to, lua will just yeet out the semi colon by itself

    • @joechristo2
      @joechristo2 3 года назад

      I think that means the end of a chunk (read the reference manual if you want to know what that is)

  • @danielfrland6058
    @danielfrland6058 8 лет назад +8

    Just wondering, are there annyone else than me that is watching this for help to script farming sim? :P

  • @user-ob5hj5vn8c
    @user-ob5hj5vn8c 4 года назад

    Hi, just want to let you people know that the code from 52:00 onwards is pretty much completely wrong. Reference “self” is pointing to the parent table in the :new function, not a new table. A new table isn’t even being created. in fact, setmetatable({},parent) on its own literally doesn’t do anything if you don’t assign a variable to the returned table. Alongside that, the setmetatable is also useless because there are no meta-methods in the parent table. (E.G. __index or __call). The reason the new function works when printing is because you are modifying values of the parent table, (self) and returning the parent table (self), which gives the appearance of a new object being made. If you created 2 animal objects using that func and printed out their memory addresses, you would see that they are the same object.

    • @pluckyhero2975
      @pluckyhero2975 4 года назад

      Is the a way to fix the code to make it behave in a way to create new animal objects? Sorry for necro post, but be a real big help if you could get the code to work as it seems to be intended.

  • @aznashwan
    @aznashwan 9 лет назад +4

    Derek Banas
    First off; very nice video; as always. I really enjoy your stuff and I think it's all really awesome.
    One small thing with a big impact I had to point out though:
    In the 'OO' section of this video; you're constructors are wrong in a very subtle way.
    The way you wrote it; your X:new()'s are simply modifying the existing table and returning it.
    You can check this by simply making two Animal `objects` and comparing them with ==; same goes for two Cat `objects`.
    I've written the necessary changes together with a few explanations here:
    paste.ubuntu.com/11793664/
    Again, I very much love your videos, and very subtle mistakes like these are perfectly natural. Pitching in a little hand is the very least I could do.
    Thanks again for all the great content; you rock!
    Nashwan.

    • @derekbanas
      @derekbanas  9 лет назад

      Nashwan Azhari Thank you very much for fixing that :)

  • @spodzone
    @spodzone 2 года назад

    5.2 % 3 *IS* 2.2. Helps to evaluate the same expression as the text suggests.

  • @okok6997
    @okok6997 5 лет назад +3

    If you are here from Roblox, don't watch this video. Some things are useful, but Roblox uses a modified version of Lua with more functions.

    • @Tony_Chopper
      @Tony_Chopper 5 лет назад

      i want to learn lua anyways, and nobody does a good tutorial rather than this guy

    • @neurofiedyamato8763
      @neurofiedyamato8763 5 лет назад

      Well, if you have NO knowledge of programming, learning Lua is still going to be helpful in terms of some syntax and things. And on the plus side, knowing any programming language makes it easier to transition to a new one, Lua or not.

    • @TeddyHartling
      @TeddyHartling 5 лет назад +1

      @@neurofiedyamato8763 As a Roblox Developer, the syntax on roblox is so watered down that they just use a base of LUA and add their own functions entirely.

    • @lukinhas8537
      @lukinhas8537 5 лет назад

      @@TeddyHartling Hey what do u recommend to learn lua in Roblox?

    • @PerspicaciousVG
      @PerspicaciousVG 5 лет назад

      oh k

  • @BboyHotshot
    @BboyHotshot 9 месяцев назад +1

    The modulus part isn't right. 7:30

  • @limitedfair
    @limitedfair 3 года назад +3

    im skipping maths lol

  • @maxtruxa
    @maxtruxa 2 года назад

    Nice video. One thing that threw me off is the remark at 32:44 : "There's always an extra little nil [...] whenever we create tables". No there's not. Your `splitStr` function just has an off-by-one error: The second return value is not `numOfStr` but the number of strings + 1, causing the loop to run past the end. Small side note: The `stringTable` variable in the same function is missing the `local` keyword, making the variable bleed into the global scope.

  • @jadonbtmurder9744
    @jadonbtmurder9744 9 лет назад +3

    I tried while loops, Roblox crashed (yes, I am learning with Roblox)

    • @jadonbtmurder9744
      @jadonbtmurder9744 9 лет назад +1

      qCmdUtl Rōblox (Windows 10) Yea, I figured it our a while ago. Thanks for the help, though.

    • @IllusiveMadness
      @IllusiveMadness 7 лет назад +2

      Roblox uses rbx lua so some stuff will be different

  • @miykaylataylor2893
    @miykaylataylor2893 5 лет назад +1

    Lua gang! I'm excited to get into something new, thanks for the opportunity.

  • @deletedchannel3293
    @deletedchannel3293 8 лет назад +11

    Anyone who knows why this won't work:
    repeat
    io.write("Gissa ett nummer mellan 5 till 30 : ")
    Gissa = io.read()
    if
    Gissa = < 5
    then io.write("Bara nummer över 5!")
    until tonumber(Gissa) == 19

    • @aamird5760
      @aamird5760 8 лет назад +4

      leme learn lua

    • @sinisterrectus6010
      @sinisterrectus6010 8 лет назад +2

      You're mixing an if statement with a repeat loop.

    • @supertrol2042
      @supertrol2042 8 лет назад +1

      +TehPs7ch0 you forgot to end your if statement

    • @audiemurphy7421
      @audiemurphy7421 8 лет назад +1

      You forgot the end of your if statement.. otherwise the repeat is just fine so I don't know..

    • @hamsegamerxx1tv583
      @hamsegamerxx1tv583 8 лет назад +10

      Maybe because you need to type english

  • @OndrejPopp
    @OndrejPopp 7 лет назад

    Cool session, thanks. I don't know whether this had been said before because I don't have time to go through the 700 comments, but around 44:34 you write return feet + 30.48, which should be times like you say but you write '+' instead.

    • @derekbanas
      @derekbanas  7 лет назад

      Sorry about the error

    • @OndrejPopp
      @OndrejPopp 7 лет назад

      Derek Banas No problem I was not confused I just thought you would like to know about it to update the video or whatever. I don't know but I got the impression that it is possible to replace the video while everything else stays intact. But I haven't looked into this myself. Thanks again for the cool intro.