1
0

Merge pull request #3476 from Seadragon91/patch-1

Export GetPosition and GetSpeed from cEntity as a copy instead of a pointer to lua.
This commit is contained in:
Mattes D 2016-12-11 21:22:09 +01:00 committed by GitHub
commit c59ff9b431
2 changed files with 52 additions and 2 deletions

View File

@ -3799,6 +3799,50 @@ static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S)
static int tolua_cEntity_GetPosition(lua_State * tolua_S)
{
cLuaState L(tolua_S);
// Get the params:
cEntity * self = reinterpret_cast<cEntity *>(tolua_tousertype(tolua_S, 1, nullptr));
if (self == nullptr)
{
LOGWARNING("%s: invalid self (%p)", __FUNCTION__, static_cast<void *>(self));
return 0;
}
L.Push(Mtolua_new((Vector3d)(self->GetPosition())));
tolua_register_gc(L, lua_gettop(L)); // Make Lua own the object
return 1;
}
static int tolua_cEntity_GetSpeed(lua_State * tolua_S)
{
cLuaState L(tolua_S);
// Get the params:
cEntity * self = reinterpret_cast<cEntity *>(tolua_tousertype(tolua_S, 1, nullptr));
if (self == nullptr)
{
LOGWARNING("%s: invalid self (%p)", __FUNCTION__, static_cast<void *>(self));
return 0;
}
L.Push(Mtolua_new((Vector3d)(self->GetSpeed())));
tolua_register_gc(L, lua_gettop(L)); // Make Lua own the object
return 1;
}
void cManualBindings::Bind(lua_State * tolua_S)
{
tolua_beginmodule(tolua_S, nullptr);
@ -3878,6 +3922,8 @@ void cManualBindings::Bind(lua_State * tolua_S)
tolua_beginmodule(tolua_S, "cEntity");
tolua_constant(tolua_S, "INVALID_ID", cEntity::INVALID_ID);
tolua_function(tolua_S, "GetPosition", tolua_cEntity_GetPosition);
tolua_function(tolua_S, "GetSpeed", tolua_cEntity_GetSpeed);
tolua_endmodule(tolua_S);
tolua_beginmodule(tolua_S, "cFile");

View File

@ -191,7 +191,6 @@ public:
double GetHeadYaw (void) const { return m_HeadYaw; } // In degrees
double GetHeight (void) const { return m_Height; }
double GetMass (void) const { return m_Mass; }
const Vector3d & GetPosition (void) const { return m_Position; }
double GetPosX (void) const { return m_Position.x; }
double GetPosY (void) const { return m_Position.y; }
double GetPosZ (void) const { return m_Position.z; }
@ -199,7 +198,6 @@ public:
double GetPitch (void) const { return m_Rot.y; } // In degrees, [-180, +180), but normal client clips to [-90, +90]
double GetRoll (void) const { return m_Rot.z; } // In degrees, unused in current client
Vector3d GetLookVector(void) const;
const Vector3d & GetSpeed (void) const { return m_Speed; }
double GetSpeedX (void) const { return m_Speed.x; }
double GetSpeedY (void) const { return m_Speed.y; }
double GetSpeedZ (void) const { return m_Speed.z; }
@ -292,6 +290,12 @@ public:
// tolua_end
/** Exported in ManualBindings */
const Vector3d & GetPosition(void) const { return m_Position; }
/** Exported in ManualBindings */
const Vector3d & GetSpeed(void) const { return m_Speed; }
/** Destroy the entity without scheduling memory freeing. This should only be used by cChunk or cClientHandle for internal memory management. */
void DestroyNoScheduling(bool a_ShouldBroadcast);