METATABLES | What are they and how can we use them?

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ธ.ค. 2024

ความคิดเห็น • 100

  • @TreeLeeGames
    @TreeLeeGames 11 หลายเดือนก่อน +78

    meta

    • @crusherfire1
      @crusherfire1  11 หลายเดือนก่อน +18

      meta

    • @inactivated101
      @inactivated101 11 หลายเดือนก่อน +3

      tables

    • @IAmLoviatar
      @IAmLoviatar 11 หลายเดือนก่อน +16

      teta mables

    • @disreceded
      @disreceded 11 หลายเดือนก่อน +5

      the metaverse

    • @himynameisidiot
      @himynameisidiot 11 หลายเดือนก่อน +1

      beta aables

  • @NeverEverFaceTheDark
    @NeverEverFaceTheDark 8 หลายเดือนก่อน +38

    First four minutes have already done a much better job of saying what these things are than anyone else's explanation I've tried. Thanks

    • @Gix0_0
      @Gix0_0 4 หลายเดือนก่อน +2

      Og this is such a lifesaver nobody explains it like this. This is so simple to understand because instead of jumping to the __index then doing myTable.__index = myTable which is a ridiculously complicated syntax to understand on your first time __add just makes so much intuitive sense!

  • @nutmooose
    @nutmooose 9 หลายเดือนก่อน +24

    Thanks for this short and comprehensive tutorial on Metatables. You have a natural skill for teaching. I don't usually comment on youtube but I wanted to say this because I believe that we do have so many teachers but only few who has truly can do it well.

    • @crusherfire1
      @crusherfire1  9 หลายเดือนก่อน +4

      thanks 🫡

  • @Andrew90046zero
    @Andrew90046zero 11 หลายเดือนก่อน +27

    One thing metatables do is make it so you don't have to store functions directly inside the "instance" tables. Which means your tables only store the things that are different between each table, which saves memory.
    All of your table instances will refer to the same "metatable" for various functions and other data that is shared among all the table instances.

    • @crusherfire1
      @crusherfire1  11 หลายเดือนก่อน +8

      This is a great point too! Just like how you can create a single function that listens to events (for example, maybe you have dozens of UI buttons) to save on memory as well

    • @Andrew90046zero
      @Andrew90046zero 11 หลายเดือนก่อน +4

      ​@@crusherfire1 Thank you :D
      Idk if you plan on doing many episodes on metatables. But covering the other meta functions would definately be cool, and would compliment this video well.
      Because if somone wanted to achieve those benefits I mentioned, they would need __index and __newindex.
      Which then goes into how Lua achieves OOP.

    • @crusherfire1
      @crusherfire1  11 หลายเดือนก่อน +7

      @@Andrew90046zero
      I think I'll make a video in the future talking about how to use metatables for imitating OOP concepts, thanks!

  • @imaSeraphRBX
    @imaSeraphRBX 11 หลายเดือนก่อน +18

    Thank you for this. Ive been ignoring them for the longest time because they confused me.
    I finally get it!
    I still dont think I'll end up using them, but who knows, I may suprise myself.

    • @imaSeraphRBX
      @imaSeraphRBX 11 หลายเดือนก่อน

      Do you know what type of scenario would be good to implement these? They seem like fun@@epixerty

    • @TheMastrBuilder
      @TheMastrBuilder 7 หลายเดือนก่อน

      They are useful in OOP

  • @Jesseyn
    @Jesseyn 11 หลายเดือนก่อน +14

    Very Well explained video, I saw some people struggle to understand metatables so i thought it would be very difficult. But, then I saw your video and it looked so easy.

  • @SilverSuperGamer
    @SilverSuperGamer 9 หลายเดือนก่อน +3

    Absolutely brilliant for making those stupidly annoying to make but excellent in the end ui libraries

  • @zeekbit
    @zeekbit 5 หลายเดือนก่อน +2

    I was scared of these for so long when watching tutorials, and now sleep deprived me just learned the entire thing in 18 minutes. VERY easy to follow video wonderful explanations keep it up man

  • @vy_productions
    @vy_productions หลายเดือนก่อน

    Excellent video. I've been super intimidated by the apparent complexity of metatables, and this video made it super easy to understand -- it's essentially just operator overloads for tables! Nice work here.

  • @diegoj4382
    @diegoj4382 หลายเดือนก่อน +1

    This is a sort of operator overloading in R. What I don't get is the need to call table to a linkedlist(?) and call set metatable to the assignment of different methods to a list. At the end, metatabled are just classes and tables are instances

  • @LovPotatoes
    @LovPotatoes 11 หลายเดือนก่อน +4

    One of the best Explanations out there! Appreciate this!

  • @Tybeef
    @Tybeef 10 หลายเดือนก่อน +1

    I used metatables to create an OOP without knowing what it does, but this was a great explanation of what it is.

  • @yami5007
    @yami5007 3 หลายเดือนก่อน

    Pretty much the best tutorial i have seen on metatables , thanks !

  • @sicknickeroni
    @sicknickeroni 11 หลายเดือนก่อน

    thanks! as someone who does most work in javascript and typescript, i had no previous understanding of metatables.

  • @jarrett-xr3bm
    @jarrett-xr3bm 11 หลายเดือนก่อน +2

    you've explained it better than anyone else, thanks!

  • @mafnor2268
    @mafnor2268 11 หลายเดือนก่อน

    Finally a tutorial on metatables I can understand, this was the only thing I never understood in lua lmao.

  • @guyguy6516
    @guyguy6516 5 หลายเดือนก่อน +1

    Hey man, a bit late to the party but I just discovered your channel and the way you explain things is just crazy good. Keep up the good work :) +1 sub !

  • @infinity2394
    @infinity2394 8 หลายเดือนก่อน

    YOU SIR ARE AMAZING, ONE OF THE BEST EXPLANATIONS OF METATABLES, THE ANALOGY WITH THE RESTRAUNT WAS ABSOLUTELY BRILLAINT, YOU HAVE MY UTMOST GRATITUDE! 🔥🔥

  • @hexarinumerial
    @hexarinumerial 8 หลายเดือนก่อน +1

    Nice video, the only thing I would've recommended is to teach the "self" syntax because that's very important in metatables

  • @FoXcodeZ
    @FoXcodeZ 15 วันที่ผ่านมา

    13:45 I would not recommend that. A simpler and safer solution is to use the __concat method, which handles concatenating our class with other strings. After implementing this, the __tostring method and the print function should work correctly.

  • @jonaslavicka2411
    @jonaslavicka2411 2 หลายเดือนก่อน +1

    What is a practical use of metatables? To me they seem more complicated than classes, yet less powerful

  • @BedwarsRBLX
    @BedwarsRBLX 11 หลายเดือนก่อน +43

    Basically: Table on steroids

  • @taazered
    @taazered 11 หลายเดือนก่อน +1

    i finally understand now, true enlightenment

  • @amit6875
    @amit6875 11 หลายเดือนก่อน

    Damn thats the best explanation i have seen of metatables, great video

  • @TheMastrBuilder
    @TheMastrBuilder 7 หลายเดือนก่อน

    Hey Cursher! Regarding the const thing, there actually is something (at least for tables) that does allow you to create readonly values. Using 'table.freeze()', we can freeze a table, making it readonly. It does not effect any tables inside it though.
    My question: How would one implement 'table.freeze()' into a system like this? Creating a whole result variable seems very round about'y', but you can't perform calculations on a read-only value.. In a nutshell, I'm trying to learn how to make code as short as possible and would like to know the pro methods. 😊

  • @SoollzPlays
    @SoollzPlays 6 หลายเดือนก่อน +1

    this was easier than i thought

  • @Miltonator77
    @Miltonator77 6 หลายเดือนก่อน +1

    Hi, I know I'm late to the party, but I have a question: In what circumstances would a metatable be more beneficial than a set of normal functions acting on a table. I am curious to the use cases behind the metatable. To me, the metatable seems more complicated to set up and limited to the pre-defined functions created by the Lua developers. I am new to Roblox Lua and programming in general and am interested in learning from an experienced programmer such as yourself. I loved this video and think you are an amazing teacher.

    • @crusherfire1
      @crusherfire1  6 หลายเดือนก่อน +1

      There are many metamethods for all the possible scenarios of things that can happen to your tables with the interpreter not knowing how to do them by default, so I wouldn't consider them limited.
      Metamethods won't be used commonly (I rarely use them), but the most common metamethod typically used is the __index metamethod due to its necessity for OOP.
      Another way I utilize the __index metamethod is by creating a table that errors when you index it with a key that doesn't exist. This is useful when you're trying to imitate an enum and want to make errors in your game easier to trace as the code will immediately halt instead of having a nil value floating around your code.

  • @bretabel1642
    @bretabel1642 6 หลายเดือนก่อน +1

    to be more specific, methods are functions that belong to objects/classes

  • @Cidosophy
    @Cidosophy 9 หลายเดือนก่อน +1

    My question is which is better practice to use?
    function additionMetaTable.__add(ourTable, value)

    end
    *OR*
    local additionMetaTable = {
    __add = function(ourtable, value)
    }
    Is there any major differences? is one better practice over the other? personally I find it much easier to understand using the first way I provided

    • @crusherfire1
      @crusherfire1  9 หลายเดือนก่อน +2

      Either way works, just a different way to create them.
      However, it should be noted that if you need to make any functions that need to have access to the hidden 'self' keyword, it needs to be created using the colon notation.
      function SomeClass:SomeMethod()
      --- has access to self
      end
      SomeClass.SomeMethod = function()
      --- does not have access to self
      end

  • @akaisstudios
    @akaisstudios 9 หลายเดือนก่อน

    Good class, i'm making my own system and i'm using some of your lession to put in practice.

  • @stephen5070
    @stephen5070 6 หลายเดือนก่อน +1

    How can using Meta Tables help me while using Module Scripts? I'm currently making an Incremental game in Roblox Studio which will have a lot of unlockable buttons for the player to purchase. I have two choices, either hardcoding a huge wall of text to return a table or generate a bunch of keys inside a table but I have to be able remember each of the returned variables. I'm trying to manage a big player data base and make sure nothing gets out of control once my game becomes bigger.

  • @Yusaq
    @Yusaq 10 หลายเดือนก่อน

    thanks

  • @AlexD-mg9xb
    @AlexD-mg9xb 11 หลายเดือนก่อน

    i aint watching allat but im liking cause crusherfire is goated

    • @TheMastrBuilder
      @TheMastrBuilder 7 หลายเดือนก่อน +2

      Then you'll never truely learn :)

  • @SudoSed
    @SudoSed 10 หลายเดือนก่อน +1

    Hello, I am taking the course called Roblox studio on the Udemy platform. However, the course currently does not have a Turkish subtitle option. I have a request to add Turkish subtitles. Help me in this matter

    • @yami5007
      @yami5007 3 หลายเดือนก่อน

      Hala studio öğreniyor musun

  • @AskAKill99
    @AskAKill99 2 วันที่ผ่านมา

    From learning C++ first i was like wtf until he said making a new table in memory the method was just looking not unserstandable. Until explained logically.maybe i only understand computer logic wasnt understanding why this way until the creation of the new table which is easier to understand

  • @polymerr
    @polymerr 6 หลายเดือนก่อน

    is there anyway you can post your roblox studio script editor theme? it's really nice to the eyes (ok never mind, I found it)

  • @hapablap2088
    @hapablap2088 13 วันที่ผ่านมา

    why do we have both __add and __sub if you can just change the operand? And what do you do if you want to get something like: "myTable ^ 2 + 3"

  • @betapacket
    @betapacket 11 หลายเดือนก่อน +1

    did anyone tell him that using pairs or ipairs is redundant because you can just pass the table in the for loop (for x, y in ipairsOrPairs(z) -> for x, y in z)

    • @crusherfire1
      @crusherfire1  11 หลายเดือนก่อน +16

      Yes, I know you can pass a table directly without the use of an iterator like ipairs() or pairs(). This is a feature exclusive to Luau and not native Lua.
      However, if you do not use an iterator and pass the table itself and if that table has a metatable with a custom __call metamethod, that __call metamethod will be executed, which may not be desired behavior. Wrapping in ipairs() or pairs() prevents that issue.

    • @xwewfbgcangvao6159
      @xwewfbgcangvao6159 6 หลายเดือนก่อน +1

      @@crusherfire1thx

  • @ultimate_masterpiece
    @ultimate_masterpiece 11 หลายเดือนก่อน

    make a FastCast tutorial please and also a tutorial about ViewportFrames 💖💖

    • @crusherfire1
      @crusherfire1  11 หลายเดือนก่อน +1

      I actually have not yet found a need to use the FastCast module.
      However, you don't need to wait for me to learn it, I'd recommend reading the documentation for FastCast and experimenting with it yourself!
      etithespir.it/FastCastAPIDocs/
      As for ViewportFrames, maybe?! 🤔

  • @EpicPico0625
    @EpicPico0625 11 หลายเดือนก่อน +1

    Essentially tables with modifiable behavior

  • @arandom_bwplayeralt
    @arandom_bwplayeralt 2 หลายเดือนก่อน

    holy shet i actually might need string interpolation

  • @mightymixsal
    @mightymixsal 4 หลายเดือนก่อน

    So it's like a module script but for tables

    • @GuizinPE81
      @GuizinPE81 3 หลายเดือนก่อน

      Modules are tables generally

  • @o_master362
    @o_master362 5 หลายเดือนก่อน

    Metatables are also great ways for exploiters to hook onto your functions ;)

  • @RexBruhh
    @RexBruhh 9 หลายเดือนก่อน

    Whenever I try to print something out I get as output table: 0x79d1391f852dbe5e

  • @tal5667
    @tal5667 9 หลายเดือนก่อน

    what's your studio colours? looks sick

    • @crusherfire1
      @crusherfire1  9 หลายเดือนก่อน

      you can check out this plugin for some neat code editor color schemes:
      create.roblox.com/store/asset/3617323299

  • @noturne54
    @noturne54 7 หลายเดือนก่อน

    I never ever saw any real utility to the metamethods except __index and __newindex other than making tables fancier. Maybe organization? Its not the best for it, so it seems kinda pointless tho.

    • @nxsus
      @nxsus 6 หลายเดือนก่อน

      __eq

  • @bbnmm8720
    @bbnmm8720 11 หลายเดือนก่อน +1

    1:37 what is the music tell me now or your next code will give a error 😈😈

    • @crusherfire1
      @crusherfire1  11 หลายเดือนก่อน

      oh no!
      the music for this video can be found here:
      th-cam.com/video/muLrR10nThM/w-d-xo.html

    • @bbnmm8720
      @bbnmm8720 11 หลายเดือนก่อน

      In a distant kingdom where bytes danced to algorithmic melodies and codes wove the fabric of the digital universe, a young programmer found themselves ensnared in the clutches of a dreadful curse: the dreaded "Fatal Error". This error cast a shadow over their work, bringing forth despair and frustration. Try as they might, they couldn't unravel the origins of this mysterious error.
      In their distress, they sought help. They made their way to the tower of the wise code master, an old and sage programmer known as Master Algorithmos. The tower was shrouded in digital mist, and with hope in their heart, they knocked on the door.
      Master Algorithmos, with their long beard and white hair, welcomed them kindly. With a wise smile, they said, "Ah, young one, I see the cloak of the 'Fatal Error' has enveloped you. But fear not, for every error has its solution, and every problem, its answer."
      Seated at a table laden with code manuscripts, Master Algorithmos guided them through the intricate pathways of the algorithm, unveiling hidden secrets and invisible patterns. With patience and wisdom, they explored lines of code, debugged functions, and unraveled the enigmas of programmatic logic.
      As the hours passed and the stars danced in the digital sky, they felt a weight being lifted off their shoulders. The "Fatal Error" began to lose its grip on them. Thanks to the guidance of Master Algorithmos, they began to see the light at the end of the programming tunnel.
      Finally, after a journey of learning and discovery, they found the solution to the "Fatal Error". With a simple adjustment to the code, the curse was broken, and the project came back to life, shimmering with newfound energy.
      In gratitude to the wise code master, they thanked Master Algorithmos with humility and respect. They vowed to honor the knowledge gained and share it with other programmers, so that they would never again succumb to the power of the "Fatal Error".
      And so, with a light heart and a renewed mind, they returned to their work, ready to face new challenges with courage and determination. For now they knew that, with the right guidance and the will to learn, no programming error could stand in their way. And thus, the legend of the one who broke free from the curse of the "Fatal Error" spread throughout the kingdom, inspiring programmers everywhere to never give up, no matter how daunting the code.@@crusherfire1

    • @bbnmm8720
      @bbnmm8720 11 หลายเดือนก่อน

      @@crusherfire1 i meant... thanks you wont get any error, will use this song for programming rn

  • @yourcomputerhasdied
    @yourcomputerhasdied 11 หลายเดือนก่อน

    I loove metatables 🤤

  • @JeffaFloppa
    @JeffaFloppa 11 หลายเดือนก่อน +1

    now we need oop...

  • @PumpyGT
    @PumpyGT 2 หลายเดือนก่อน

    metable

  • @rfo.
    @rfo. 11 หลายเดือนก่อน

    Thx

  • @Schwert_Brawl_Stars
    @Schwert_Brawl_Stars 11 หลายเดือนก่อน

    Have you a dc server?

    • @crusherfire1
      @crusherfire1  11 หลายเดือนก่อน

      I do have a server but it's not public

    • @Schwert_Brawl_Stars
      @Schwert_Brawl_Stars 11 หลายเดือนก่อน

      @@crusherfire1 ah okay nice 👍

  • @Andrew90046zero
    @Andrew90046zero 11 หลายเดือนก่อน +1

    table

  • @seeray11
    @seeray11 3 หลายเดือนก่อน

    0-0:8. That’s my story…

  • @crooda3681
    @crooda3681 5 หลายเดือนก่อน

    table with workers

  • @ralphwuu
    @ralphwuu 11 หลายเดือนก่อน

    Similar to Python dunder methods

    • @crusherfire1
      @crusherfire1  11 หลายเดือนก่อน +1

      Yup, and metatables allow us to imitate classes! You can actually recreate many Roblox classes, like Vector3, entirely from tables and metatables!

  • @Zadano
    @Zadano 2 หลายเดือนก่อน

    Now we know where Metamethod and Metatableindex got their names from lol