LuaDataModel.h
Go to the documentation of this file.
1 
20 #ifndef LUADATAMODEL_H_113E014C
21 #define LUADATAMODEL_H_113E014C
22 
23 #include "uscxml/config.h"
25 #include <list>
26 
27 extern "C" {
28 #include "lua.h"
29 #include "lualib.h"
30 #include "lauxlib.h"
31 }
32 
33 #ifdef BUILD_AS_PLUGINS
34 #include "uscxml/plugins/Plugins.h"
35 #endif
36 
37 
38 namespace uscxml {
39 class Event;
40 class Data;
41 }
42 
43 namespace uscxml {
44 
50 class LuaDataModel : public DataModelImpl {
51 public:
52  LuaDataModel();
53  virtual ~LuaDataModel();
54  virtual std::shared_ptr<DataModelImpl> create(DataModelCallbacks* callbacks);
55 
56  virtual void addExtension(DataModelExtension* ext);
57 
58  virtual std::list<std::string> getNames() {
59  std::list<std::string> names;
60  names.push_back("lua");
61  return names;
62  }
63 
64  virtual bool isValidSyntax(const std::string& expr);
65 
66  virtual void setEvent(const Event& event);
67 
68  // foreach
69  virtual uint32_t getLength(const std::string& expr);
70  virtual void setForeach(const std::string& item,
71  const std::string& array,
72  const std::string& index,
73  uint32_t iteration);
74 
75  virtual bool evalAsBool(const std::string& expr);
76  virtual Data evalAsData(const std::string& expr);
77  virtual Data getAsData(const std::string& content);
78 
79  virtual bool isDeclared(const std::string& expr);
80 
81  virtual void assign(const std::string& location,
82  const Data& data,
83  const std::map<std::string, std::string>& attr = std::map<std::string, std::string>());
84  virtual void init(const std::string& location,
85  const Data& data,
86  const std::map<std::string, std::string>& attr = std::map<std::string, std::string>());
87 
88 protected:
89 
90  static int luaInFunction(lua_State * l);
91 
92  lua_State* _luaState;
93 };
94 
95 #ifdef BUILD_AS_PLUGINS
96 PLUMA_INHERIT_PROVIDER(LuaDataModel, DataModelImpl)
97 #endif
98 
99 }
100 
101 #endif /* end of include guard: LUADATAMODEL_H_113E014C */
virtual Data evalAsData(const std::string &expr)
Return a string as an evaluated Data object.
Definition: LuaDataModel.cpp:351
Definition: Breakpoint.cpp:26
virtual void addExtension(DataModelExtension *ext)
Register an extension to get data into and out of the data-model.
Definition: LuaDataModel.cpp:269
virtual void assign(const std::string &location, const Data &data, const std::map< std::string, std::string > &attr=std::map< std::string, std::string >())
Assign a data object to a location in the data-model.
Definition: LuaDataModel.cpp:476
virtual bool isDeclared(const std::string &expr)
Determine whether a given variable / location is declared.
Definition: LuaDataModel.cpp:470
virtual std::list< std::string > getNames()
Return a list of names to be matched by the datamodel attribute in SCXML.
Definition: LuaDataModel.h:58
virtual void init(const std::string &location, const Data &data, const std::map< std::string, std::string > &attr=std::map< std::string, std::string >())
Initialize a variable / location in the data-model with a given data object.
Definition: LuaDataModel.cpp:588
Definition: DataModelImpl.h:61
Abstract base class for all data-model implementations.
Definition: DataModelImpl.h:77
Lua data-model.
Definition: LuaDataModel.h:50
virtual void setEvent(const Event &event)
Set the given event as _event in the data-model's global scope.
Definition: LuaDataModel.cpp:273
virtual std::shared_ptr< DataModelImpl > create(DataModelCallbacks *callbacks)
The Factory wants to instantiate a new instance.
Definition: LuaDataModel.cpp:209
virtual bool isValidSyntax(const std::string &expr)
Determine whether a given string constitutes valid syntax in the data-model's language.
Definition: LuaDataModel.cpp:398
virtual bool evalAsBool(const std::string &expr)
Evaluate a given expression as a boolean.
Definition: LuaDataModel.cpp:593
virtual void setForeach(const std::string &item, const std::string &array, const std::string &index, uint32_t iteration)
Set a given item to the object at a given index for one iteration.
Definition: LuaDataModel.cpp:450
Definition: Event.h:94
virtual uint32_t getLength(const std::string &expr)
Evaluate the given expression as something iterable and return its length.
Definition: LuaDataModel.cpp:412
Callbacks available for every data-model.
Definition: DataModelImpl.h:47
virtual Data getAsData(const std::string &content)
Return a string as an unevaluated Data object.
Definition: LuaDataModel.cpp:609
Definition: Data.h:44