Learning Lua: Part 21 Using Metatables & Metamethods to simulate OOP in Lua: Matrix Addiction

preview_player
Показать описание
Learn to program in Lua. Lua is a popular scripting language that is widely used by many app and game engines including Roblox, Solar2D, Core, Defold, Cocos2D, neovim, minetest, Amazon Lumberyard, moai, and many other great tools.


In Part 21, we continue learning about objects with the use of metatables and metamethods. This continues a subset of tutorials on OOP (object-oriented programming) and how to implement many OOP features in Lua. In this tutorial, Dr. Burton shows how to do matrix addition as a metamethod

Unlock the power of Lua programming with my latest book, "Learning Lua." Whether you're a beginner or an experienced coder, this comprehensive guide will take you on a journey to mastering Lua. Get your copy now:

Рекомендации по теме
Комментарии
Автор

just went thru the 21 parts ... Thanks a lot Dr.!

MyCenturion
Автор

Thanks Dr. Burton for explaining this complex topic in very simple and short videos, looking forward for the next ones

appdomus
Автор

Thank You!, This series is very well made I wonder why it doesn't receive more attention.

Kitsune_Dev
Автор

It seems like Lua is being used for things far beyond what was originally intended by the language creators. Perhaps there will be a "Lua 2" that includes proper OOP. If polymorphism, encapsulation, and inheritance were first-class language features, proper coding and debugging support would follow. Surely that would be preferable to the current collection of hack-like workarounds and missing features. (No reflection on your efforts here, of course)

agnichatian
Автор

Could you do a video on memory management?

RCdiy
Автор

Thanks for the tutorial. I did one experiment and associated the metatable __add method of myTable2 with a different method to see what will happen.

To my surprise it still worked as long as I was adding myTable1 + myTable2. However if I switch the places (myTable2+myTable1), then myTable2's __add function is called. So I guess one should be extra careful when using this.

Is there any practical value of having two different __add (or other operator) functions for different objects?

petarpetrov
Автор

Any idea why lua does not have a round() implementation? I know how to write my own.

RCdiy
Автор

What would be the difference between table["n"] = 5 and table.n = 5 ?

haakonpad
Автор

?? Why did not you debug by explaining the API commands

Niyzoky
Автор

we wait lua-c interaction lessons in detail.

mumin