LRAUV  revA
LuaAPI Class Reference

A wrapper for the lua programming language interface. More...

#include <LuaAPI.h>

Inheritance diagram for LuaAPI:
Collaboration diagram for LuaAPI:

Classes

class  LuaState
 

Public Member Functions

virtual ~LuaAPI ()
 
virtual ScriptNodemakeScriptFunction (const char *moduleName, const char *componentName, const char *methodName, FlexArray< InputInfo * > &inputs, FlexArray< SettingInfo * > &settings, const char *code, Logger &logger)
 Returns a ScriptNode within the namespace of componentName that contains a function with the given methodName, with arguments of the given inputNames, with the indicated code. More...
 
- Public Member Functions inherited from ScriptAPI
virtual ~ScriptAPI ()
 Destructor. More...
 

Static Protected Member Functions

static const char * LoadFile (const char *filename)
 Loads the indicated file. More...
 
static const char * Exec (const char *command)
 Runs the specified command, with no return. More...
 
static bool Exec (FlexArray< DataReader * > *inputs, FlexArray< SettingReader * > *settings, bool &boolValue, FlexArray< DataWriter * > *outputs, FlexArray< const Unit * > *outUnits, Logger &logger)
 Runs the function on top of the stack with the indicated args and returns the indicated outputs. More...
 
static const char * Run ()
 Runs whatever is on top of the stack with no args and no return. More...
 
static const char * RunFunction (const char *functionName, Str &returnValue, bool isRoot=false)
 Runs specified function from the currently open table. More...
 
static bool IsTable (bool isRoot)
 Is the item at the top of the stack a table? More...
 
static bool OpenTableItemByIndex (int index, bool isRoot)
 Opens an item from the table on the top of the stack by its zero-based index it must be closed later with CloseTableItem() More...
 
static bool OpenTableItemByName (const char *name, bool isRoot)
 Opens an item from the table on the top of the stack by its name it must be closed later with CloseTableItem() More...
 
static void PushNil ()
 Pushes a nil onto the stack. More...
 
static int GetStackHeight ()
 returns the height of the stack More...
 
static int GetTableSize (bool isRoot)
 Returns the size of the table on the top of the stack Returns -1 if not a table. More...
 
static void CloseTableItem ()
 Just pops the top item off the lua stack. More...
 
static bool GetBool (bool &readTo, bool isRoot)
 gets a boolean from the top of the stack More...
 
static bool GetNumber (double &readTo, bool isRoot)
 gets a number from the top of the stack More...
 
static bool GetString (Str &readTo, bool isRoot)
 gets a unsigned char string from the top of the stack More...
 
static bool NewTable (const char *name, bool isRoot)
 creates a new empty table and adds to open node, returns true if successful More...
 
static const char * NewFunction (const char *functionName, const char *functionBody, bool isRoot)
 creates a new function and adds to open node, returns error message if error More...
 

Static Protected Attributes

static LuaState LUA_
 

Private Member Functions

 LuaAPI (const LuaAPI &old)
 
 LuaAPI ()
 Private constructor for singleton. More...
 

Private Attributes

LuaNoderootNode_
 

Static Private Attributes

static LuaAPI Instance_
 

Friends

class LuaMissionAPI
 
class LuaNode
 

Additional Inherited Members

- Protected Member Functions inherited from ScriptAPI
 ScriptAPI (const char *name, const char *extension)
 Protected constructor for ABC. More...
 
 ScriptAPI ()
 Note that the default constructor below is private and not given a body. More...
 
 ScriptAPI (const ScriptAPI &old)
 Note that the copy constructor below is private and not given a body. More...
 

Detailed Description

A wrapper for the lua programming language interface.

Allows scripted modules and components to share much of the same API as c++ modules and components. Works closely with Tethys.lua code.

Constructor & Destructor Documentation

LuaAPI::~LuaAPI ( )
virtual

References rootNode_.

LuaAPI::LuaAPI ( const LuaAPI old)
private
LuaAPI::LuaAPI ( )
private

Private constructor for singleton.

Member Function Documentation

void LuaAPI::CloseTableItem ( )
staticprotected

Just pops the top item off the lua stack.

Just pops the top item off the LUA_ stack.

References LUA_.

Referenced by LuaNode::close(), LuaNode::getIndexedNode(), LuaNode::getNamedNode(), and NewFunction().

const char * LuaAPI::Exec ( const char *  command)
staticprotected

Runs the specified command, with no return.

Returns pointer to error message if unable to do so.

References LUA_.

Referenced by LuaNode::execute(), and LuaMissionAPI::loadMissionFile().

bool LuaAPI::Exec ( FlexArray< DataReader * > *  inputs,
FlexArray< SettingReader * > *  settings,
bool &  boolValue,
FlexArray< DataWriter * > *  outputs,
FlexArray< const Unit * > *  outUnits,
Logger logger 
)
staticprotected

Runs the function on top of the stack with the indicated args and returns the indicated outputs.

