ReFRACtor
FullPhysics::RegisterLua Class Reference

This class handles the registration of luabind class wrappers with Lua. More...

#include <register_lua.h>

+ Collaboration diagram for FullPhysics::RegisterLua:

Static Public Member Functions

static int add_file_and_line (lua_State *ls)
 
static void register_lua (lua_State *ls)
 

Detailed Description

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:

  1. Add the registration code to the class code (e.g., for Foo, this is the file "foo.cc").
  2. Add the class to the list of classes in the function RegisterLua::register_lua found at "lib/Lua/register_lua.cc"

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:

#ifdef HAVE_LUA
#include "register_lua.h"
#endif

In level_1b_hdf.cc:

#ifdef HAVE_LUA
#include "register_lua.h"
REGISTER_LUA_DERIVED_CLASS(Level1bAcos, Level1b)
.def(luabind::constructor<std::string, std::string>())
#endif

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:

require("librefractor")

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

LUA_CPATH=install/lib/?.so lua
require "librefractor"
l1b = Level1bAcos("filename","soundingid")

Definition at line 105 of file register_lua.h.

Member Function Documentation

◆ add_file_and_line()

static int FullPhysics::RegisterLua::add_file_and_line ( lua_State *  ls)
static

◆ register_lua()

void FullPhysics::RegisterLua::register_lua ( lua_State *  ls)
static

Definition at line 119 of file register_lua.cc.


The documentation for this class was generated from the following files:

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:13