Lua - metatables

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Lua - metatables

      These are looking like arrays to me, even more like SQL tables in a strange but in my mind kinda way. The way you have a key -> value relationship, and how they are accessed. Would this be accurate?

      Edit: Forgot to mention, that really is an unique approach to make Lua OOP!
      You may call me char 71 97 100 100 97 109.

      The post was edited 1 time, last by Gaddam ().

    • RE: Lua - metatables

      You're describing tables in general, not metatables.

      A Lua table is an associative array where the key can be anything. In this way, they're kind of like STL maps. Under the covers, Lua tables actually have two components. The first is an array component, which acts just like an array. The second is a hash table, which handles the rest. If you treat a table purely like an array, you'll get all the benefits (like fast look-ups). It's an incredibly simple yet powerful concept.

      A metatable is a type of table that you attach to another table to modify the behavior of Lua. It's necessary for things like inheritance, where you want to call the base-class function if it doesn't exist in the subclass. It's also used to override operators.

      These two concepts combined make Lua a simple yet powerful and versatile language. That's what makes it one of my favorite scripting languages.

      -Rez