ReFRACtor
|
This class handles the registration of luabind class wrappers with Lua. More...
#include <register_lua.h>
Static Public Member Functions | |
static int | add_file_and_line (lua_State *ls) |
static void | register_lua (lua_State *ls) |
This class handles the registration of luabind class wrappers with Lua.
One approach to this is to have a central function that registers everything, and as we add classes update that central function. An alternative is the one selected here, were we have a more decentralized registration. Classes set up the registration in their own area, and then simple get listed and needing registration in the file "register_lua.cc". It would be nice to decentralize this completely, but I could never figure out a way to actually do this.
So registration involves 2 steps:
The registration code is cookie cutter, so we have macros to help do this. The registration is different depending on if we have a derived class with a base class, or a class that doesn't derive from another (or at least one that we want to tell Lua about).
An example of this:
In level_1b.cc:
In level_1b_hdf.cc:
Then in register_lua.cc, we add
Note that you don't need to put all the member functions into the Lua registration, just the ones you want to call in Lua. For many classes, this will just be the constructors. We use Lua configuration files for creating the objects needed in Level 2 Full physics, not to do major computation with it. That is more what we do with the Python wrappers. Lua is a small language that is ideal for integration in the C++ code, but it is no replacement for Python, nor is it meant to be.
Pretty much all our classes are Printable. We've put the magic incantation in place for classes in the macros (this ties the Lua function __tostring to the C++ code print_to_string). If you have a class that is not printable, we'll need to add a macro to support that.
We normally use Lua through our C++ code. It can be useful, particularly when testing, to go the other way. We define the function "luaopen_refractor" to go the other way, call in Lua like:
Note that you should use the installed library, like we do with python (i.e., do a "make install").
You will need to make sure that the library is on the PATH. Lua uses an odd syntax for its path, an example of using it would be
Definition at line 105 of file register_lua.h.
|
static |
|
static |
Definition at line 119 of file register_lua.cc.