Free Electron
LuaHandler.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __lua_LuaHandler_h__
8 #define __lua_LuaHandler_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /** lua execution component. Can also operate as a handler.
16 
17  Similar to LuaExec except that on handle() the lua function
18  handle is called instead of the whole script. This allows for
19  initialization to be done by the script at some preceding time (via
20  calling execute()).
21 
22  @copydoc LuaHandler_info
23  */
24 class LuaHandler : public Initialize<LuaHandler>,
25  virtual public Dispatch,
26  virtual public HandlerI,
27  virtual public LuaI
28 {
29  public:
30  LuaHandler(void);
31 virtual ~LuaHandler(void);
32 
33  void initialize(void);
34 
35  // AS LuaI
36 virtual bool preloadString(const String &text);
37 virtual Result loadFile(const String &filename);
38 virtual Result loadString(const String &text);
39 
40 virtual void set(const String &key, Record r_value);
41 virtual void set(const String &key, sp<RecordArray> ra_value);
42 virtual void set(const String &key, const String &value);
43 virtual void set(const String &key, const Real &value);
44 virtual void set(const String &key, Vector2 &value);
45 virtual void set(const String &key, Vector3 &value);
46 virtual void set(const String &key, Vector4f &value);
47 virtual void set(const String &key, sp<Layout> l_value);
48 virtual void set(const String &key, sp<Component> spValue);
49 virtual void set(const String &key, sp<Scope> spValue);
50 virtual void set(const String &key, sp<StateCatalog> spValue);
51 
52 virtual Record getRecord(const String &key);
53 virtual String getString(const String &key);
54 virtual Real getReal(const String &key);
55 virtual Vector2 getVector2(const String &key);
56 virtual Vector3 getVector3(const String &key);
57 virtual Vector4 getVector4(const String &key);
58 virtual Vector4f getVector4f(const String &key);
59 
60 virtual bool execute(void);
61 virtual bool execute(const String &a_fnName);
62 virtual void flush(void);
63 virtual void alias(String a_aliasName,String a_trueName);
64 
65  // AS HandlerI
66 virtual void handle(Record& r_sig);
67 
68  using Dispatch::call;
69 
70  // AS DispatchI
71 virtual bool call(const String &a_name, Array<Instance>& a_argv);
72 
73  private:
74  Result compile(void);
75 
76  lua_State *m_pLuaState;
77  String m_preload;
78  String m_chunk;
79  String m_source;
80  sp<LuaContext> m_spContext;
81  String m_name;
82 #if FE_COUNTED_TRACK
83  Array<void*> m_trackArray;
84 #endif
85 };
86 
87 } /* namespace ext */
88 } /* namespace fe */
89 
90 
91 #endif /* __lua_LuaHandler_h__ */
92 
kernel
Definition: namespace.dox:3
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
Interface to handle signals from an SignalerI.
Definition: HandlerI.h:22
Automatically reference-counted string container.
Definition: String.h:128
lua execution interface
Definition: LuaI.h:16
Wrapper for std::vector.
Definition: Array.h:21
Result
Generalized return value indicating success or failure, and why.
Definition: Result.h:24
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
lua execution component.
Definition: LuaHandler.h:24
virtual bool call(const String &a_name, Array< Instance > &a_argv)
Execute the call.
Definition: LuaHandler.cc:453