what does class() actually do?

I’m thinking I might grow a bit of a unit testing framework for Codea as part of my new series of articles (any minute now on http://www.xprogramming.com). So I am looking at how to do reflection kinds of things in Codea/lua. I see that I can learn a lot from the keys in the tables, _G and the table that represents a class.

I’m curious to know, however, what the class() function actually does. Could we see the source for it, and/or an explanation, please?

Thanks!

The code used for class() can be found here: http://twolivesleft.com/Codea/Talk/discussion/96/class-inheritances/p1

Because Lua is table-based, we get reflection essentially for free, and that capability is there regardless of whether you use some implementation of class-based programming.

In general, Codea’s class() function provides a way to enable inheritance. It’s very no-frills and it doesn’t do much else. It’s worth noting that there are other implementations out there that provide more features (such as https://github.com/kikito/middleclass), and other OO paradigms that can be implemented in Lua (like prototyping for example, which is what JavaScript primarily uses).

You can find similar and additional information on the wiki here.

Thanks!