Hacker News new | ask | show | jobs
by chatmasta 744 days ago
It’s really much more like JavaScript (due to its prototypical nature), where “everything is an object” is effectively saying the same thing.
1 comments

It's much more like JS without all the prototype stuff.
Aren't Lua metatables and JS prototypes almost the same mechanism?

I say almost, because I think metatables are more broad than JS prototypes - you can emulate JS prototypes behavior using Lua metatables[0], but I don't think the reverse can be done (maybe with some Proxy[1] hackery?).

[0] https://www.lua.org/pil/13.4.1.html

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Yes, you're right, `__index` does behave a lot like `__proto__`. I often forget that it is one of the few entries in the metatable that doesn't have to be a function.