Why Lua 🥺

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

Комментарии • 764

  • @timelessnesses
    @timelessnesses Год назад +2095

    who the fuck invited javascript devs to lua 💀🙏

  • @Ulissescars
    @Ulissescars Год назад +2753

    I like Java's way of handling things: if there is a string on the middle, then everything is a String.

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

      System.out.println() is beauty. The only problem is that it’s called System.out.println().

    • @Wawwior
      @Wawwior Год назад +147

      Well java objects get stringified, either by hashing or by an implementation, so if anything in the expression is not a number, its probably gonna be a string.

    • @gingeral253
      @gingeral253 Год назад +28

      It’s just a lot easier

    • @kyleavery6372
      @kyleavery6372 Год назад +200

      (1 + 2 + "3") is "33"

    • @PimPumSObaka
      @PimPumSObaka Год назад +4

      exactly

  • @G-u-z-i-o
    @G-u-z-i-o 7 месяцев назад +720

    This sounds scary, but starts making a lot more sense when you consider that "+" is ALWAYS supposed to be addition in Lua. For string concatenation, ".." is used.

    • @Yolwoocle
      @Yolwoocle 7 месяцев назад +64

      Been using Lua for a long time and I didn't even know that + was compatible with strings for this exact reason. It just isn't an issue you run into, unlike in JS

    • @goldenollies8338
      @goldenollies8338 6 месяцев назад +12

      In Lua you can also do something like this for string concatenation, sorry I’m on phone so it will be hard to type
      ‘{not a string here} a string’
      it works the same way just a little less messy I guess

    • @CogTheSuit
      @CogTheSuit 6 месяцев назад +10

      @@goldenollies8338 string interpolation isn't part of vanilla Lua

    • @goldenollies8338
      @goldenollies8338 6 месяцев назад

      @@CogTheSuit oh well it is with LOVE engine thing

    • @goldenollies8338
      @goldenollies8338 6 месяцев назад

      @@CogTheSuit oh well it is with LOVE engine thing

  • @tldr_rm_-rf
    @tldr_rm_-rf Год назад +2006

    So Lua doesn't stop you from shooting your leg. Very nice

    • @sayven
      @sayven Год назад +39

      Yeah I expected this to actually work and that that would be the issue.

    • @pedroivog.s.6870
      @pedroivog.s.6870 Год назад +5

      Does it also work on JS?

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

      @@pedroivog.s.6870 in JS 1 + "1" gives you "11", but 1 - "1" gives you 0

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

      @@pedroivog.s.6870 almost certainly, that wretched language will type coerce nan to a string

    • @honk2448
      @honk2448 Год назад +82

      @@pedroivog.s.6870 oh it's bad, really bad. JS doesn't and never will make sense. 1 + 1 + "1" = "21"

  • @qing-hh4su
    @qing-hh4su Год назад +175

    why people are dumb?
    lua gave you “..” operator for concat and “+” for math 😒

    • @Sakupenny
      @Sakupenny 3 месяца назад

      so real

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

      Legit it's is as logical as things can be

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

      that's what i was thinking too

    • @all_matters-dm1jw
      @all_matters-dm1jw 20 дней назад

      calm down dawg its a joke

  • @NanerBag
    @NanerBag Год назад +831

    I love it when scripting languages decide to make things "convenient" for new programmers who have never read a line of code in their life at the expense of everyone else.

    • @jco_sfm
      @jco_sfm Год назад +120

      string concatenation in lua is done with .. so theres really nothing else for + to do in that scenario, it might as well try to do some addition

    • @SomeRandomPiggo
      @SomeRandomPiggo Год назад +5

      So true

    • @phir9255
      @phir9255 Год назад +6

      can't tell if this is sarcasm

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

      It is sarcasm, ​@@phir9255.

    • @noelka8134
      @noelka8134 Год назад +13

      @@jco_sfm it could be 11, but no, it's 2... but it's pretty useless either way lol

  • @badradish2116
    @badradish2116 Год назад +488

    "static types are better"
    "no! dynamic types are better!"
    can't a man just get type inference with reasonable implicit casts?

    • @rikschaaf
      @rikschaaf Год назад +44

      Who decides what's reasonable? If I were to create a programming language, I'd allow the user to decide what's a reasonable way to cast (for example through operator overloading).

    • @0xCAFEF00D
      @0xCAFEF00D Год назад +4

      @@rikschaaf If you're not super picky you can easily find reasonable implicit cast systems.
      It really isnt a hard problem.

    • @Mr.Not_Sure
      @Mr.Not_Sure Год назад +30

      Should be "a"+1 be "b" or "a1"?

    • @pranavgaur1086
      @pranavgaur1086 Год назад +10

      Funny words magic man

    • @potzko2552
      @potzko2552 Год назад +5

      learn rust or ocamel for that tbh, there are some great type inference in those

  • @zyxyuv1650
    @zyxyuv1650 Год назад +1981

    Lua was almost big in the game industry but it died because of the 1-indexing which made subtle off-by-1 incompatibility with all existing libraries, and made it impractical to directly bind libraries because they would have inconsistent indexing with Lua. The 1-indexing kind of destroyed the entire Lua project.

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

      doesnt roblox use LUA? i wouldnt call exactly call it dead

    • @catritonix
      @catritonix Год назад +103

      well its not completely dead

    • @mudrost4934
      @mudrost4934 Год назад +563

      Lua is insanely popular for embedding in applications (e.g. scripting in games). I have no clue where you read about it being 'destroyed', but it is a really fast programming language (the Just-In-Time compiler is faster than Python or JS and interacts neatly with the C API). Used in World of Warcraft, Project Zomboid, Elder Scrolls Online, Roblox, Factorio, Don't Starve, and many others (from AAA studios as well). While the 1-indexing has a constant overhead due to memory access shenanigans, this is almost a non-issue.

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

      oh yeah? what about doom@@mudrost4934

    • @burkeychathouse5537
      @burkeychathouse5537 Год назад +303

      I can’t even tell if this is a joke or not lmao. Saying something was almost good and then died because of 1 indexing is hilarious.

  • @somenameidk5278
    @somenameidk5278 Год назад +215

    I think this is actually part of the standard string library, it creates an __add metamethod for strings that converts them to numbers. Without it i believe this would just give "Attempted to perform arithmetic on a string value."

    • @j3y445
      @j3y445 Год назад +33

      this is actually more of a consequence of using the wrong operator. String concatenation in Lua is purely just '..', not +. SO when u use the + operator on two objects, the Lua interpreter will see a string and try to covert to a number or fail and if its an object it will call the __add metamethod if defined or fail. I don't believe strings have meta methods because to my knowledge they are primitive types in Lua, not objects.

    • @somenameidk5278
      @somenameidk5278 Год назад +8

      @@j3y445 i am aware of the concatenation operator, i aws simply explaining why this happens when you do it wrong. Strings do actually have a metatable, as each primitive type has a metatable shared among all instances of that type (so all strings share a metatable, all numbers, all bools, etc). This is why you can do this: local length = "hi everyone":len(). The string library adds all its functions to the string metatable alongside the "__add" function shown in hte video.

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

      @@somenameidk5278 ah i see. And yea ur right about strings having a metatable. It’s been a while for me and lua. Though for numbers I really hope metamethods are only called for non-number things because otherwise there would be a pretty significant performance hit i would imagine. And is it the first operands metamethod that is actually called? I believe it should be and would make the most sense.

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

      ⁠@@somenameidk5278while correct in the sense of pseudocoding - you’d need to make the string an object by wrapping it with parentheses or assigning it to a variable before you’re able to call the metamethods so itd be: `(“hi everyone”):len()`

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

      @@j3y445 it tries the first operand first, and if it dosen't have that metamethod, it tries the second operand. i believe strings are the only type metatable that gets anything placed into it by the standard library.

  • @hadawardgz
    @hadawardgz Год назад +74

    The problem is that + is an arithmetic operation in lua, so lua will always try to do type coercion and you can even overload the operator to behave differently. For concatenation in Lua you always use *..* as it is the only method of joining two strings and with numbers it would cause an error.

    • @imaxx4
      @imaxx4 6 месяцев назад +1

      Yes, but it should be error. You just can't add int to string, that's crazy. What it will do if you write 1 + "big", it will output prob something crazy

    • @hadawardgz
      @hadawardgz 6 месяцев назад +5

      @@imaxx4 nope, first if you do 1 + "something that is not a number" it will error. But if you try to do an operation with a valid digit inside a string then it will transform the string into number and do the operation. I particularly like this, if the person entered a valid number it makes perfect sense for the language itself to deal with the conversion and addition. Now as you said 1 + "something" will error with "attempt to perform arithmetic on a string value"

    • @guavapaste
      @guavapaste 6 месяцев назад

      @@hadawardgz I though it had something to do with ASCII char tables like in C.
      C reads characters as a number between 0-255, and then returns the ASCII character correspondent to that number when asked to. The ASCII code for the number 1 is 61. 61 + 1 = 62, and 62 in the ASCII is the number 2. So basically '1' + 1 = '2'
      There's a lot of weird things you can do in C, and this definetively isn't the weirdest.

    • @hadawardgz
      @hadawardgz 6 месяцев назад +1

      @@guavapaste Hmm, but no. It's just that Lua actually performs coercion, it checks whether the string can be transformed into a number to operate on it.

    • @guavapaste
      @guavapaste 6 месяцев назад +1

      @@hadawardgz oh. That's cool.

  • @yerenzter
    @yerenzter Год назад +242

    Lua it just 150KB compiler while Python over a hundred megabytes does.

    • @Raspredval1337
      @Raspredval1337 Год назад +69

      since you can embed lua into c programs and supply your own mem alocator, I've managed to get lua running under 30k of ram, without the std library ofc, but still, kinda impressive. You can theoretically fit the whole lua interpreter into a NES RAM

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

      @@Raspredval1337 if you defer the builtin libraries (table, os, io, string, math, etc) to not load until they are referenced (via metatables) then a new environment is less than 5k.

    • @niko5008
      @niko5008 7 месяцев назад +36

      ​@@Raspredval1337aw man NES developers shoulda added scripts to their games, imagine the possibilities 😢

    • @torque8047
      @torque8047 7 месяцев назад

      ​@@niko5008If you wanna you could glitch the game to make it run arbitrary code. Look up snes code injection

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

      Plus it's much faster.

  • @gordonramsay8351
    @gordonramsay8351 Год назад +113

    lets be real, programming languages are cringe. i think we should send electrical impulses directly to the CPU to write binary code.

    • @dijital4801
      @dijital4801 6 месяцев назад +10

      may as well break out your punch cards while youre at it

    • @turuukuruu
      @turuukuruu 5 месяцев назад +7

      No you have to extract electricity from a jellyfish and input it to conputer to make efficient code to run

    • @JeLeff.
      @JeLeff. 2 месяца назад +1

      fr

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

      @@turuukuruu ☝️🤓 jelly fishes produce venom not electricity nincompoop

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

      Too abstract ​@@dijital4801

  • @Nox-Music
    @Nox-Music Год назад +189

    This type conversion is useful in some cases. But if you just wanna concatenate strings, doing ("1"+"1") wont actually work. This is why ".." exists.

    • @Templarfreak
      @Templarfreak Год назад +18

      in this case i would say it isnt strictly useful but not problematic either. it kind of just is what it is.
      string concatenation using a different symbol from addition is a small quirk that's different from a lot of other programming languages, but, frankly, in my opinion, should be a standard in other programming languages. addition and string concatenation just should never have both been done with the same operator in any language. _that_ is actually problematic. it's not a huge, gigantic, big deal or anything, but it is a flaw in most other programming languages imo.

    • @Nox-Music
      @Nox-Music Год назад +15

      @@Templarfreak Concatenation isnt an Arithmatic operation so i see why they split it apart. Although other programming languages should certainly adapt to the way lua did it. Although people find JavaScript weird for this exact reason...

    • @MagicGonads
      @MagicGonads Год назад +7

      string concatenation differs from addition in a few ways that can be important:
      addition is commutative, concatenation is not
      addition is fast, concatenation is slow
      addition is invertible, concatenation is not
      addition distributes multiplication, concatenation does not (in python for example)
      the JIT could make use of these properties to simplify bytecode if not for ((dynamic typing and the operators being the same) or overriding not necessarily following that contract)

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

      then try print (0+"1"+"1")

    • @Nox-Music
      @Nox-Music Год назад +2

      @@xerlandia JavaScript says 011. Lua(u) says... 2

  • @FitraFadilana
    @FitraFadilana Год назад +36

    in JS it will be "11"

    • @user-tw2kr6hg4r
      @user-tw2kr6hg4r 7 месяцев назад +7

      11 is honestly better than 2.

    • @P-39_Airacobra
      @P-39_Airacobra 3 месяца назад +5

      @@user-tw2kr6hg4r only if you use a 2 year old's definition of addition

    • @kylezdancewicz7346
      @kylezdancewicz7346 2 месяца назад +3

      @@user-tw2kr6hg4ronly if you arbitrarily make + also concatenation, which Lua does not do. + is only addition .. is concatenation

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

      @@user-tw2kr6hg4r chill out terrence howard

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

      In assembly it's 50

  • @Michael-pp8lz
    @Michael-pp8lz Год назад +47

    I started programming with C++, which, for most people, is a difficult language. I started programming in Python recently and it actually makes no sense lol. Its confusing how easy something can be

    • @kayastuff9367
      @kayastuff9367 Год назад +7

      I did the opposite (started with python, now Java) and I want to kms

    • @saharsh-sh
      @saharsh-sh Год назад +13

      Started with python and now doing c. What is genuinely wrong with his language??? Why is it built like this

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

      @@saharsh-sh Me with python be like

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

      started with python, now learning c++@@saharsh-sh

    • @АлександрКоновалов-ш1н
      @АлександрКоновалов-ш1н Год назад +2

      It's because you just have started. Advanced python isn't easy.

  • @melody_florum
    @melody_florum Год назад +13

    To be entirely fair, string concatenation in lua isn’t done with the + operator, it has a special .. operator
    Still hate that it tries to automatically cast a string to a number that’s horrible

  • @szupertntakos5000
    @szupertntakos5000 Год назад +5

    I'm not sure but print(1 .. "1") or print(1, "1") should work.

    • @JeLeff.
      @JeLeff. 2 месяца назад +1

      I was for real searching for a comment that solves this and now that I found this, I feel so dumb, like I knew it existed, I even used it in the same project I'm using it rn, but I forgot it exists for some reason lol

  • @2Deep.
    @2Deep. 2 месяца назад +5

    To be honest... Is actually a good thing...

  • @lau6438
    @lau6438 25 дней назад +4

    This is why i prefer to do everything in c/c++. It's either right or wrong, and i want to know which one it is. Not let the compiler figure it out.

  • @TheCubicLog
    @TheCubicLog Год назад +87

    tbh I expected it to be "11" like javascript

    • @v0xl
      @v0xl 7 месяцев назад +17

      but lua has a separate sting concat operator (..)

    • @Brahvim
      @Brahvim 7 месяцев назад

      What?
      JavaScript does it THE SAME AS LUA.

    • @Nick12_45
      @Nick12_45 7 месяцев назад +6

      @@Brahvim 1 + "1" === "11"

    • @Гдекамин
      @Гдекамин 6 месяцев назад +4

      @@Brahvim no if you write in JS 1+"1", you get 11, but if you write 1-"1", you get 0.... But in Lua in both cases you get sum of 1+1, and 1-1, so Lua in this much better.....

    • @Brahvim
      @Brahvim 6 месяцев назад

      @@Гдекамин Huh.
      I've heard that numbers inside strings can sometimes be treated as parsed values in JS.
      That's what I was referring to.

  • @ameer6168
    @ameer6168 Год назад +8

    Javascript :- finally a worthy competitor

  • @CrazyStranger11
    @CrazyStranger11 Год назад +131

    What about C?
    printf("%c", 1 + '1') prints 2

    • @jonforhan9196
      @jonforhan9196 Год назад +89

      man ascii

    • @king_james_official
      @king_james_official Год назад +71

      if you do 1 + '9' it will print ":" because it is after "9" in the ascii table

    • @royler8848
      @royler8848 Год назад +40

      this is kind of the other way around, a '1' is actually just 49. c is rightly doing 1 + 49, and then %c is asking printf to take the number 50 and print it out in ASCII form

    • @thecwd8919
      @thecwd8919 Год назад +38

      Chaotic neutral coder

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

      @@thecwd8919 lmao

  • @mrvoid8464
    @mrvoid8464 Год назад +4

    "You don't know me son"
    ~JavaScript

  • @junetxpid2425
    @junetxpid2425 Год назад +30

    it's type coercion, it happen too in javascript 😂
    type coercion is the automatic or implicit conversion of values from one data type to another (such as strings to numbers). type conversion is similar to type coercion because they both convert values from one data type to another with one key difference - type coercion is implicit whereas type conversion can be either implicit or explicit.

    • @callyral
      @callyral Год назад +9

      "if it happens in javascript, it shouldn't happen"

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

      ​@@callyralb-but
      antimatter dimensions :(
      what will we spend hours watching without the ANTIMATTER?

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

      I thought implicit type conversion meant the computer just read the literal binary representation of a type, while explicit conversation actually converted it, no matter if it was specified in the code or not. You can do this in C, too--"printf("%c", 1 + '1');" will output "2", but "printf("%s", "12" + 1);" will . . . index into the string "12" and output "2", apparently. I thought I'd get a "you can't implicitly convert from pointer to int" error, but apparently C thought I wanted to do a little pointer arithmetic.
      You definitely can't implicitly convert from float to int without some union gymnastics, though. Do "printf("%c", 1.0 + "1");" and you get "invalid operands to binary +". C is a bit protective of floating point numbers.

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

      @@mage3690 it depends on the language. Lua literally converts a string into a number, but will give you an error if you try to use addition with a string with ascii characters. but this is actually doable in something like C. in C you can do something like 1 + "a" and you'll get something like 98 i believe, but if you try to do that in lua it will complain at you because it cant convert "a" into a number via Lua's string to number function on the C side. however, because Lua lets you redefine any variable, including the inbuilt global variables, and any members of tables in those global variables, you can actually redefine the __add functions for the number and string metatables to handle the case yourself and make letters properly convert to their ascii representation and make 1 + "a" return 98 in Lua if you desire.

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

      ​@@mage3690 That's because modern CPUs have dedicated hardware just for floats

  • @hadawardgz
    @hadawardgz Год назад +5

    By the way, i think Luau is more interesting as it's the roblox lua modified version that add typings to the language and make it more consistent

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

      luau is trash cuz u can only learn lua inside of roblox. learning actual lua helps alot + there are better languages which are easier to learn like python

    • @hadawardgz
      @hadawardgz Год назад +3

      @@Fayroll5 there are luau interpreters out of roblox 🤷 actual Lua is cool, but if you want devs to be productive and efficient then Luau is better.

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

      @@Fayroll5 why learning it inside roblox is trash? im 13 and i spent 2 years learning pro lua in roblox. Now im migrating to java, all thanks to roblox

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

      pluto would actually be better. Luau is a mistake.​@@hadawardgz

    • @fhudufin
      @fhudufin 7 месяцев назад

      @@Fayroll5 you can download a standalone luau interpreter

  • @cattokomo
    @cattokomo Год назад +23

    when you play with the metatable too much

  • @sunofabeach9424
    @sunofabeach9424 Год назад +53

    I know that people couldn't care less about Lua these days but here is how you can legally disallow such behavior in your project. Watch the hands:
    getmetatable(" ").__add = nil
    Now what did I just do: when you try to "add" a string to a number, the string tries to do it in a naive way, fails (because strings aren't meant to be added by Lua), then looks into its metatable (an object that contains methods for values of certain type, basically Lua's way of OOP) and executes "__add" metamethod from there which does this wierd thing. So "getmetatable" function called with *any* string returns us that metatable, and then we wipe out "__add" metamethod from there. Now Lua cannot do anything when you add strings which makes it yield an error.
    It's not a hack or anything, Lua just doesn't mind exposing to you some things that are predefined by standard library
    Or just don't forget that there is ".." operator specifically for concatenation

    • @CuriousLight._dev
      @CuriousLight._dev 6 месяцев назад +1

      roblox uses lua though wdym "I know that people couldn't care less about Lua these days"

    • @sunofabeach9424
      @sunofabeach9424 6 месяцев назад

      @@CuriousLight._dev no offense but I mean developers not Roblox players

    • @CogTheSuit
      @CogTheSuit 6 месяцев назад

      Bad news for you, setting __add to nil doesn't give you anything

    • @sunofabeach9424
      @sunofabeach9424 6 месяцев назад

      @@CogTheSuit ??? I just checked it again
      I'm using just old plain Lua 5.4.6 interpreter from the official repository. not some unholy contraption used in Roblox or something. works in both REPL and chunk

    • @CogTheSuit
      @CogTheSuit 6 месяцев назад

      @@sunofabeach9424 I used LuaJIT 2.1

  • @potatony997
    @potatony997 Год назад +11

    Shit man, i don't know how i got here or why i stayed but damn my brain just farted

  • @Orincaby
    @Orincaby 7 месяцев назад +4

    summary from the comments:
    + is arithmetic add
    .. is concatenate
    "+" casts the string to and int and thus prints 2

  • @pedroivog.s.6870
    @pedroivog.s.6870 Год назад +27

    I'm absolutely biased towards Python's handling of data structures. It becomes pretty recurrent to explicitly modify the class type (say, int("1") + 1), but I got used to it

    • @izd4
      @izd4 Год назад +27

      Explicit is better than implicit. The Zen of Python is generally correct on this sort of thing

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

      Same, but for JS, just write 1+ +"1". Why waste time say lot words when few words do trick.

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

      @@GermanZindro When all you have is casting a number to a string for concatenation, then sure, it's not terrible. But JS is infamous for the way implicit type casting yield wildly undesirable results. For instance, `false == "0"` yields `true`, which you may never have guessed coming from any language with saner typing

  • @renren_does_programming
    @renren_does_programming Год назад +8

    I hope languages with type coercion adds a optional static type option to stop your suffering you made yourself... ...Implicit type casting is not good for large projects and can introduce bugs if its not detected. Thats why TypeScript exists for Javascript.

    • @klartnet
      @klartnet Год назад +4

      TypeScript doesn't prevent the implicit type casting. you can string + number or vice versa without any errors.

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

      Since the + operator asserts both operands are of type number, IMHO it's explicit typecasting. PHP allows you to do strict typing by "declare(strict_types=1);" at the top of the file. Only JS has the literal worst of all worlds by (for some reason) allowing the computer to assume whatever the f*** it wants.

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

      add an optional*
      it's*
      that's*

    • @sunofabeach9424
      @sunofabeach9424 9 месяцев назад +3

      there is a language server for Lua with strict static typing

    • @brianfunt2619
      @brianfunt2619 7 месяцев назад

      ​@@klartnetNot if you annotate the variable as a number

  • @__Merchant
    @__Merchant Год назад +6

    Lua's way of printing that is even more cursed.

    • @__Merchant
      @__Merchant 2 месяца назад +1

      @xvutq706xcrt If you haven't understood the concept of watching the goddamn video, Python tells you that "hey, you are combining an integer and a string together so please fix that" because common sense, Lua on the other hand thinks it is an integer even though it's a string.
      But hey, you are a bot anyway.

    • @hvroblox
      @hvroblox 23 дня назад +1

      ​@__Merchant Lua doesn't think it is an integer, it takes it as an integer. For string concat, .. is used.

  • @Mark-lr9pb
    @Mark-lr9pb Год назад +6

    isn't lua string concatenation is double dots '..' or I just didn't know '+' also does concatenation?

    • @j3y445
      @j3y445 Год назад +11

      yea lua's concatenation is exclusively the dots. so the + operator here implicitly tries to either cast the string to a number or invoke an object's __add metamethod.

    • @Epsicronics
      @Epsicronics 7 месяцев назад +2

      Yeah I don't know if this entire comment section is trolling or everyone here is so knee deep into js/py brainrot they don't understand that + is not the concat operator.
      Yeah, turns out the math operator casts to numbers, just like the concat operator casts to strings, and people are calling this extremely intuitive system dumb?

  • @Cinarbayramic
    @Cinarbayramic 2 месяца назад +1

    every time i need to prove to my friends that python or lua is not any better i usually show them the weird syntax of those languages like whitespace for python and whatever this is for lua and they agree with me

  • @j3y445
    @j3y445 Год назад +15

    You used the wrong operator if you are trying to concatenate. Concatentation in Lua is purely using .. and not +. So when u use +, you are trying to invoke a mathematical operation so the interpreter tries to cast the string to a number or fail, and if it's an object call its __add metamethod or fail. So ur + operator on a string a number will only fail if u have an invalid number. If you try to do print("a" + 1) it will fail, but if u do print("a" .. 1) it will succeed and print "a1". If you try to do print("1" .. 1) it will print 11. Yes its still bad because its an implicit behavior, but its also somewhat more sensical if u consider that Lua has actually a dedicated concatenation operator and + is purely a math operator.

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

      i think it was just a joke but yeah

    • @mage3690
      @mage3690 Год назад +5

      Technically it's explicit behavior because the operator is asserting that both operands are of a certain type. At least, that's my opinion of it.

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

      @@mage3690 yea it’s explicit enough, but I sort of dislike the hidden control flow aspect of it. There’s a multitude of behaviors that can occur depending on context

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

      @@j3y445 yeah, it is hidden, and that's hella annoying. Especially when you can't change the hidden behavior, then it becomes downright infuriating.

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

      ​@@mage3690i _think_ you have C to blame for this as it really set the standard for things like this afaik. but in C's case you can kind of forgive it because what C is doing really _is_ arithmetic addition and not some freaky type coercion because the C compiler doesnt _really_ see "a" as a string (well, in C's case a "char") it just sees it as any other pointer that happens to point to an index in the ascii table and 1 as an ascii character _happens_ to have an ascii code of 1. (well not "happens" as in by pure coincidence, it was specifically planned out and there is a lot of freaky manipulations you can do like turn any lower-case characters into its uppercase by adding some constant number to it)
      type coercion is sort of hidden but at the same time you would kind of expect it to correctly convert a string of "1" into a number of 1 and be properly able to add them together. this may seem bad on a type-safety standard but most average people would simply _expect_ this to work and originally back when Lua was first invented that was really who Lua was designed for. and imo this is a much better middleground than what something like Python or something like C do which are essentially two opposite ends of the spectrum. C is so oblivious to the fact that what you are trying to use is a "char" that it doesnt even consider it a possibility at all that your ascii character is meant to be a char and not an integer. meanwhile Python is so scared of its users doing something a little risky that it doesnt even let you do it at all without jumping through a hoop and basically completely invalidating any convenience you would get out of such a feature.

  • @SameTheta
    @SameTheta 7 месяцев назад +1

    for anyone wondering, lua has a different concatenation symbol than python (being '..'). so when using + to attempt to concatenate a int or a float with a string containing an int or a float, it just results in the addition of both operands (otherwise resulting in an error if theres a type mismatch). if .. was used instead, it would output the intended result, being 11

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

    I have rewatched this too many times and I have died laughing each time

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

    It actually makes more sense in Lua than JS because "+" is always addition.

  • @eetumaenpaa594
    @eetumaenpaa594 Год назад +47

    lua LUA.lua

  • @gingeral253
    @gingeral253 Год назад +4

    Should I learn Lua? Seems like a fun time

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

      yes. This video does not tell the full story, because Lua has a dedicated concatenation operator which is simply ".." . So by invoking the add operator (+) in this video, Lua will either try to convert a string to a number or fail, or invoke the __add metamethod for objects or fail. But by using the .. operator you will either concatenate a string and a number, or a string and an object by invoking the __concat metamethod or fail. So the control flow is pretty obvious, but only if you actually know lua.

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

      Lua is actually really good, the haters here are overreacting and saying subjective stuff.

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

      if you have knowledge about basic concepts of programming, it'll take you a couple of days. Lua is basically Esperanto of programming languages, it is that easy to learn
      and almost as useless

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

      @@sunofabeach9424 i like it because it’s quite nice as an embedded language for as much as extensibility or as little as just configuration. Anything else, it’s not very good for. It’s kind of a super powered json, toml, xml, etc.

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

      there is no greater pleasure in life than using lua tables

  • @anere5326
    @anere5326 7 месяцев назад +2

    1 + "1",
    character for "1" = 49
    1 + 49 = 50 which is character for 2

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

    I remember learning lua and one of my early mistakes was using ‘+’ instead of ‘..’ to concatenate and being so confused.

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

    I was always very curious about Lua, after seeing this I want to learn it

  • @creatorbot0056
    @creatorbot0056 6 месяцев назад +2

    In roblox studio cause roblox script use lua. When you do that 1 + "1" the console will scream at you and say are you trying to do ..

  • @muffinsaur.
    @muffinsaur. 3 месяца назад

    i’ve only just stuck my fingers into the pie that is javascript, so naturally i have to be on my boy lua’s side

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

    python probably specifically does not allow you to output integer together with string, since you yourself determine what you output, integer or string

  • @MasIndie
    @MasIndie 12 дней назад

    Python beginner here, I can’t feel my brain watching this

  • @gpgamepremiums
    @gpgamepremiums 6 месяцев назад +1

    This might be one of the reasons why Roblox and CryEngine (its 2nd language) chose lua but not Python. At the same time, we use the string concatenation function and the addition function of companies such as Microsoft and Berry Labs with the "+" sign. However, Lua did not make this mistake and did the string concatenation with ".." and the addition with the "+" sign. As much as I wanted Roblox to use C# or JavaScript, we shouldn't underestimate Lua and frankly, I think it's a pretty good programming language. I would like to express my sincere congratulations to Roberto, Luiz and Waldemar!!

  • @noobkaz
    @noobkaz 6 месяцев назад +1

    this is why '..' exists for concat

  • @Garfield_Minecraft
    @Garfield_Minecraft 2 месяца назад +1

    lua LUA.lua
    why you name the file like that bruh
    and why it's 2 auto conversion? it converts string to number to default usually because I think it's actually more practical than convert number to string because why?

  • @reminderIknows
    @reminderIknows 7 месяцев назад

    this is known as type coercion, where using specific operators changes the type
    1 + "1" -> 2 (number)
    "5"..5 -> "55" (string)

    • @mbrofoc
      @mbrofoc 5 месяцев назад

      I think it's a must be programmed crime towards performance

  • @randomnumbers84269
    @randomnumbers84269 Месяц назад +1

    Are we just going to ignore all those lines before the print statement in Lua? 😂

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

    If you allow integer to plus string unintendtionally and no error raised, it's bug in your software you might never ever gonna find it.

    • @F4biano
      @F4biano 7 месяцев назад

      in lua concatenating is done using the ".." operator, so if you do "+" it can only ever mean you are trying to perform an arithmetic addition, therefore doing int + string can only ever happen if you are actually trying to mathematically add them together

  • @zergon321
    @zergon321 Год назад +6

    It's because of the purpose of the language. It's a client-side language. Usually you want a client application to run at least somehow no matter what happens. And Python is a server-side language where correctness is top priority

  • @real_below
    @real_below 6 месяцев назад

    calculating numbers X string is not possible in some lua engines but you can do tonumber("1") to convert your current string into a number or just simply use 1 + 1 like a normal person 💀
    (edit: btw some lua engines allow 1 + "1")

  • @Lees-kingdomn
    @Lees-kingdomn 6 месяцев назад

    Lua if you want to make some active function you want variable exam
    local a = 1
    local b = 2
    local ab = 1 + 2
    print(ab)
    But you can make short
    local a = 1
    local b = 2
    Print(a + b)

  • @overdsh_
    @overdsh_ 7 месяцев назад

    It's because lua autoamtically converts the string into a number. Imagine you have a user that inputs a number into the terminal and it returns a string, you would have to convert the string into a number manually wich works but it does it automatically so it's cool. And if it's a string that cant be converted into a number it will throw an error

  • @justchicknugget
    @justchicknugget Год назад +4

    JavaScript: "11"

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

      At least it’s better then 2.

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

      @@mgames3209 he used the wrong operator. If you want concatenation, you have to use .. in Lua. + is always a mathematical operator in Lua. So it will either try to convert a string to a number or fail, or call an objects __add metamethod or fail. And if your intention is concatenation, with the .. operator, Lua will convert a number to a string or try to call __concat metamethod on objects or fail on either of those. And on failure it gives u a useful error message. It's still implicit and only Lua programmers will actually know what the heck is going on.

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

      @@j3y445oh ok

  • @TheCyanKiller
    @TheCyanKiller 6 месяцев назад

    "Attempt to perform arithmetic (add) on number and string"

  • @user-unknown-jfjgjdmvorjrg
    @user-unknown-jfjgjdmvorjrg 2 месяца назад

    (Roblox Studio knowledge so my theory is prob wrong in the normal LUA cuz Roblox Studio uses a modified one I'm pretty sure) Problably sees that its trying to do an equation with a int value and a string value and converts the string to a number using tonumber()

  • @onee
    @onee 7 месяцев назад +1

    You can also do this in JavaScript. But I have a genuine question. Why would you ever wanna do this?

  • @hoodie_cat
    @hoodie_cat 7 месяцев назад +1

    tf was all that yap at the beginning of the lua file?

  • @markps97
    @markps97 5 месяцев назад

    I don't know what's going on, that's why I'm sticking to batch files.

  • @blueisthebest5k
    @blueisthebest5k 5 месяцев назад +1

    bro added an int and a str together 💀

  • @cheesepop7175
    @cheesepop7175 Год назад +16

    b-but you tried to add a string to a number so of course it would output ERROR and not 2

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

    I am a c programmer and am very confused, only briefly touched lua for nvim. Why is it not '2'? Take ascii code of '1', then add 1 to it and it becomes the ascii code for '2'? Alternatively this should work in most sane character sets aswell?

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

      I am a C programmer as well and I'm pretty sure it should be an empty string.

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

      Assuming that Lua's type inference treats it as a String (char *), yes.
      Assuming that the type inference classifies it as a character then it'd be a '2'
      I believe in lua "" and '' are evaluated identically, assuming so, it'd be down to the type inference system which it choses.
      Alternatively it may use a Struct for strings which could be all kinds of a mess

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

      Oh, I thought you were joking.
      "" in lua is neither a char or a char* - it's a lua string. How it is implemented doesn't matter, and you can't do arithmetic on it.
      The key to what happens here is the + operator, in lua, attempts to parse string operands into a number. 1+"1" in lua isn't equivalent to writing 1+"1" or 1+'1' in C, it's equivalent to 1+atoi("1").

  • @pcoi94-2
    @pcoi94-2 7 месяцев назад

    in lua, it would display "11" which is a string

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

    As a lua dev, my day is ruined

  • @sankx_SK
    @sankx_SK 7 месяцев назад

    i fucking love this man. Lua is strong 💪

  • @andreashanna6060
    @andreashanna6060 7 месяцев назад

    Lua: BROTHER! Look at me!!
    Javascript: ...

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

    wiat doesn't lua concatenate strings with double dots...?

  • @alphaqueueop
    @alphaqueueop 2 месяца назад +1

    Automatic conversion by convenience, but any competent developer would already know that...

  • @LCTesla
    @LCTesla 6 месяцев назад

    When I make a mistake I just want the language to call me an idiot to my face, not think it behind my back while nodding

  • @TFB2K-baubau
    @TFB2K-baubau 7 месяцев назад

    im questioning my life rn with this

  • @Yavkurse1
    @Yavkurse1 13 дней назад

    As Python geek, I can only say syntax error on line 42

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

    oh no, dont forget to cast your numbers to string before generating strings

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

      if the intention was to concatenate, you have to use the .. operator in lua. + will always try to add mathematically through either a string conversion to number which can fail, or by invoking an object's __add metamethod, which can also fail. And upon failure, obviously there is a useful error that tells you. Its still an implicit behavior, but it makes sense if you know lua.

  • @That_Random_Guy101
    @That_Random_Guy101 6 месяцев назад

    im pretty sure this is because of strings that only have numbers are treated as an int

  • @thacuber2a03
    @thacuber2a03 6 месяцев назад

    lmaoooooo, I actually made a post about that in my website, turns out that Lua is some years older than JavaScript, and has had string-to-number type coercion since it was first made
    when you use *any* operator, in fact, the string gets scanned to check if it's a number, and if it is, it's automatically converted to one

  • @SomeNinety
    @SomeNinety 29 дней назад +1

    print(1.. "1")

  • @sullivanbell-removedaccount
    @sullivanbell-removedaccount 6 месяцев назад

    esolang where its just a completely normal language except you have to spell "concatenate" whenever you wanna concatenate 2 strings

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

    if u want it to print 1 + "1" then just do print("1 + "1"")

  • @mila-d5b
    @mila-d5b 2 месяца назад

    LUA is the aimware of programming languages

  • @jeppknappen6901
    @jeppknappen6901 5 дней назад

    Hey what are datatypes never heard of it

  • @mypfpisfire-wv4sw
    @mypfpisfire-wv4sw 7 месяцев назад

    THIS IS ILLEGAL NOOOOOOOOOOOOOOOOOO AS A PYTHON USER IM CRYING

  • @FrozenRBLX
    @FrozenRBLX Месяц назад +1

    print("1+1")

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

    this makes an ok amount of sense since + only adds, and .. only concatenates, instead of js where + does both or python where you get an error. Yes yes tonumber() but I don’t care I am a lua supporter

  • @_GhostMiner
    @_GhostMiner 6 месяцев назад

    Javascript: 2 + "2" = 22; 2 - "2" = 0
    Lua:

  • @ItsVoidly
    @ItsVoidly 2 месяца назад +1

    Lua is peak (no joke involved (yes, really no joke (really (fr ( ok im fr ) ) ) ) ) )

  • @GeroCoati12
    @GeroCoati12 3 месяца назад

    The correct way to type a math operation in LUA is: print(1 +1 )

  • @ИванИсайков-я5с
    @ИванИсайков-я5с 9 месяцев назад

    Actually this: print("1" .. 1)
    will work to without type error (returns 22).
    That's quite nice)

  • @sankx_SK
    @sankx_SK 7 месяцев назад +1

    what debugger do you use for lua?

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

    print "some string" is syntactically valid, btw, :3

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

    tragically-typed programming language

  • @ivanp.2405
    @ivanp.2405 5 месяцев назад

    Bruh maybe because first variable is a number and second is the string? And if you would do it like this print(1 + 1) it will work

  • @100timezcooler
    @100timezcooler 7 месяцев назад

    this video save my life. thank you.

  • @VRixxo123
    @VRixxo123 7 месяцев назад

    I dont see how this could ever cause hidden issues

    • @gmdrandom6287
      @gmdrandom6287 7 месяцев назад

      It's fine in Lua for the most part (string concat and mathematical addition have different operators, so while the casting isn't explicit, it's not terrible)

  • @CriticVida
    @CriticVida 28 дней назад

    print (1 + 1) output: 2, print ("yo wsg my g") output: yo wsg my g

  • @cat_awry
    @cat_awry 6 месяцев назад

    That's why I like lua. It just makes more sense. Like how does "+" means concatenation!?!?

  • @Florida_man21
    @Florida_man21 Год назад +3

    Bro the music 😂

  • @FedorTheUser
    @FedorTheUser 5 месяцев назад

    1 + "1" = ERROR , about left parameter number, and right parameter text