LRAUV  revA
LuaAPI.h
Go to the documentation of this file.
1 
21 #ifndef LUAAPI_H_
22 #define LUAAPI_H_
23 
25 
27 class lua_State;
28 class DataReader;
29 class DataWriter;
30 class InputInfo;
31 class LuaNode;
32 class ScriptNode;
33 class Unit;
34 
42 class LuaAPI: public ScriptAPI
43 {
44 public:
45 
46  virtual ~LuaAPI();
47 
52  virtual ScriptNode* makeScriptFunction( const char* moduleName,
53  const char* componentName, const char* methodName,
55  const char* code, Logger& logger );
56 
57 protected:
58 
59  friend class LuaMissionAPI;
60 
61  class LuaState
62  {
63  public:
64  LuaState();
65  ~LuaState();
66  operator lua_State*()
67  {
68  return lua_;
69  }
70  private:
71  // Note that the copy constructor below is private and not given a body.
72  // Any attempt to call it will return a compiler error.
73  LuaState( const LuaState& old ); // disallow copy constructor
74  lua_State* lua_;
75  };
76 
77  static LuaState LUA_;
78 
79  friend class LuaNode;
80 
83  static const char* LoadFile( const char* filename );
84 
87  static const char* Exec( const char* command );
88 
92  static bool Exec( FlexArray<DataReader*>* inputs, FlexArray<SettingReader*>* settings,
93  bool& boolValue, FlexArray<DataWriter*>* outputs, FlexArray<const Unit*>* outUnits,
94  Logger& logger );
95 
98  static const char* Run();
99 
102  static const char* RunFunction( const char* functionName, Str& returnValue, bool isRoot = false );
103 
105  static bool IsTable( bool isRoot );
106 
109  static bool OpenTableItemByIndex( int index, bool isRoot );
110 
113  static bool OpenTableItemByName( const char* name, bool isRoot );
114 
116  static void PushNil();
117 
119  static int GetStackHeight();
120 
123  static int GetTableSize( bool isRoot );
124 
126  static void CloseTableItem();
127 
129  static bool GetBool( bool& readTo, bool isRoot );
130 
132  static bool GetNumber( double& readTo, bool isRoot );
133 
135  static bool GetString( Str& readTo, bool isRoot );
136 
138  static bool NewTable( const char* name, bool isRoot );
139 
141  static const char* NewFunction( const char* functionName, const char* functionBody, bool isRoot );
142 
143 private:
144  // Note that the copy constructor below is private and not given a body.
145  // Any attempt to call it will return a compiler error.
146  LuaAPI( const LuaAPI& old ); // disallow copy constructor
147 
149  LuaAPI();
150 
152 
154 
155 };
156 
157 #endif /* LUAAPI_H_ */
Client-side interface for injecting log data into the log queue.
Definition: Logger.h:30
Definition: LuaAPI.h:61
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 ...
Definition: LuaAPI.cpp:270
static const char * Run()
Runs whatever is on top of the stack with no args and no return.
Definition: LuaAPI.cpp:216
static void CloseTableItem()
Just pops the top item off the lua stack.
Definition: LuaAPI.cpp:330
Abstract base class for scripted programming language interfaces.
Definition: ScriptAPI.h:29
A DataAccessor that reads values from the Slate Contains a default dataValue that must not be NULL...
Definition: DataReader.h:30
bool isRoot() const
True if this is the root element.
Definition: LuaNode.h:123
virtual ScriptNode * makeScriptFunction(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 me...
Definition: LuaAPI.cpp:55
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
Definition: LuaAPI.cpp:380
Abstract base class for nodes in tree-like scripts.
Definition: ScriptNode.h:20
static const char * LoadFile(const char *filename)
Loads the indicated file.
Definition: LuaAPI.cpp:42
static bool NewTable(const char *name, bool isRoot)
creates a new empty table and adds to open node, returns true if successful
Definition: LuaAPI.cpp:367
A wrapper for the lua programming language interface.
Definition: LuaAPI.h:42
static bool IsTable(bool isRoot)
Is the item at the top of the stack a table?
Definition: LuaAPI.cpp:258
LuaAPI()
Private constructor for singleton.
Definition: LuaAPI.cpp:430
static int GetTableSize(bool isRoot)
Returns the size of the table on the top of the stack Returns -1 if not a table.
Definition: LuaAPI.cpp:320
lua_State * lua_
Definition: LuaAPI.h:74
A DataAccessor that writes values to the Slate via its associated DataElement.
Definition: DataWriter.h:27
virtual ~LuaAPI()
Definition: LuaAPI.cpp:22
static bool GetBool(bool &readTo, bool isRoot)
gets a boolean from the top of the stack
Definition: LuaAPI.cpp:337
Replacement for standard template class string.
Definition: Str.h:12
LuaNode * rootNode_
Definition: LuaAPI.h:153
LuaState()
Definition: LuaAPI.cpp:27
static const char * Exec(const char *command)
Runs the specified command, with no return.
Definition: LuaAPI.cpp:108
static bool GetString(Str &readTo, bool isRoot)
gets a unsigned char string from the top of the stack
Definition: LuaAPI.cpp:355
~LuaState()
Definition: LuaAPI.cpp:33
static LuaAPI Instance_
Definition: LuaAPI.h:151
static bool GetNumber(double &readTo, bool isRoot)
gets a number from the top of the stack
Definition: LuaAPI.cpp:344
Implements MissionAPI in the lua programming language.
Definition: LuaMissionAPI.h:22
Contains the ScriptAPI class definition.
Information to create a Input in a Method.
Definition: Method.h:31
static int GetStackHeight()
returns the height of the stack
Definition: LuaAPI.cpp:313
static void PushNil()
Pushes a nil onto the stack.
Definition: LuaAPI.cpp:307
static const char * RunFunction(const char *functionName, Str &returnValue, bool isRoot=false)
Runs specified function from the currently open table.
Definition: LuaAPI.cpp:232
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 CloseTa...
Definition: LuaAPI.cpp:289
Code that represents an engineering unit.
Definition: Unit.h:24
Implements ScriptNode for the LuaAPI.
Definition: LuaNode.h:26
static LuaState LUA_
Definition: LuaAPI.h:77