Runs the function on top of the stack with the indicated args and sets the indicated outputs.

If boolValue is true, it will be set to the single boolean result of the function.

Returns true on success.

References Syslog::CRITICAL, FlexArray< T >::get(), DataReader::getDefaultUnit(), SettingReader::getDefaultUnit(), LUA_, Units::NONE, SettingReader::read(), DataReader::read(), FlexArrayBase::size(), Syslog::StringToSeverity(), Logger::syslog(), and DataWriter::write().

bool LuaAPI::GetBool ( bool &  readTo,
bool  isRoot 
)
staticprotected

gets a boolean from the top of the stack

References LUA_.

Referenced by LuaNode::readBool().

bool LuaAPI::GetNumber ( double &  readTo,
bool  isRoot 
)
staticprotected

gets a number from the top of the stack

References LUA_.

Referenced by LuaNode::readDouble().

int LuaAPI::GetStackHeight ( )
staticprotected

returns the height of the stack

References LUA_.

bool LuaAPI::GetString ( Str readTo,
bool  isRoot 
)
staticprotected

gets a unsigned char string from the top of the stack

References LUA_.

Referenced by LuaNode::readString(), and RunFunction().

int LuaAPI::GetTableSize ( bool  isRoot)
staticprotected

Returns the size of the table on the top of the stack Returns -1 if not a table.

References IsTable(), and LUA_.

Referenced by LuaNode::getNodeCount().

bool LuaAPI::IsTable ( bool  isRoot)
staticprotected

Is the item at the top of the stack a table?

References LUA_.

Referenced by LuaNode::getNodeCount(), GetTableSize(), LuaNode::hasChildNodes(), OpenTableItemByIndex(), and OpenTableItemByName().

const char * LuaAPI::LoadFile ( const char *  filename)
staticprotected

Loads the indicated file.

loads the indicated file.

Returns pointer to error message if unable to do so.

References LUA_.

Referenced by LuaMissionAPI::loadMissionFile().

ScriptNode * LuaAPI::makeScriptFunction ( const char *  moduleName,
const char *  componentName,
const char *  methodName,
FlexArray< InputInfo * > &  inputs,
FlexArray< SettingInfo * > &  settings,
const char *  code,
Logger logger 
)
virtual

Returns a ScriptNode within the namespace of componentName that contains a function with the given methodName, with arguments of the given inputNames, with the indicated code.

Implements ScriptAPI.

References LuaNode::getNamedNode(), LuaNode::newChildFunction(), LuaNode::newChildNode(), rootNode_, and FlexArrayBase::size().

const char * LuaAPI::NewFunction ( const char *  functionName,
const char *  functionBody,
bool  isRoot 
)
staticprotected

creates a new function and adds to open node, returns error message if error

References CloseTableItem(), Str::cStr(), and LUA_.

Referenced by LuaNode::newChildFunction().

bool LuaAPI::NewTable ( const char *  name,
bool  isRoot 
)
staticprotected

creates a new empty table and adds to open node, returns true if successful

References LUA_.

Referenced by LuaNode::newChildNode().

bool LuaAPI::OpenTableItemByIndex ( int  index,
bool  isRoot 
)
staticprotected

Opens an item from the table on the top of the stack by its zero-based index it must be closed later with CloseTableItem()

opens an item from the table on the top of the stack by its zero-based index it must be closed later with CloseTable()

References IsTable(), LUA_, and PushNil().

Referenced by LuaNode::getIndexedNode(), and LuaNode::open().

bool LuaAPI::OpenTableItemByName ( const char *  name,
bool  isRoot 
)
staticprotected

Opens an item from the table on the top of the stack by its name it must be closed later with CloseTableItem()

opens an item from the table on the top of the stack by its name it must be closed later with CloseTable()

References IsTable(), LUA_, and PushNil().

Referenced by LuaNode::getNamedNode(), and LuaNode::open().

void LuaAPI::PushNil ( )
staticprotected

Pushes a nil onto the stack.

References LUA_.

Referenced by LuaNode::execute(), OpenTableItemByIndex(), and OpenTableItemByName().

const char * LuaAPI::Run ( )
staticprotected

Runs whatever is on top of the stack with no args and no return.

Returns pointer to error message if unable to do so.

References LUA_.

Referenced by LuaMissionAPI::loadMissionFile().

const char * LuaAPI::RunFunction ( const char *  functionName,
Str returnValue,
bool  isRoot = false 
)
staticprotected

Runs specified function from the currently open table.

Returns pointer to error message if unable to do so.

References GetString(), and LUA_.

Referenced by LuaMissionAPI::loadMissionFile().

Friends And Related Function Documentation

friend class LuaMissionAPI
friend
friend class LuaNode
friend

Member Data Documentation

LuaAPI LuaAPI::Instance_
staticprivate
LuaNode* LuaAPI::rootNode_
private

Referenced by makeScriptFunction(), and ~LuaAPI().


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