Skip to content

Commit fa15f37

Browse files
committed
Fix ColShape:getSize vector return for non-OOP functions
1 parent 85efb9a commit fa15f37

File tree

4 files changed

+84
-6
lines changed

4 files changed

+84
-6
lines changed

Client/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void CLuaColShapeDefs::AddClass(lua_State* luaVM)
5757

5858
lua_classfunction(luaVM, "getRadius", GetColShapeRadius);
5959
lua_classfunction(luaVM, "setRadius", SetColShapeRadius);
60-
lua_classfunction(luaVM, "getSize", GetColShapeSize);
60+
lua_classfunction(luaVM, "getSize", OOP_GetColShapeSize);
6161
lua_classfunction(luaVM, "setSize", SetColShapeSize);
6262
lua_classfunction(luaVM, "getPoints", GetColPolygonPoints);
6363
lua_classfunction(luaVM, "getPointPosition", GetColPolygonPointPosition);
@@ -69,7 +69,7 @@ void CLuaColShapeDefs::AddClass(lua_State* luaVM)
6969
lua_classvariable(luaVM, "shapeType", nullptr, "getColShapeType");
7070

7171
lua_classvariable(luaVM, "radius", SetColShapeRadius, GetColShapeRadius);
72-
lua_classvariable(luaVM, "size", SetColShapeSize, GetColShapeSize);
72+
lua_classvariable(luaVM, "size", SetColShapeSize, OOP_GetColShapeSize);
7373
lua_classvariable(luaVM, "points", nullptr, GetColPolygonPoints);
7474

7575
lua_registerclass(luaVM, "ColShape", "Element");
@@ -455,6 +455,45 @@ int CLuaColShapeDefs::GetColShapeSize(lua_State* luaVM)
455455
CScriptArgReader argStream(luaVM);
456456
argStream.ReadUserData(pColShape);
457457

