9 #include <argos3/core/utility/math/vector2.h>
10 #include <argos3/core/utility/math/angles.h>
11 #include <argos3/core/wrappers/lua/lua_utility.h>
18 const std::string CLuaVector2::m_strTypeId(
"argos3.vector2");
25 lua_pushcfunction(pt_state,
Create);
26 lua_setglobal(pt_state,
"vector2");
28 luaL_newmetatable(pt_state, m_strTypeId.c_str());
50 switch(lua_gettop(pt_state)) {
61 if(lua_isnumber(pt_state, 1) &&
62 lua_isnumber(pt_state, 2)) {
64 lua_tonumber(pt_state, 1),
65 lua_tonumber(pt_state, 2));
68 lua_pushstring(pt_state,
"invalid arguments to vector2");
73 lua_pushstring(pt_state,
"invalid arguments to vector2");
87 luaL_checkudata(pt_state, n_index, m_strTypeId.c_str());
89 if(pvUserdatum ==
nullptr) {
90 lua_pushstring(pt_state,
"vector2 not found at requested index");
102 if(lua_isuserdata(pt_state, 1) &&
103 lua_isstring(pt_state, 2)) {
105 const char* pchKey = lua_tolstring(pt_state, 2, &unLength);
110 lua_pushnumber(pt_state, cVector.
GetX());
113 lua_pushnumber(pt_state, cVector.
GetY());
116 lua_pushstring(pt_state,
"invalid key for vector2");
122 luaL_getmetatable(pt_state, m_strTypeId.c_str());
123 lua_pushvalue(pt_state, 2);
124 lua_gettable(pt_state, -2);
128 lua_pushstring(pt_state,
"invalid operation on vector2");
137 if(lua_isuserdata(pt_state, 1) &&
138 lua_isstring(pt_state, 2) &&
139 lua_isnumber(pt_state, 3)) {
141 const char* pchKey = lua_tolstring(pt_state, 2, &unLength);
146 cVector.
SetX(lua_tonumber(pt_state, 3));
149 cVector.
SetY(lua_tonumber(pt_state, 3));
152 lua_pushstring(pt_state,
"invalid key for vector2");
158 lua_pushstring(pt_state,
"invalid operation on vector2");
170 lua_pushboolean(pt_state, bEqual);
189 if(lua_isuserdata(pt_state, 1) && lua_isnumber(pt_state, 2)) {
191 PushVector2(pt_state, cVector * lua_tonumber(pt_state, 2));
193 else if(lua_isuserdata(pt_state, 2) && lua_isnumber(pt_state, 1)) {
195 PushVector2(pt_state, cVector * lua_tonumber(pt_state, 1));
198 lua_pushstring(pt_state,
"invalid arguments for multiplication by scalar");
248 lua_pop(pt_state, 1);
261 lua_pushnumber(pt_state, fDotProduct);
269 if(lua_isuserdata(pt_state, 1) && lua_isnumber(pt_state, 2)) {
272 CRadians cAngle(lua_tonumber(pt_state, 2));
277 lua_pop(pt_state, 1);
280 lua_pushstring(pt_state,
"invalid arguments to rotate");
295 std::ostringstream ossOutput;
296 ossOutput << cVector;
298 lua_pushstring(pt_state, ossOutput.str().c_str());
float Real
Collects all ARGoS code.
The namespace containing all the ARGoS related code.
It defines the basic type CRadians, used to store an angle value in radians.
Real DotProduct(const CVector2 &c_vector2) const
Returns the dot product between this vector and the passed one.
Real GetY() const
Returns the y coordinate of this vector.
Real CrossProduct(const CVector2 &c_vector2) const
Returns the cross product between this vector and the passed one.
CVector2 & Rotate(const CRadians &c_angle)
Rotates this vector by the wanted angle.
CVector2 & Normalize()
Normalizes this vector.
void SetY(Real f_y)
Sets the y coordinate of this vector.
void SetX(Real f_x)
Sets the x coordinate of this vector.
Real GetX() const
Returns the x coordinate of this vector.
static void AddToTable(lua_State *pt_state, const std::string &str_key, void *pt_data)
Adds a pointer to a chunk of data with the given string key to the table located at the top of the st...
static int Multiply(lua_State *pt_state)
static int Add(lua_State *pt_state)
static int CrossProduct(lua_State *pt_state)
static int UnaryMinus(lua_State *pt_state)
static int Length(lua_State *pt_state)
static int NewIndex(lua_State *pt_state)
static void RegisterType(lua_State *pt_state)
static int Rotate(lua_State *pt_state)
static int DotProduct(lua_State *pt_state)
static int Index(lua_State *pt_state)
static CVector2 & ToVector2(lua_State *pt_state, int n_index)
static int Equal(lua_State *pt_state)
static void PushVector2(lua_State *pt_state, TArguments &&... t_arguments)
static int ToString(lua_State *pt_state)
static int Subtract(lua_State *pt_state)
static int Normalize(lua_State *pt_state)
static int Create(lua_State *pt_state)