Introspection and navel gazing

"Thomas Nelson" <[email protected]>
Newsgroups gmane.comp.lang.lua.bind.user
Message-ID <4F630C3C97AC456D8276B6042683C479@Spawn>
Perhaps I'm going about this in entirely the wrong way, or this may not even
be possible as things are now... or I'm misunderstanding something. So some
pointers here would be appreciated.  

A long winded description:
In the (perhaps oversimplified) code below is a class NavelGazer. An
instance of this class may be created in the C++ and passed to Lua or it may
be created by a Lua script. 

It may also be subclassed in lua and have new methods added. 

I need to be able to examine an instance of NavelGazer from C++ and see if
an arbitrarily named method has been defined in the lua subclass.

<C++>
class NavelGazer
{
  public:
    NavelGazer( ) {}
    virtual ~NavelGazer() {}
    
    void examineMyself(const std::string &strForWhat)
    {
      luabind::class_info cinfo (luabind::get_class_info(*this));
      
      luabind::object method = cinfo.methods[strForWhat];
      
      /* do something with the method */
    }
    
    static void bindScripting(Lua_state *pScript)
    { using namespace luabind;
      
      module(L)
      [
        class_<NavelGazer>("NavelGazer")
          .def(constructor<>())
          .def("examine", &NavelGazer::examineMyself)
      ];

    }
};
</C++>
<Lua>
class 'ASubClass' (NavelGazer)

function ASubClass:__init()
	NavelGazer.__init();
end

function ASubClass:ALuaOnlyMethod()
	return print("haha can't find me.");
end

------------------
JustBase = NavelGazer();
JustBase:examine("ALuaOnlyMethod"); -- would NOT find anything.

Derived = ASubClass();
Derived:examine("ALuaOnlyMethod"); -- should find it
</Lua>

--
Thomas Nelson  [email protected]  
--------------------------------------------------------------
"If you still have gas, you're not lost".
- French explorer Pierre Frontage.
(M.Frontage was so influential in the exploration of North America many
roads are still named after him.)




------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.