lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


thanks

On Sat, Jul 12, 2008 at 12:57 PM, Graham Wakefield <lists@grahamwakefield.net> wrote:

On Jul 11, 2008, at 9:08 PM, Abhinav Lele wrote:

What does this snippet from lunar.h in http://lua-users.org/wiki/CppBindingWithLunar  mean
#define method(class, name) {#name, &class::name}
Just a macro for shorthand sugar. 

The # symbol in a macro inserts quotation marks around the given value (i.e., it constructs a string).
The ampersand (&), class name, double colon (::) and function name thing is the standard form of a (static) class method pointer in C++, which can be compatible with a C function pointer type.
So, the macro results in a form compatible with a C-style lua module registration.

Lunar<Account>::RegType Account::methods[] = {
method(Account, deposit),
-->
{ "deposit", &Account::deposit },

method(Account, withdraw),
-->
{ "withdraw", &Account::withdraw } ,

etc.

I.e. it's just shorthand sugar.



--
Emo Philips  - "I got some new underwear the other day. Well, new to me."