::className and ::method calls

I have been learning how to embed the Lua scripting language into a very simple OpenGL application I am creating with C++. As a part of this adventure, I've been examining a C++ class called Luna that binds C++ objects to Lua. The code for Luna is available here: http://lua-users.org/wiki/SimplerCppBinding. The code under the section entitled, “luna.h for Lua 5.0” contains the code that I have been studying.

My question does not concern any of the Lua specific calls, but rather the ::className and ::method static variables that are being accessed on the template's class. For example, in the code snippets:

luaL_newmetatable(L, T::className);

and

for (RegType *l = T::methods; l->name; l++) {

I would like to learn more about these, but have been unable to uncover much information about them. For example, a google search of C++ className does not yield very fruitful results. Are there any additional static calls that can be made? It reminds me a little bit of Java's reflection capabilities, and I would like to know what kind of information is available besides ::className and ::methods (if any at all).

I would appreciate being pointed towards a better search query or perhaps an article with a useful explanation.
That is a typical idiom used to provide information about the instantiated template class for use by descendants and users.

For example, STL containers list value_type as the type of the contained values. That way, you can create another template that uses that information.

Here's an example I wrote that I use all the time:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  //--------------------------------------------------------------------------
  // member_of()
  //   Unary predicate to return whether or not a value is a member of a
  //   given container.
  //
  template <typename Container>
  struct member_of: std::unary_function <typename Container::value_type, bool>
    {
    const Container& container;
    member_of( const Container& container ): container( container ) { }
    bool operator () ( const typename Container::value_type& value )
      {
      return std::find( container.begin(), container.end(), value )
          != container.end();
      }
    };

Notice lines 7 and 11, which use that information in the specification of this new object.

Now it can be used handily. For example, to determine the number of whitespace characters in a string, I can say:

int num_whitespaces = count_if( s.begin(), s.end(), member_of <string> ( " \f\n\r\t\v" ) );

Neat, huh?
Thank you for your response, but I am still a little in the dark. I would still like to do some reading about className, methods, and even the value_type you mentioned. Is there any place where I can read through all the static variables that are available on an instantiated template? Thanks!
Not really...
For STL objects, the SGI site has pretty good documentation (I use it all the time because <functional> is not documented elsewhere very well -- except on slow MSDN).
http://www.sgi.com/tech/stl/functors.html

For other things you will just have to look through the source code. Outside of the STL there is no standard convention.


I'm out of time tonight, but I'll post you something else useful tomorrow.
Ah ha, problem solved.

I was way over analyzing the problem. When I was examining the Luna class (which is where the code snippets in my original post were copied from), I thought that ::className and ::methods were some sort of special C++ functionality I had not yet learned about. This was totally incorrect.

It turned out that "className" and "methods" were simply static methods that were, by convention, added to the classes being processed by the Luna class template. If I had spent more time looking at the class being passed to Luna, I would have realized this.

This is probably what you were already pointing out to me with value_type. However, I still was misunderstanding what was going on, even after your first reply.
Welcome to the wonderful world of C++... (I say that to myself all the time...)

It seems I misunderstood your original code anyway... ::methods, etc were actually objects and not types, as I assumed.

But I'm glad you figured it out anyway. :-)
Topic archived. No new replies allowed.