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 412 of file lbp_function.h.

#include <lbp_function.h>

Public Member Functions

 LuaState (void)
 
 ~LuaState (void)
 
lua_State * LL (void)
 
void Reset (void)
 
void Install (const std::string &rFilename)
 
void Push (const Type *fdata)
 
TypePop (void)
 
TypeGlobal (const std::string &gname, const Type *fdata=0)
 
void Evaluate (const std::string &expr)
 
std::list< std::string > Complete (const std::string &word)
 

Static Public Member Functions

static LuaStateG (void)
 
static void Initialize (lua_State *pLL)
 
static void Install (lua_State *pLL, const std::string &rFilename)
 
static void Push (lua_State *pLL, const Type *fdata)
 
static TypePop (lua_State *pLL)
 
static TypeGlobal (lua_State *pLL, const std::string &gname, const Type *fdata=0)
 
static void Evaluate (lua_State *pLL, const std::string &expr)
 
static std::list< std::string > Complete (lua_State *pLL, const std::string &word)
 

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

Definition at line 1131 of file lbp_function.cpp.

◆ ~LuaState()

faudes::LuaState::~LuaState ( void )

Destructor

Definition at line 1132 of file lbp_function.cpp.

◆ LuaState() [2/2]

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

Definition at line 656 of file lbp_function.h.

Member Function Documentation

◆ Close()

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

Definition at line 1175 of file lbp_function.cpp.

◆ 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.

Definition at line 1468 of file lbp_function.cpp.

◆ Complete() [2/2]

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.

Definition at line 1473 of file lbp_function.cpp.

◆ 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)

Definition at line 1427 of file lbp_function.cpp.

◆ Evaluate() [2/2]

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)

Definition at line 1432 of file lbp_function.cpp.

◆ G()

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

Convenience global Lua state.

Definition at line 1157 of file lbp_function.cpp.

◆ 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)

Definition at line 1406 of file lbp_function.cpp.

◆ Global() [2/2]

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)

Definition at line 1411 of file lbp_function.cpp.

◆ Initialize()

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

Definition at line 1183 of file lbp_function.cpp.

◆ 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)

Definition at line 1152 of file lbp_function.cpp.

◆ LL()

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

Access Lua state.

Definition at line 1135 of file lbp_function.cpp.

◆ Open()

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

Definition at line 1164 of file lbp_function.cpp.

◆ Pop() [1/2]

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)

Definition at line 1322 of file lbp_function.cpp.

◆ 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)

Definition at line 1317 of file lbp_function.cpp.

◆ 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)

Definition at line 1211 of file lbp_function.cpp.

◆ Push() [2/2]

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)

Definition at line 1216 of file lbp_function.cpp.

◆ 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.

Definition at line 1138 of file lbp_function.cpp.

Member Data Documentation

◆ mpLL

lua_State* faudes::LuaState::mpLL
private

Definition at line 658 of file lbp_function.h.


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

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen