Why Lua 🥺

  Рет қаралды 321,965

Carrot

Carrot

Күн бұрын

Пікірлер: 755
@timelessnesses
@timelessnesses Жыл бұрын
who the fuck invited javascript devs to lua 💀🙏
@xanstraincvkuro8707
@xanstraincvkuro8707 Жыл бұрын
fr
@cycrothelargeplanet
@cycrothelargeplanet 10 ай бұрын
Fr
@EdKolis
@EdKolis 7 ай бұрын
Francium
@berthold64
@berthold64 7 ай бұрын
Javascript is inspired by lua
@brianviktor8212
@brianviktor8212 6 ай бұрын
@@berthold64 And I thought that guy was haunted by visions of hell and decided to let it out all out.
@Ulissescars
@Ulissescars Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
It’s just a lot easier
@kyleavery6372
@kyleavery6372 Жыл бұрын
(1 + 2 + "3") is "33"
@PimPumSObaka
@PimPumSObaka Жыл бұрын
exactly
@G-u-z-i-o
@G-u-z-i-o 6 ай бұрын
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 6 ай бұрын
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 ай бұрын
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 ай бұрын
@@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 Жыл бұрын
So Lua doesn't stop you from shooting your leg. Very nice
@sayven
@sayven Жыл бұрын
Yeah I expected this to actually work and that that would be the issue.
@pedroivog.s.6870
@pedroivog.s.6870 Жыл бұрын
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 Жыл бұрын
@@pedroivog.s.6870 almost certainly, that wretched language will type coerce nan to a string
@honk2448
@honk2448 Жыл бұрын
@@pedroivog.s.6870 oh it's bad, really bad. JS doesn't and never will make sense. 1 + 1 + "1" = "21"
@zyxyuv1650
@zyxyuv1650 Жыл бұрын
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 Жыл бұрын
well its not completely dead
@mudrost4934
@mudrost4934 Жыл бұрын
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 Жыл бұрын
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.
@NanerBag
@NanerBag Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
So true
@phir9255
@phir9255 Жыл бұрын
can't tell if this is sarcasm
@WinterNox
@WinterNox Жыл бұрын
It is sarcasm, ​@@phir9255.
@noelka8134
@noelka8134 Жыл бұрын
@@jco_sfm it could be 11, but no, it's 2... but it's pretty useless either way lol
@badradish2116
@badradish2116 Жыл бұрын
"static types are better" "no! dynamic types are better!" can't a man just get type inference with reasonable implicit casts?
@rikschaaf
@rikschaaf Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
Should be "a"+1 be "b" or "a1"?
@pranavgaur1086
@pranavgaur1086 Жыл бұрын
Funny words magic man
@potzko2552
@potzko2552 Жыл бұрын
learn rust or ocamel for that tbh, there are some great type inference in those
@qing-hh4su
@qing-hh4su Жыл бұрын
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_ 17 күн бұрын
that's what i was thinking too
@all_matters-dm1jw
@all_matters-dm1jw 5 күн бұрын
calm down dawg its a joke
@somenameidk5278
@somenameidk5278 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
@@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 Жыл бұрын
⁠@@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 Жыл бұрын
@@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.
@yerenzter
@yerenzter Жыл бұрын
Lua it just 150KB compiler while Python over a hundred megabytes does.
@Raspredval1337
@Raspredval1337 Жыл бұрын
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 ай бұрын
​@@Raspredval1337aw man NES developers shoulda added scripts to their games, imagine the possibilities 😢
@torque8047
@torque8047 6 ай бұрын
​@@niko5008If you wanna you could glitch the game to make it run arbitrary code. Look up snes code injection
@FaizKTG
@FaizKTG 2 ай бұрын
Plus it's much faster.
@hadawardgz
@hadawardgz Жыл бұрын
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 ай бұрын
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 ай бұрын
@@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 5 ай бұрын
@@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 5 ай бұрын
@@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 5 ай бұрын
@@hadawardgz oh. That's cool.
@Nox-Music
@Nox-Music Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
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 Жыл бұрын
then try print (0+"1"+"1")
@Nox-Music
@Nox-Music Жыл бұрын
@@xerlandia JavaScript says 011. Lua(u) says... 2
@lau6438
@lau6438 11 күн бұрын
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.
@gordonramsay8351
@gordonramsay8351 Жыл бұрын
lets be real, programming languages are cringe. i think we should send electrical impulses directly to the CPU to write binary code.
@dijital4801
@dijital4801 5 ай бұрын
may as well break out your punch cards while youre at it
@turuukuruu
@turuukuruu 4 ай бұрын
No you have to extract electricity from a jellyfish and input it to conputer to make efficient code to run
@JeLeff.
@JeLeff. 2 ай бұрын
fr
@ICM9
@ICM9 2 ай бұрын
@@turuukuruu ☝️🤓 jelly fishes produce venom not electricity nincompoop
@SomeCuteDoragons
@SomeCuteDoragons Ай бұрын
Too abstract ​@@dijital4801
@FitraFadilana
@FitraFadilana Жыл бұрын
in JS it will be "11"
@user-tw2kr6hg4r
@user-tw2kr6hg4r 6 ай бұрын
11 is honestly better than 2.
@P-39_Airacobra
@P-39_Airacobra 2 ай бұрын
@@user-tw2kr6hg4r only if you use a 2 year old's definition of addition
@kylezdancewicz7346
@kylezdancewicz7346 2 ай бұрын
@@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 19 күн бұрын
In assembly it's 50
@Michael-pp8lz
@Michael-pp8lz Жыл бұрын
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 Жыл бұрын
I did the opposite (started with python, now Java) and I want to kms
@sdn6605
@sdn6605 Жыл бұрын
Started with python and now doing c. What is genuinely wrong with his language??? Why is it built like this
@kooale3252
@kooale3252 Жыл бұрын
@@sdn6605 Me with python be like
@Bl0xxy
@Bl0xxy Жыл бұрын
started with python, now learning c++@@sdn6605
@АлександрКоновалов-ш1н
@АлександрКоновалов-ш1н Жыл бұрын
It's because you just have started. Advanced python isn't easy.
@TheCubicLog
@TheCubicLog Жыл бұрын
tbh I expected it to be "11" like javascript
@v0xl
@v0xl 7 ай бұрын
but lua has a separate sting concat operator (..)
@Brahvim
@Brahvim 6 ай бұрын
What? JavaScript does it THE SAME AS LUA.
@Nick12_45
@Nick12_45 6 ай бұрын
@@Brahvim 1 + "1" === "11"
@Гдекамин
@Гдекамин 5 ай бұрын
@@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 5 ай бұрын
@@Гдекамин Huh. I've heard that numbers inside strings can sometimes be treated as parsed values in JS. That's what I was referring to.
@__Merchant
@__Merchant Жыл бұрын
Lua's way of printing that is even more cursed.
@__Merchant
@__Merchant 2 ай бұрын
@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 9 күн бұрын
​@__Merchant Lua doesn't think it is an integer, it takes it as an integer. For string concat, .. is used.
@melody_florum
@melody_florum Жыл бұрын
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
@2Deep.
@2Deep. 2 ай бұрын
To be honest... Is actually a good thing...
@ameer6168
@ameer6168 Жыл бұрын
Javascript :- finally a worthy competitor
@CrazyStranger11
@CrazyStranger11 Жыл бұрын
What about C? printf("%c", 1 + '1') prints 2
@jonforhan9196
@jonforhan9196 Жыл бұрын
man ascii
@king_james_official
@king_james_official Жыл бұрын
if you do 1 + '9' it will print ":" because it is after "9" in the ascii table
@royler8848
@royler8848 Жыл бұрын
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 Жыл бұрын
Chaotic neutral coder
@trex511ft
@trex511ft Жыл бұрын
@@thecwd8919 lmao
@szupertntakos5000
@szupertntakos5000 Жыл бұрын
I'm not sure but print(1 .. "1") or print(1, "1") should work.
@JeLeff.
@JeLeff. 2 ай бұрын
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
@mrvoid8464
@mrvoid8464 Жыл бұрын
"You don't know me son" ~JavaScript
@hhhsp951
@hhhsp951 Жыл бұрын
"11" No matter what design, any programming language should either evaluate that as "11" or throw an error.
@gmdrandom6287
@gmdrandom6287 6 ай бұрын
Why?
@Orincaby
@Orincaby 7 ай бұрын
summary from the comments: + is arithmetic add .. is concatenate "+" casts the string to and int and thus prints 2
@sunofabeach9424
@sunofabeach9424 Жыл бұрын
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 ай бұрын
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
@cattokomo
@cattokomo Жыл бұрын
when you play with the metatable too much
@potatony997
@potatony997 Жыл бұрын
Shit man, i don't know how i got here or why i stayed but damn my brain just farted
@hadawardgz
@hadawardgz Жыл бұрын
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 Жыл бұрын
@@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 11 ай бұрын
@@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
@junetxpid2425
@junetxpid2425 Жыл бұрын
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 Жыл бұрын
"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 19 күн бұрын
​@@mage3690 That's because modern CPUs have dedicated hardware just for floats
@SameTheta
@SameTheta 6 ай бұрын
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
@Cinarbayramic
@Cinarbayramic Ай бұрын
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
@pedroivog.s.6870
@pedroivog.s.6870 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@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
@robertodelgado6387
@robertodelgado6387 2 ай бұрын
I was always very curious about Lua, after seeing this I want to learn it
@ICM9
@ICM9 2 ай бұрын
I remember learning lua and one of my early mistakes was using ‘+’ instead of ‘..’ to concatenate and being so confused.
@ItsVoidly
@ItsVoidly Ай бұрын
Lua is peak (no joke involved (yes, really no joke (really (fr ( ok im fr ) ) ) ) ) )
@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
@zergon321
@zergon321 Жыл бұрын
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
@gpgamepremiums
@gpgamepremiums 5 ай бұрын
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!!
@renren_does_programming
@renren_does_programming Жыл бұрын
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 Жыл бұрын
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 ай бұрын
there is a language server for Lua with strict static typing
@brianfunt2619
@brianfunt2619 7 ай бұрын
​@@klartnetNot if you annotate the variable as a number
@Codermiguel
@Codermiguel Ай бұрын
It actually makes more sense in Lua than JS because "+" is always addition.
@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
@tatertime
@tatertime Жыл бұрын
I have rewatched this too many times and I have died laughing each time
@creatorbot0056
@creatorbot0056 6 ай бұрын
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 ..
@reminderIknows
@reminderIknows 6 ай бұрын
this is known as type coercion, where using specific operators changes the type 1 + "1" -> 2 (number) "5"..5 -> "55" (string)
@mbrofoc
@mbrofoc 4 ай бұрын
I think it's a must be programmed crime towards performance
@Mark-lr9pb
@Mark-lr9pb Жыл бұрын
isn't lua string concatenation is double dots '..' or I just didn't know '+' also does concatenation?
@j3y445
@j3y445 Жыл бұрын
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 ай бұрын
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?
@eetumaenpaa594
@eetumaenpaa594 Жыл бұрын
lua LUA.lua
@emersoneisen
@emersoneisen Жыл бұрын
hole TWO.hole
@MediumSizedBagel
@MediumSizedBagel Жыл бұрын
​@@emersoneisenlol I was about to say that
@linuxization4205
@linuxization4205 5 ай бұрын
take TAKE take
@anere5326
@anere5326 6 ай бұрын
1 + "1", character for "1" = 49 1 + 49 = 50 which is character for 2
@Garfield_Minecraft
@Garfield_Minecraft 2 ай бұрын
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?
@cheesepop7175
@cheesepop7175 Жыл бұрын
b-but you tried to add a string to a number so of course it would output ERROR and not 2
@shdwmere
@shdwmere Жыл бұрын
~_~
@ShredBorges
@ShredBorges Жыл бұрын
t-that's the joke...
@noobkaz
@noobkaz 6 ай бұрын
this is why '..' exists for concat
@gingeral253
@gingeral253 Жыл бұрын
Should I learn Lua? Seems like a fun time
@j3y445
@j3y445 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
there is no greater pleasure in life than using lua tables
@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
@williamdrum9899
@williamdrum9899 19 күн бұрын
Performance issues everywhere
@markps97
@markps97 4 ай бұрын
I don't know what's going on, that's why I'm sticking to batch files.
@keenoogodlike
@keenoogodlike Жыл бұрын
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
@j3y445
@j3y445 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
​@@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.
@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 5 ай бұрын
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)
@RandomDylan
@RandomDylan Ай бұрын
if u want it to print 1 + "1" then just do print("1 + "1"")
@LCTesla
@LCTesla 5 ай бұрын
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
@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
@randomnumbers84269
@randomnumbers84269 Ай бұрын
Are we just going to ignore all those lines before the print statement in Lua? 😂
@TheCyanKiller
@TheCyanKiller 5 ай бұрын
"Attempt to perform arithmetic (add) on number and string"
@soapycanthandle
@soapycanthandle 5 ай бұрын
esolang where its just a completely normal language except you have to spell "concatenate" whenever you wanna concatenate 2 strings
@andreashanna6060
@andreashanna6060 7 ай бұрын
Lua: BROTHER! Look at me!! Javascript: ...
@TFB2K-baubau
@TFB2K-baubau 7 ай бұрын
im questioning my life rn with this
@Frozen_RobIox
@Frozen_RobIox Ай бұрын
print("1+1")
@SomeNinety
@SomeNinety 15 күн бұрын
print(1.. "1")
@markusTegelane
@markusTegelane 5 ай бұрын
and JavaScript be like "everything should be a string unless specified, so the answer is 11"
@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()
@justchicknugget
@justchicknugget Жыл бұрын
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
@sankx_SK
@sankx_SK 7 ай бұрын
i fucking love this man. Lua is strong 💪
@onee
@onee 7 ай бұрын
You can also do this in JavaScript. But I have a genuine question. Why would you ever wanna do this?
@Immadeus
@Immadeus Жыл бұрын
Lua is one of the languages of all time
@mypfpisfire-wv4sw
@mypfpisfire-wv4sw 7 ай бұрын
THIS IS ILLEGAL NOOOOOOOOOOOOOOOOOO AS A PYTHON USER IM CRYING
@stavros222
@stavros222 Жыл бұрын
Print(1.."1")
@opwip
@opwip Ай бұрын
While true do //Annihilates your computer end
@pcoi94-2
@pcoi94-2 6 ай бұрын
in lua, it would display "11" which is a string
@That_Random_Guy101
@That_Random_Guy101 5 ай бұрын
im pretty sure this is because of strings that only have numbers are treated as an int
@fdef12678
@fdef12678 Жыл бұрын
As a lua dev, my day is ruined
@MegoZ_
@MegoZ_ 4 ай бұрын
wiat doesn't lua concatenate strings with double dots...?
@nomadshiba
@nomadshiba Жыл бұрын
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.
@blueisthebest5k
@blueisthebest5k 4 ай бұрын
bro added an int and a str together 💀
@cat_awry
@cat_awry 5 ай бұрын
That's why I like lua. It just makes more sense. Like how does "+" means concatenation!?!?
@wrathofainz
@wrathofainz 13 күн бұрын
Java: "It's a string." Javascript: "Yea, what he said." Lua: "It's a number, see the plus sign?" Python: "This is wrong."
@triandot
@triandot Жыл бұрын
tragically-typed programming language
@Florida_man21
@Florida_man21 Жыл бұрын
Bro the music 😂
@wealth-wise2day
@wealth-wise2day 6 ай бұрын
WHY OH WHY??? WHY DO YOU DO THIS TO US LORD?? WHAT HAVE WE DONE TO YOU?!?!?!?
@FedorTheUser
@FedorTheUser 5 ай бұрын
1 + "1" = ERROR , about left parameter number, and right parameter text
@100timezcooler
@100timezcooler 7 ай бұрын
this video save my life. thank you.
@ivanp.2405
@ivanp.2405 4 ай бұрын
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
@4amVili
@4amVili Жыл бұрын
You can do print(1 + tonumber("1")) .
@alphaqueueop
@alphaqueueop 2 ай бұрын
Automatic conversion by convenience, but any competent developer would already know that...
@madbanana22
@madbanana22 5 ай бұрын
> does not understand how the language works > blames the language for it
@GabriellSimic
@GabriellSimic 4 ай бұрын
as a lua programmer, this
@CXLDMXNEofficial
@CXLDMXNEofficial 24 күн бұрын
1 + "1" = undefined
@epsi
@epsi 5 ай бұрын
I've seen JS devs on the verge of tears when they see Lua where typing is stronger: • (+) is strictly for addition (string→number is automatic). • (..) is strictly for string concatenation (number→string is automatic). With rules like that, you don't get things like this: node> null+true+1+'1'-3 18 I'm not saying we should be advocating for Lua in the browser in place of JS, but...
@mila-d5b
@mila-d5b 2 ай бұрын
LUA is the aimware of programming languages
@_GhostMiner
@_GhostMiner 5 ай бұрын
Javascript: 2 + "2" = 22; 2 - "2" = 0 Lua:
@ИванИсайков-я5с
@ИванИсайков-я5с 8 ай бұрын
Actually this: print("1" .. 1) will work to without type error (returns 22). That's quite nice)
why you NEED math for programming
5:03
Joma Tech
Рет қаралды 9 МЛН
This Is What 2 Years Of Scripting Looks Like
45:59
Ludius
Рет қаралды 35 М.
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
The Ultimate Tier Programming Tier List | Prime Reacts
26:57
ThePrimeTime
Рет қаралды 518 М.
Python laid waste to my C++!
17:18
Sheafification of G
Рет қаралды 183 М.
I made a horror game that's IMPOSSIBLE to SCREENSHOT!
3:52
Branta Games
Рет қаралды 2,4 МЛН
Hide & Seek, But You Are The Spike
28:00
XcreatorGoal
Рет қаралды 2,3 МЛН
Making a Game in Lua with No Experience
5:52
Goodgis
Рет қаралды 374 М.
3 Hours vs. 3 Years of Blender
17:44
Isto Inc.
Рет қаралды 6 МЛН
Running "Hello World!" in 10 FORBIDDEN Programming Languages
18:07
I Programmed your INSANE Ideas and this happened... (Pt. 3)
9:49
CodeCraftedPhysics
Рет қаралды 143 М.
Lua in 100 Seconds
2:24
Fireship
Рет қаралды 2,3 МЛН
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 120 МЛН