lua_vector3.h
Go to the documentation of this file.
1 #ifndef LUA_VECTOR3_H
2 #define LUA_VECTOR3_H
3 
10 extern "C" {
11 #include <lua.h>
12 #include <lualib.h>
13 #include <lauxlib.h>
14 }
15 
16 #include <argos3/core/utility/datatypes/datatypes.h>
17 #include <argos3/core/utility/math/vector3.h>
18 
19 #include <string>
20 #include <utility>
21 
22 namespace argos {
23 
24  class CLuaVector3 {
25 
26  public:
27 
28  static void RegisterType(lua_State* pt_state);
29 
30  static const std::string& GetTypeId() {
31  return m_strTypeId;
32  }
33 
34  static int Create(lua_State* pt_state);
35 
36  template<class... TArguments>
37  static void PushVector3(lua_State* pt_state, TArguments&&... t_arguments) {
38  /* allocate memory for a CVector3 */
39  void* pvUserdatum =
40  lua_newuserdata(pt_state, sizeof(CVector3));
41  /* run the constructor on the allocated memory */
42  new (pvUserdatum) CVector3(std::forward<TArguments>(t_arguments)...);
43  /* set the metatable for the userdatum */
44  luaL_getmetatable(pt_state, m_strTypeId.c_str());
45  lua_setmetatable(pt_state, -2);
46  }
47 
48  static CVector3& ToVector3(lua_State* pt_state, int n_index);
49 
50  static int Index(lua_State* pt_state);
51 
52  static int NewIndex(lua_State* pt_state);
53 
54  static int ToString(lua_State* pt_state);
55 
56  static int Equal(lua_State* pt_state);
57 
58  static int Add(lua_State* pt_state);
59 
60  static int Multiply(lua_State* pt_state);
61 
62  static int Subtract(lua_State* pt_state);
63 
64  static int UnaryMinus(lua_State* pt_state);
65 
66  static int Normalize(lua_State* pt_state);
67 
68  static int Length(lua_State* pt_state);
69 
70  static int DotProduct(lua_State* pt_state);
71 
72  static int CrossProduct(lua_State* pt_state);
73 
74  static int Rotate(lua_State* pt_state);
75 
76  private:
77 
78  static const std::string m_strTypeId;
79 
80  };
81 
82 }
83 
84 #endif
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
A 3D vector class.
Definition: vector3.h:31
static int ToString(lua_State *pt_state)
static int Create(lua_State *pt_state)
Definition: lua_vector3.cpp:50
static int Multiply(lua_State *pt_state)
static int Normalize(lua_State *pt_state)
static void PushVector3(lua_State *pt_state, TArguments &&... t_arguments)
Definition: lua_vector3.h:37
static int DotProduct(lua_State *pt_state)
static void RegisterType(lua_State *pt_state)
Definition: lua_vector3.cpp:25
static int Equal(lua_State *pt_state)
static int UnaryMinus(lua_State *pt_state)
static int CrossProduct(lua_State *pt_state)
static CVector3 & ToVector3(lua_State *pt_state, int n_index)
Definition: lua_vector3.cpp:87
static int NewIndex(lua_State *pt_state)
static int Subtract(lua_State *pt_state)
static int Length(lua_State *pt_state)
static int Add(lua_State *pt_state)
static int Index(lua_State *pt_state)
static int Rotate(lua_State *pt_state)
static const std::string & GetTypeId()
Definition: lua_vector3.h:30