1818#include < LuaBool.h>
1919#include < visualisationState.h>
2020#include < commandLine.h>
21+ #include < camera.h>
2122
2223/* *
2324 * @brief Store for lua global state.
@@ -28,6 +29,8 @@ struct LuaExtraSpace
2829{
2930 VisualisationState * visualisationState;
3031 CommandLine * options;
32+ Camera * camera;
33+ bool * exit;
3134};
3235
3336/* *
@@ -53,18 +56,60 @@ int dispatchVisualisationState(lua_State * lua)
5356}
5457
5558/* *
56- * @brief Toggle video recording.
59+ * @brief A Lua binding in Camera;
5760 *
61+ */
62+ typedef int (Camera::*CameraMember)(lua_State * lua);
63+
64+ /* *
65+ * @brief Dispath to a Lua binding of Camera.
66+ *
67+ * @see LuaExtraSpace.
68+ * @tparam function the Lua binding to dispatch.
5869 * @param lua the Lua context.
5970 * @return int the return code.
6071 */
61- int lua_toggleRecord (lua_State * lua)
72+ template <CameraMember function>
73+ int dispatchCamera (lua_State * lua)
74+ {
75+ LuaExtraSpace * store = *static_cast <LuaExtraSpace**>(lua_getextraspace (lua));
76+ Camera * ptr = store->camera ;
77+ return ((*ptr).*function)(lua);
78+ }
79+
80+ /* *
81+ * @brief Start video recording (if not already recording).
82+ *
83+ * @param lua the Lua context.
84+ * @return int the return code.
85+ */
86+ int lua_startRecord (lua_State * lua)
6287{
6388 LuaExtraSpace * extraSpace = *static_cast <LuaExtraSpace**>(lua_getextraspace (lua));
64- extraSpace->visualisationState ->toggleRecord (*extraSpace->options );
89+ if (!extraSpace->visualisationState ->recording )
90+ {
91+ extraSpace->visualisationState ->toggleRecord (*extraSpace->options );
92+ }
6593 return 0 ;
6694}
6795
96+ /* *
97+ * @brief Stop video recording (if already recording).
98+ *
99+ * @param lua the Lua context.
100+ * @return int the return code.
101+ */
102+ int lua_stopRecord (lua_State * lua)
103+ {
104+ LuaExtraSpace * extraSpace = *static_cast <LuaExtraSpace**>(lua_getextraspace (lua));
105+ if (extraSpace->visualisationState ->recording )
106+ {
107+ extraSpace->visualisationState ->toggleRecord (*extraSpace->options );
108+ }
109+ return 0 ;
110+ }
111+
112+
68113/* *
69114 * @brief Start playing frames.
70115 *
@@ -78,6 +123,19 @@ int lua_play(lua_State * lua)
78123 return 0 ;
79124}
80125
126+ /* *
127+ * @brief Exit SFOAV.
128+ *
129+ * @param lua the Lua context.
130+ * @return int the return code.
131+ */
132+ int lua_exit (lua_State * lua)
133+ {
134+ LuaExtraSpace * extraSpace = *static_cast <LuaExtraSpace**>(lua_getextraspace (lua));
135+ *(extraSpace->exit ) = true ;
136+ return 0 ;
137+ }
138+
81139/* *
82140 * @brief Stop playing frames.
83141 *
@@ -107,7 +165,8 @@ class Console
107165 (
108166 jLog::Log & l,
109167 VisualisationState * visualisationState,
110- CommandLine * options
168+ CommandLine * options,
169+ Camera * camera
111170 )
112171 : lastCommandOrProgram(" " ), lastStatus(false ), log(l)
113172 {
@@ -116,6 +175,8 @@ class Console
116175 luaL_requiref (lua," sfoav" ,load_sfoavLib,1 );
117176 extraSpace.visualisationState = visualisationState;
118177 extraSpace.options = options;
178+ extraSpace.camera = camera;
179+ extraSpace.exit = &exit;
119180 *static_cast <LuaExtraSpace**>(lua_getextraspace (lua)) = &extraSpace;
120181 }
121182
@@ -209,6 +270,14 @@ class Console
209270 return value;
210271 }
211272
273+ /* *
274+ * @brief If sfoav.exit() has been called.
275+ *
276+ * @return true exit has been requested in Lua.
277+ * @return false exit has not been requested in Lua.
278+ */
279+ bool exitCalled () const { return exit; }
280+
212281private:
213282
214283 lua_State * lua;
@@ -218,6 +287,7 @@ class Console
218287 std::stringstream input;
219288 static std::string stackTrace;
220289 bool lastStatus;
290+ bool exit = false ;
221291
222292 jLog::Log & log;
223293
@@ -250,7 +320,7 @@ class Console
250320
251321 static int load_sfoavLib (lua_State * lua)
252322 {
253- luaL_Reg sfoavLib[14 ] =
323+ luaL_Reg sfoavLib[21 ] =
254324 {
255325 {" setAtomColour" , &dispatchVisualisationState<&VisualisationState::lua_setAtomColour>},
256326 {" getAtomColour" , &dispatchVisualisationState<&VisualisationState::lua_getAtomColour>},
@@ -262,9 +332,16 @@ class Console
262332 {" getAtomsNeighbours" , &dispatchVisualisationState<&VisualisationState::lua_getAtomsNeighbours>},
263333 {" setText" , &dispatchVisualisationState<&VisualisationState::lua_setText>},
264334 {" getFrame" , &dispatchVisualisationState<&VisualisationState::lua_getFrame>},
265- {" toggleRecord" , &lua_toggleRecord},
335+ {" startRecording" , &lua_startRecord},
336+ {" stopRecording" , &lua_stopRecord},
266337 {" play" , &lua_play},
267338 {" pause" , &lua_pause},
339+ {" cameraPosition" , &dispatchCamera<&Camera::lua_cameraPosition>},
340+ {" setCameraPosition" , &dispatchCamera<&Camera::lua_setCameraPosition>},
341+ {" rotateCamera" , &dispatchCamera<&Camera::lua_rotateCamera>},
342+ {" zoomCamera" , &dispatchCamera<&Camera::lua_zoomCamera>},
343+ {" inclineCamera" , &dispatchCamera<&Camera::lua_inclineCamera>},
344+ {" exit" , &lua_exit},
268345 {NULL , NULL }
269346 };
270347
0 commit comments