@@ -59,8 +59,8 @@ void CLuaColShapeDefs::AddClass(lua_State* luaVM)
59
59
lua_classfunction (luaVM, " setRadius" , " setColShapeRadius" , SetColShapeRadius);
60
60
lua_classfunction (luaVM, " getSize" , " getColShapeSize" , OOP_GetColShapeSize);
61
61
lua_classfunction (luaVM, " setSize" , " setColShapeSize" , SetColShapeSize);
62
- lua_classfunction (luaVM, " getPoints" , " getColPolygonPoints" , GetColPolygonPoints );
63
- lua_classfunction (luaVM, " getPointPosition" , " getColPolygonPointPosition" , GetColPolygonPointPosition );
62
+ lua_classfunction (luaVM, " getPoints" , " getColPolygonPoints" , OOP_GetColPolygonPoints );
63
+ lua_classfunction (luaVM, " getPointPosition" , " getColPolygonPointPosition" , OOP_GetColPolygonPointPosition );
64
64
lua_classfunction (luaVM, " setPointPosition" , " setColPolygonPointPosition" , SetColPolygonPointPosition);
65
65
lua_classfunction (luaVM, " addPoint" , " addColPolygonPoint" , AddColPolygonPoint);
66
66
lua_classfunction (luaVM, " removePoint" , " removeColPolygonPoint" , RemoveColPolygonPoint);
@@ -69,7 +69,7 @@ void CLuaColShapeDefs::AddClass(lua_State* luaVM)
69
69
70
70
lua_classvariable (luaVM, " radius" , " setColShapeRadius" , " getColShapeRadius" , SetColShapeRadius, GetColShapeRadius);
71
71
lua_classvariable (luaVM, " size" , " setColShapeSize" , " getColShapeSize" , SetColShapeSize, OOP_GetColShapeSize);
72
- lua_classvariable (luaVM, " points" , nullptr , " getColPolygonPoints" , nullptr , GetColPolygonPoints );
72
+ lua_classvariable (luaVM, " points" , nullptr , " getColPolygonPoints" , nullptr , OOP_GetColPolygonPoints );
73
73
74
74
lua_registerclass (luaVM, " ColShape" , " Element" );
75
75
}
@@ -559,6 +559,46 @@ int CLuaColShapeDefs::GetColPolygonPoints(lua_State* luaVM)
559
559
CScriptArgReader argStream (luaVM);
560
560
argStream.ReadUserData (pColShape);
561
561
562
+ if (argStream.HasErrors ())
563
+ return luaL_error (luaVM, argStream.GetFullErrorMessage ());
564
+
565
+ if (pColShape->GetShapeType () == COLSHAPE_POLYGON)
566
+ {
567
+ CColPolygon* pColPolygon = static_cast <CColPolygon*>(pColShape);
568
+
569
+ lua_newtable (luaVM);
570
+
571
+ uint uiIndex = 0 ;
572
+ for (auto iter = pColPolygon->IterBegin (); iter != pColPolygon->IterEnd (); ++iter)
573
+ {
574
+ CVector2D vecPoint = *iter;
575
+ lua_pushnumber (luaVM, ++uiIndex);
576
+ lua_newtable (luaVM);
577
+ {
578
+ lua_pushnumber (luaVM, 1 );
579
+ lua_pushnumber (luaVM, vecPoint.fX );
580
+ lua_settable (luaVM, -3 );
581
+
582
+ lua_pushnumber (luaVM, 2 );
583
+ lua_pushnumber (luaVM, vecPoint.fY );
584
+ lua_settable (luaVM, -3 );
585
+ }
586
+ lua_settable (luaVM, -3 );
587
+ }
588
+ return 1 ;
589
+ }
590
+
591
+ argStream.SetCustomError (" ColShape must be Polygon" );
592
+ return luaL_error (luaVM, argStream.GetFullErrorMessage ());
593
+ }
594
+
595
+ int CLuaColShapeDefs::OOP_GetColPolygonPoints (lua_State* luaVM)
596
+ {
597
+ CColShape* pColShape;
598
+
599
+ CScriptArgReader argStream (luaVM);
600
+ argStream.ReadUserData (pColShape);
601
+
562
602
if (argStream.HasErrors ())
563
603
return luaL_error (luaVM, argStream.GetFullErrorMessage ());
564
604
@@ -599,6 +639,38 @@ int CLuaColShapeDefs::GetColPolygonPointPosition(lua_State* luaVM)
599
639
CColPolygon* pColPolygon = static_cast <CColPolygon*>(pColShape);
600
640
CVector2D vecPoint;
601
641
if (uiPointIndex > 0 && CStaticFunctionDefinitions::GetColPolygonPointPosition (pColPolygon, uiPointIndex - 1 , vecPoint))
642
+ {
643
+ lua_pushnumber (luaVM, vecPoint.fX );
644
+ lua_pushnumber (luaVM, vecPoint.fY );
645
+ return 2 ;
646
+ }
647
+
648
+ m_pScriptDebugging->LogWarning (luaVM, " Invalid point index" );
649
+ lua_pushboolean (luaVM, false );
650
+ return 1 ;
651
+ }
652
+
653
+ argStream.SetCustomError (" ColShape must be Polygon" );
654
+ return luaL_error (luaVM, argStream.GetFullErrorMessage ());
655
+ }
656
+
657
+ int CLuaColShapeDefs::OOP_GetColPolygonPointPosition (lua_State* luaVM)
658
+ {
659
+ CColShape* pColShape;
660
+ uint uiPointIndex;
661
+
662
+ CScriptArgReader argStream (luaVM);
663
+ argStream.ReadUserData (pColShape);
664
+ argStream.ReadNumber (uiPointIndex);
665
+
666
+ if (argStream.HasErrors ())
667
+ return luaL_error (luaVM, argStream.GetFullErrorMessage ());
668
+
669
+ if (pColShape->GetShapeType () == COLSHAPE_POLYGON)
670
+ {
671
+ CColPolygon* pColPolygon = static_cast <CColPolygon*>(pColShape);
672
+ CVector2D vecPoint;
673
+ if (uiPointIndex > 0 && CStaticFunctionDefinitions::GetColPolygonPointPosition (pColPolygon, uiPointIndex - 1 , vecPoint))
602
674
{
603
675
lua_pushvector (luaVM, vecPoint);
604
676
}
0 commit comments