458+
if (argStream.HasErrors())
459+
return luaL_error(luaVM, argStream.GetFullErrorMessage());
460+
461+
switch (pColShape->GetShapeType())
462+
{
463+
case COLSHAPE_RECTANGLE:
464+
{
465+
CVector2D size = static_cast<CClientColRectangle*>(pColShape)->GetSize();
466+
lua_pushnumber(luaVM, size.fX);
467+
lua_pushnumber(luaVM, size.fY);
468+
return 2;
469+
}
470+
case COLSHAPE_CUBOID:
471+
{
472+
CVector size = static_cast<CClientColCuboid*>(pColShape)->GetSize();
473+
lua_pushnumber(luaVM, size.fX);
474+
lua_pushnumber(luaVM, size.fY);
475+
lua_pushnumber(luaVM, size.fZ);
476+
return 3;
477+
}
478+
case COLSHAPE_TUBE:
479+
{
480+
float fHeight = static_cast<CClientColTube*>(pColShape)->GetHeight();
481+
lua_pushnumber(luaVM, fHeight);
482+
return 1;
483+
}
484+
}
485+
486+
argStream.SetCustomError("ColShape must be Rectangle, Cuboid or Tube");
487+
return luaL_error(luaVM, argStream.GetFullErrorMessage());
488+
}
489+
490+
int CLuaColShapeDefs::OOP_GetColShapeSize(lua_State* luaVM)
491+
{
492+
CClientColShape* pColShape;
493+
494+
CScriptArgReader argStream(luaVM);
495+
argStream.ReadUserData(pColShape);
496+
458497
if (argStream.HasErrors())
459498
return luaL_error(luaVM, argStream.GetFullErrorMessage());
460499

Client/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CLuaColShapeDefs : public CLuaDefs
2727

2828
LUA_DECLARE(GetColShapeRadius);
2929
LUA_DECLARE(SetColShapeRadius);
30-
LUA_DECLARE(GetColShapeSize);
30+
LUA_DECLARE_OOP(GetColShapeSize);
3131
LUA_DECLARE(SetColShapeSize);
3232
LUA_DECLARE(GetColPolygonPoints);
3333
LUA_DECLARE(GetColPolygonPointPosition);

Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void CLuaColShapeDefs::AddClass(lua_State* luaVM)
5757

5858
lua_classfunction(luaVM, "getRadius", "getColShapeRadius", GetColShapeRadius);
5959
lua_classfunction(luaVM, "setRadius", "setColShapeRadius", SetColShapeRadius);
60-
lua_classfunction(luaVM, "getSize", "getColShapeSize", GetColShapeSize);
60+
lua_classfunction(luaVM, "getSize", "getColShapeSize", OOP_GetColShapeSize);
6161
lua_classfunction(luaVM, "setSize", "setColShapeSize", SetColShapeSize);
6262
lua_classfunction(luaVM, "getPoints", "getColPolygonPoints", GetColPolygonPoints);
6363
lua_classfunction(luaVM, "getPointPosition", "getColPolygonPointPosition", GetColPolygonPointPosition);
@@ -68,7 +68,7 @@ void CLuaColShapeDefs::AddClass(lua_State* luaVM)
6868
lua_classvariable(luaVM, "shapeType", nullptr, "getColShapeType");
6969

7070
lua_classvariable(luaVM, "radius", "setColShapeRadius", "getColShapeRadius", SetColShapeRadius, GetColShapeRadius);
71-
lua_classvariable(luaVM, "size", "setColShapeSize", "getColShapeSize", SetColShapeSize, GetColShapeSize);
71+
lua_classvariable(luaVM, "size", "setColShapeSize", "getColShapeSize", SetColShapeSize, OOP_GetColShapeSize);
7272
lua_classvariable(luaVM, "points", nullptr, "getColPolygonPoints", nullptr, GetColPolygonPoints);
7373

7474
lua_registerclass(luaVM, "ColShape", "Element");
@@ -436,6 +436,45 @@ int CLuaColShapeDefs::GetColShapeSize(lua_State* luaVM)
436436
CScriptArgReader argStream(luaVM);
437437
argStream.ReadUserData(pColShape);
438438

439+
if (argStream.HasErrors())
440+
return luaL_error(luaVM, argStream.GetFullErrorMessage());
441+
442+
switch (pColShape->GetShapeType())
443+
{
444+
case COLSHAPE_RECTANGLE:
445+
{
446+
CVector2D size = static_cast<CColRectangle*>(pColShape)->GetSize();
447+
lua_pushnumber(luaVM, size.fX);
448+
lua_pushnumber(luaVM, size.fY);
449+
return 2;
450+
}
451+
case COLSHAPE_CUBOID:
452+
{
453+
CVector size = static_cast<CColCuboid*>(pColShape)->GetSize();
454+
lua_pushnumber(luaVM, size.fX);
455+
lua_pushnumber(luaVM, size.fY);
456+
lua_pushnumber(luaVM, size.fZ);
457+
return 3;
458+
}
459+
case COLSHAPE_TUBE:
460+
{
461+
float fHeight = static_cast<CColTube*>(pColShape)->GetHeight();
462+
lua_pushnumber(luaVM, fHeight);
463+
return 1;
464+
}
465+
}
466+
467+
argStream.SetCustomError("ColShape must be Rectangle, Cuboid or Tube");
468+
return luaL_error(luaVM, argStream.GetFullErrorMessage());
469+
}
470+
471+
int CLuaColShapeDefs::OOP_GetColShapeSize(lua_State* luaVM)
472+
{
473+
CColShape* pColShape;
474+
475+
CScriptArgReader argStream(luaVM);
476+
argStream.ReadUserData(pColShape);
477+
439478
if (argStream.HasErrors())
440479
return luaL_error(luaVM, argStream.GetFullErrorMessage());
441480

Server/mods/deathmatch/logic/luadefs/CLuaColShapeDefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CLuaColShapeDefs : public CLuaDefs
2828

2929
LUA_DECLARE(GetColShapeRadius);
3030
LUA_DECLARE(SetColShapeRadius);
31-
LUA_DECLARE(GetColShapeSize);
31+
LUA_DECLARE_OOP(GetColShapeSize);
3232
LUA_DECLARE(SetColShapeSize);
3333
LUA_DECLARE(GetColPolygonPoints);
3434
LUA_DECLARE(GetColPolygonPointPosition);

0 commit comments

Comments
 (0)