Detailed Description

Wrapper class to maintain a Lua state.

This class is still under construction. It aims for a sensible collection of operations that we may want to execute on a Lua state from the libFAUDES perspective. The current implementation provides static members that directly operate on a lua_State as well as a more comfortable interface that operates on thre wrapped faudes::LusState.

Definition at line 413 of file lbp_function.h.

#include <lbp_function.h>

Public Member Functions

 LuaState (void)
 Constructor. More...
 
 ~LuaState (void)
 Destructor. More...
 
lua_State * LL (void)
 Access Lua state. More...
 
void Reset (void)
 Reinitialize Lua state. More...
 
void Install (const std::string &rFilename)
 Install LuaExtension to Lua state. More...
 
void Push (const Type *fdata)
 Push faudes typed object on the Lua stack. More...
 
TypePop (void)
 Pop faudes typed object from Lua stack. More...
 
TypeGlobal (const std::string &gname, const Type *fdata=0)
 Get/set global data. More...
 
void Evaluate (const std::string &expr)
 Evaluate Lua expression. More...
 
std::list< std::string > Complete (const std::string &word)
 Complete Lua identifier. More...
 

Static Public Member Functions

static LuaStateG (void)
 Convenience global Lua state. More...
 
static void Initialize (lua_State *pLL)
 Initialze. More...
 
static void Install (lua_State *pLL, const std::string &rFilename)
 Install LuaExtension to Lua state. More...
 
static void Push (lua_State *pLL, const Type *fdata)
 Push faudes typed object on the Lua stack. More...
 
static TypePop (lua_State *pLL)
 Pop faudes typed object from Lua stack. More...
 
static TypeGlobal (lua_State *pLL, const std::string &gname, const Type *fdata=0)
 Get/set global data. More...
 
static void Evaluate (lua_State *pLL, const std::string &expr)
 Evaluate Lua expression. More...
 
static std::list< std::string > Complete (lua_State *pLL, const std::string &word)
 Complete Lua identifier. More...
 

Private Member Functions

 LuaState (const LuaState &)
 
void Open (void)
 
void Close (void)
 

Private Attributes

lua_State * mpLL
 

Constructor & Destructor Documentation

◆ LuaState() [1/2]

faudes::LuaState::LuaState ( void  )

Constructor.

◆ ~LuaState()

faudes::LuaState::~LuaState ( void  )

Destructor.

◆ LuaState() [2/2]

faudes::LuaState::LuaState ( const LuaState )
inlineprivate

Definition at line 657 of file lbp_function.h.

Member Function Documentation

◆ Close()

void faudes::LuaState::Close ( void  )
private

◆ Complete() [1/2]

std::list< std::string > faudes::LuaState::Complete ( const std::string &  word)

Complete Lua identifier.

This method uses a variation of Mike Pall's advaced readline support patch to fugure possible completions if a string to match a valid identifyer.

Parameters
wordString to complete
Returns
List of completions, first entry is longest common prefix.

◆ Complete() [2/2]

static std::list< std::string > faudes::LuaState::Complete ( lua_State *  pLL,
const std::string &  word 
)
static

Complete Lua identifier.

This static version is meant for applications that maintain their Lua state themselves. See also Evaluate(const std::string&)

Parameters
pLLLua state
wordString to complete
Returns
List of completions, first entry is longest common prefix.

◆ Evaluate() [1/2]

void faudes::LuaState::Evaluate ( const std::string &  expr)

Evaluate Lua expression.

This method runs the Lua-interpreter on the specified expression. In the case of an error, an exception will be thrown.

Exceptions
Exception
  • Lua Error (id 49)

◆ Evaluate() [2/2]

static void faudes::LuaState::Evaluate ( lua_State *  pLL,
const std::string &  expr 
)
static

Evaluate Lua expression.

This static version is meant for applications that maintain their Lua state themselves. See also Evaluate(const std::string&)

Parameters
pLLLua state
exprExpression to evaluate
Exceptions
Exception
  • Lua Error (id 49)

