Skip to content

Commit

Permalink
Fixed Lua bindings for const objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
madmaxoft authored and Seadragon91 committed May 9, 2017
1 parent 17ba5be commit 3d5ee3e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 102 deletions.
96 changes: 4 additions & 92 deletions src/Bindings/LuaState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,28 +864,6 @@ void cLuaState::Push(const AStringVector & a_Vector)



void cLuaState::Push(const cCraftingGrid * a_Grid)
{
ASSERT(IsValid());

tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<cCraftingGrid *>(a_Grid)), "cCraftingGrid");
}





void cLuaState::Push(const cCraftingRecipe * a_Recipe)
{
ASSERT(IsValid());

tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<cCraftingRecipe *>(a_Recipe)), "cCraftingRecipe");
}





void cLuaState::Push(const char * a_Value)
{
ASSERT(IsValid());
Expand All @@ -897,17 +875,6 @@ void cLuaState::Push(const char * a_Value)



void cLuaState::Push(const cItems & a_Items)
{
ASSERT(IsValid());

tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<cItems *>(&a_Items)), "cItems");
}





void cLuaState::Push(const cNil & a_Nil)
{
ASSERT(IsValid());
Expand All @@ -919,17 +886,6 @@ void cLuaState::Push(const cNil & a_Nil)



void cLuaState::Push(const cPlayer * a_Player)
{
ASSERT(IsValid());

tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<cPlayer *>(a_Player)), "cPlayer");
}





void cLuaState::Push(const cLuaState::cRef & a_Ref)
{
ASSERT(IsValid());
Expand All @@ -941,44 +897,11 @@ void cLuaState::Push(const cLuaState::cRef & a_Ref)



void cLuaState::Push(const HTTPRequest * a_Request)
{
ASSERT(IsValid());

tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<HTTPRequest *>(a_Request)), "HTTPRequest");
}





void cLuaState::Push(const HTTPTemplateRequest * a_Request)
{
ASSERT(IsValid());

tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<HTTPTemplateRequest *>(a_Request)), "HTTPTemplateRequest");
}





void cLuaState::Push(const Vector3d & a_Vector)
{
ASSERT(IsValid());

tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<Vector3d *>(&a_Vector)), "Vector3<double>");
}





void cLuaState::Push(const Vector3d * a_Vector)
{
ASSERT(IsValid());

tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<Vector3d *>(a_Vector)), "Vector3<double>");
auto c = new Vector3d(a_Vector);
tolua_pushusertype_and_takeownership(m_LuaState, c, "Vector3<double>");
}


Expand All @@ -988,19 +911,8 @@ void cLuaState::Push(const Vector3d * a_Vector)
void cLuaState::Push(const Vector3i & a_Vector)
{
ASSERT(IsValid());

tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<Vector3i *>(&a_Vector)), "Vector3<int>");
}





void cLuaState::Push(const Vector3i * a_Vector)
{
ASSERT(IsValid());

tolua_pushusertype(m_LuaState, reinterpret_cast<void *>(const_cast<Vector3i *>(a_Vector)), "Vector3<int>");
auto c = new Vector3i(a_Vector);
tolua_pushusertype_and_takeownership(m_LuaState, c, "Vector3<int>");
}


Expand Down
10 changes: 2 additions & 8 deletions src/Bindings/LuaState.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,22 +573,16 @@ class cLuaState
}

// Push a const value onto the stack (keep alpha-sorted):
// Note that these functions will make a copy of the actual value, because Lua doesn't have the concept
// of "const", and there would be lifetime management problems if they didn't.
void Push(const AString & a_String);
void Push(const AStringMap & a_Dictionary);
void Push(const AStringVector & a_Vector);
void Push(const cCraftingGrid * a_Grid);
void Push(const cCraftingRecipe * a_Recipe);
void Push(const char * a_Value);
void Push(const cItems & a_Items);
void Push(const cNil & a_Nil);
void Push(const cPlayer * a_Player);
void Push(const cRef & a_Ref);
void Push(const HTTPRequest * a_Request);
void Push(const HTTPTemplateRequest * a_Request);
void Push(const Vector3d & a_Vector);
void Push(const Vector3d * a_Vector);
void Push(const Vector3i & a_Vector);
void Push(const Vector3i * a_Vector);

// Push a simple value onto the stack (keep alpha-sorted):
void Push(bool a_Value);
Expand Down
2 changes: 1 addition & 1 deletion src/Bindings/ManualBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ class cWebTabCallback:
) override
{
AString content, contentType;
return m_Callback.Call(&a_Request, a_UrlPath, cLuaState::Return, a_Content, a_ContentType);
return m_Callback.Call(const_cast<HTTPRequest *>(&a_Request), a_UrlPath, cLuaState::Return, a_Content, a_ContentType);
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/Bindings/PluginLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ bool cPluginLua::OnPlayerFoodLevelChange(cPlayer & a_Player, int a_NewFoodLevel)

bool cPluginLua::OnPlayerFished(cPlayer & a_Player, const cItems & a_Reward)
{
return CallSimpleHooks(cPluginManager::HOOK_PLAYER_FISHED, &a_Player, a_Reward);
cItems reward(a_Reward);
return CallSimpleHooks(cPluginManager::HOOK_PLAYER_FISHED, &a_Player, &reward);
}


Expand Down

0 comments on commit 3d5ee3e

Please sign in to comment.