Skip to content

Please meet: Lua


Lua recently became very popular. I encountered Lua scripting in several applications including popular games, I believe it’s used in even more then Wikipedia says.

It’s extremely simple:

  • 6 data types (that’s counting “nul” and “function”),
  • no C++-style OOP out-of-box (but you can program one, he-he),
  • 400K of pure-C code

but is loaded with in-fashion features like

The only metaprogramming tutorial (with a ready code to implement virtual methods) is “Programming in Lua” book. Still, I don’t see a code to implement ad-hoc polymorphism… Maybe it’s a reason for another post 🙂

Redistributed book removed: it violated copyright.

2 Comments

  1. You can implement polymorphism through creative use of setmetatable and __index. Look through the Lua Wiki, the Lua Book or some of code from the Warcraft WowAce project for examples.

    Posted on 10-Dec-08 at 23:08 | Permalink
  2. On the second thought, ad-hoc polymorphism is easily implemented in Python-style constructor, just by calling parent constructor and reassigning proper methods.

    OTOH, I could be thinking about parametric polymorphism when I was writing “ad-hoc”. Which really needs a metatable trick with __call override and runtime parameter type analysis. And still a topic for another interesting hack 🙂

    Posted on 11-Dec-08 at 12:49 | Permalink

Post a Comment

Your email is never published nor shared.