◆ G()

static LuaState* faudes::LuaState::G ( void  )
static

Convenience global Lua state.

◆ Global() [1/2]

Type* faudes::LuaState::Global ( const std::string &  gname,
const Type fdata = 0 
)

Get/set global data.

This method provides access to global variables. To set a variable, provide a non-NULL fdata parameter. If you obmitt the fdata paraneter, the default will indicate a get operation. Here, the value is returned as a copy and owned by the caller.

An expection is thrown if the variable either does not exist, or cannot be converted to a faudes::Type.

Parameters
gnameName of global variable
fdataData to set
Exceptions
Exception
  • Lua Error (id 49)

◆ Global() [2/2]

static Type* faudes::LuaState::Global ( lua_State *  pLL,
const std::string &  gname,
const Type fdata = 0 
)
static

Get/set global data.

This static version is meant for applications that maintain their Lua state themselves. See also Globat(const std::string&, const Type*)

Parameters
pLLLua state
gnameName of global variable
fdataData to set
Exceptions
Exception
  • Lua Error (id 49)

◆ Initialize()

static void faudes::LuaState::Initialize ( lua_State *  pLL)
static

Initialze.

Loads std libraries and libFAUDES wrappers.

Note: this static version is provided for applications that maintain their lua state themselves. If yo use the wrapper class LuaState, you dont need explicit initialisation.

Parameters
pLLLua state

◆ Install()

void faudes::LuaState::Install ( const std::string &  rFilename)

Install LuaExtension to Lua state.

This function instantiates a LuaFunctionDefinition objects from the file and uses the Install member function to install each function to the specified lua state. Thus, after the extension has been installed, the respective Lua functions can be invoked within Lua as if they where C++ function with SWIG generated wrappers.

Note: if you want to use the extension via the run-time-interface, you must also register them with the FunctionRegistry; see also the static method LuaFunctionDefinition::Register(const std::string&).

Parameters
rFilenameSource file (typically .flx)

◆ LL()

lua_State* faudes::LuaState::LL ( void  )

Access Lua state.

◆ Open()

void faudes::LuaState::Open ( void  )
private

◆ Pop() [1/2]

static Type* faudes::LuaState::Pop ( lua_State *  pLL)
static

Pop faudes typed object from Lua stack.

This static version is meant for applications that maintain their Lua state themselves. See also Pop(const Type&)

Parameters
pLLLua state
Returns
Destination for pop data
Exceptions
Exception
  • Lua Error (id 49)

◆ Pop() [2/2]

Type* faudes::LuaState::Pop ( void  )

Pop faudes typed object from Lua stack.

This method uses SWIG generated type casts to retrieve the faudes object from the userdata on the top of the stack. It then uses the faudes Copy() method to instantiate a copy, to be owned by the caller.

Returns
Destination for pop data
Exceptions
Exception
  • Lua Error (id 49)

◆ Push() [1/2]

void faudes::LuaState::Push ( const Type fdata)

Push faudes typed object on the Lua stack.

This method uses SWIG generated constructors to instantiate new Lua userdata object of the same type as the specified data. It than invokes the faudes Assign method to assign a copy.

Parameters
fdataData to push
Exceptions
Exception
  • Lua Error (id 49)

◆ Push() [2/2]

static void faudes::LuaState::Push ( lua_State *  pLL,
const Type fdata 
)
static

Push faudes typed object on the Lua stack.

This static version is meant for applications that maintain their Lus state themselves. See also Push(const Type&)

Parameters
pLLLua state
fdataData to push
Exceptions
Exception
  • Lua Error (id 49)

◆ Reset()

void faudes::LuaState::Reset ( void  )

Reinitialize Lua state.

This method reconstructs the internal Lua state. Any references become invalid. Any LuaFunctiondefinitions from the FunctionRegistry will be (re-)installed to the new state.

Member Data Documentation

◆ mpLL

lua_State* faudes::LuaState::mpLL
private

Definition at line 659 of file lbp_function.h.


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

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen