Skip to content

Commit 7e6df07

Browse files
committed
Clean up client Vector/Matrix luadefs
(cherry picked from commit f87acdb)
1 parent 53ca72b commit 7e6df07

File tree

10 files changed

+186
-199
lines changed

10 files changed

+186
-199
lines changed

MTA10/mods/shared_logic/lua/CLuaMain.cpp

Lines changed: 4 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,184 +1658,14 @@ void CLuaMain::AddBrowserClass ( lua_State* luaVM )
16581658
}
16591659

16601660

1661-
void CLuaMain::AddVector4DClass ( lua_State* luaVM )
1662-
{
1663-
lua_newclass ( luaVM );
1664-
1665-
lua_classmetamethod ( luaVM, "__tostring", CLuaVector4Defs::ToString );
1666-
lua_classmetamethod ( luaVM, "__gc", CLuaVector4Defs::Destroy );
1667-
1668-
lua_classmetamethod ( luaVM, "__add", CLuaVector4Defs::Add );
1669-
lua_classmetamethod ( luaVM, "__sub", CLuaVector4Defs::Sub );
1670-
lua_classmetamethod ( luaVM, "__mul", CLuaVector4Defs::Mul );
1671-
lua_classmetamethod ( luaVM, "__div", CLuaVector4Defs::Div );
1672-
lua_classmetamethod ( luaVM, "__pow", CLuaVector4Defs::Pow );
1673-
lua_classmetamethod ( luaVM, "__unm", CLuaVector4Defs::Unm );
1674-
lua_classmetamethod ( luaVM, "__eq", CLuaVector4Defs::Eq );
1675-
lua_classmetamethod ( luaVM, "__len", CLuaVector4Defs::GetLength );
1676-
1677-
lua_classfunction ( luaVM, "create", CLuaVector4Defs::Create );
1678-
lua_classfunction ( luaVM, "normalize", CLuaVector4Defs::Normalize );
1679-
lua_classfunction ( luaVM, "dot", CLuaVector4Defs::Dot );
1680-
1681-
lua_classfunction ( luaVM, "getLength", CLuaVector4Defs::GetLength );
1682-
lua_classfunction ( luaVM, "getSquaredLength", CLuaVector4Defs::GetLengthSquared );
1683-
lua_classfunction ( luaVM, "getNormalized", CLuaVector4Defs::GetNormalized );
1684-
lua_classfunction ( luaVM, "getX", CLuaVector4Defs::GetX );
1685-
lua_classfunction ( luaVM, "getY", CLuaVector4Defs::GetY );
1686-
lua_classfunction ( luaVM, "getZ", CLuaVector4Defs::GetZ );
1687-
lua_classfunction ( luaVM, "getW", CLuaVector4Defs::GetW );
1688-
1689-
lua_classfunction ( luaVM, "setX", CLuaVector4Defs::SetX );
1690-
lua_classfunction ( luaVM, "setY", CLuaVector4Defs::SetY );
1691-
lua_classfunction ( luaVM, "setZ", CLuaVector4Defs::SetZ );
1692-
lua_classfunction ( luaVM, "setW", CLuaVector4Defs::SetW );
1693-
1694-
lua_classvariable ( luaVM, "x", CLuaVector4Defs::SetX, CLuaVector4Defs::GetX );
1695-
lua_classvariable ( luaVM, "y", CLuaVector4Defs::SetY, CLuaVector4Defs::GetY );
1696-
lua_classvariable ( luaVM, "z", CLuaVector4Defs::SetZ, CLuaVector4Defs::GetZ );
1697-
lua_classvariable ( luaVM, "w", CLuaVector4Defs::SetW, CLuaVector4Defs::GetW );
1698-
1699-
lua_classvariable ( luaVM, "length", NULL, CLuaVector4Defs::GetLength );
1700-
lua_classvariable ( luaVM, "squaredLength", NULL, CLuaVector4Defs::GetLengthSquared );
1701-
lua_classvariable ( luaVM, "normalized", NULL, CLuaVector4Defs::GetNormalized );
1702-
1703-
lua_registerclass ( luaVM, "Vector4" );
1704-
}
1705-
1706-
1707-
void CLuaMain::AddVector3DClass ( lua_State* luaVM )
1708-
{
1709-
lua_newclass ( luaVM );
1710-
1711-
lua_classmetamethod ( luaVM, "__tostring", CLuaVector3Defs::ToString );
1712-
lua_classmetamethod ( luaVM, "__gc", CLuaVector3Defs::Destroy );
1713-
1714-
lua_classmetamethod ( luaVM, "__add", CLuaVector3Defs::Add );
1715-
lua_classmetamethod ( luaVM, "__sub", CLuaVector3Defs::Sub );
1716-
lua_classmetamethod ( luaVM, "__mul", CLuaVector3Defs::Mul );
1717-
lua_classmetamethod ( luaVM, "__div", CLuaVector3Defs::Div );
1718-
lua_classmetamethod ( luaVM, "__pow", CLuaVector3Defs::Pow );
1719-
lua_classmetamethod ( luaVM, "__unm", CLuaVector3Defs::Unm );
1720-
lua_classmetamethod ( luaVM, "__eq", CLuaVector3Defs::Eq );
1721-
lua_classmetamethod ( luaVM, "__len", CLuaVector3Defs::GetLength );
1722-
1723-
lua_classfunction ( luaVM, "create", CLuaVector3Defs::Create );
1724-
lua_classfunction ( luaVM, "normalize", CLuaVector3Defs::Normalize );
1725-
lua_classfunction ( luaVM, "cross", CLuaVector3Defs::Cross );
1726-
lua_classfunction ( luaVM, "dot", CLuaVector3Defs::Dot );
1727-
1728-
lua_classfunction ( luaVM, "getLength", CLuaVector3Defs::GetLength );
1729-
lua_classfunction ( luaVM, "getSquaredLength", CLuaVector3Defs::GetLengthSquared );
1730-
lua_classfunction ( luaVM, "getNormalized", CLuaVector3Defs::GetNormalized );
1731-
lua_classfunction ( luaVM, "getX", CLuaVector3Defs::GetX );
1732-
lua_classfunction ( luaVM, "getY", CLuaVector3Defs::GetY );
1733-
lua_classfunction ( luaVM, "getZ", CLuaVector3Defs::GetZ );
1734-
1735-
lua_classfunction ( luaVM, "setX", CLuaVector3Defs::SetX );
1736-
lua_classfunction ( luaVM, "setY", CLuaVector3Defs::SetY );
1737-
lua_classfunction ( luaVM, "setZ", CLuaVector3Defs::SetZ );
1738-
1739-
lua_classvariable ( luaVM, "x", CLuaVector3Defs::SetX, CLuaVector3Defs::GetX );
1740-
lua_classvariable ( luaVM, "y", CLuaVector3Defs::SetY, CLuaVector3Defs::GetY );
1741-
lua_classvariable ( luaVM, "z", CLuaVector3Defs::SetZ, CLuaVector3Defs::GetZ );
1742-
lua_classvariable ( luaVM, "length", NULL, CLuaVector3Defs::GetLength );
1743-
lua_classvariable ( luaVM, "squaredLength", NULL, CLuaVector3Defs::GetLengthSquared );
1744-
lua_classvariable ( luaVM, "normalized", NULL, CLuaVector3Defs::GetNormalized );
1745-
1746-
lua_registerclass ( luaVM, "Vector3" );
1747-
}
1748-
1749-
1750-
void CLuaMain::AddVector2DClass ( lua_State* luaVM )
1751-
{
1752-
lua_newclass ( luaVM );
1753-
1754-
1755-
lua_classmetamethod ( luaVM, "__tostring", CLuaVector2Defs::ToString );
1756-
lua_classmetamethod ( luaVM, "__gc", CLuaVector2Defs::Destroy );
1757-
1758-
lua_classmetamethod ( luaVM, "__add", CLuaVector2Defs::Add );
1759-
lua_classmetamethod ( luaVM, "__sub", CLuaVector2Defs::Sub );
1760-
lua_classmetamethod ( luaVM, "__mul", CLuaVector2Defs::Mul );
1761-
lua_classmetamethod ( luaVM, "__div", CLuaVector2Defs::Div );
1762-
lua_classmetamethod ( luaVM, "__pow", CLuaVector2Defs::Pow );
1763-
lua_classmetamethod ( luaVM, "__unm", CLuaVector2Defs::Unm );
1764-
lua_classmetamethod ( luaVM, "__eq", CLuaVector2Defs::Eq );
1765-
lua_classmetamethod ( luaVM, "__len", CLuaVector2Defs::GetLength );
1766-
1767-
lua_classfunction ( luaVM, "create", CLuaVector2Defs::Create );
1768-
lua_classfunction ( luaVM, "normalize", CLuaVector2Defs::Normalize );
1769-
lua_classfunction ( luaVM, "dot", CLuaVector2Defs::Dot );
1770-
1771-
lua_classfunction ( luaVM, "getLength", CLuaVector2Defs::GetLength );
1772-
lua_classfunction ( luaVM, "getSquaredLength", CLuaVector2Defs::GetLengthSquared );
1773-
lua_classfunction ( luaVM, "getNormalized", CLuaVector2Defs::GetNormalized );
1774-
lua_classfunction ( luaVM, "getX", CLuaVector2Defs::GetX );
1775-
lua_classfunction ( luaVM, "getY", CLuaVector2Defs::GetY );
1776-
1777-
lua_classfunction ( luaVM, "setX", CLuaVector2Defs::SetX );
1778-
lua_classfunction ( luaVM, "setY", CLuaVector2Defs::SetY );
1779-
1780-
lua_classvariable ( luaVM, "x", CLuaVector2Defs::SetX, CLuaVector2Defs::GetX );
1781-
lua_classvariable ( luaVM, "y", CLuaVector2Defs::SetY, CLuaVector2Defs::GetY );
1782-
1783-
lua_classvariable ( luaVM, "length", NULL, CLuaVector2Defs::GetLength );
1784-
lua_classvariable ( luaVM, "squaredLength", NULL, CLuaVector2Defs::GetLengthSquared );
1785-
lua_classvariable ( luaVM, "normalized", NULL, CLuaVector2Defs::GetNormalized );
1786-
1787-
lua_registerclass ( luaVM, "Vector2" );
1788-
}
1789-
1790-
1791-
void CLuaMain::AddMatrixClass ( lua_State* luaVM )
1792-
{
1793-
lua_newclass ( luaVM );
1794-
1795-
lua_classmetamethod ( luaVM, "__tostring", CLuaMatrixDefs::ToString );
1796-
lua_classmetamethod ( luaVM, "__gc", CLuaMatrixDefs::Destroy );
1797-
1798-
lua_classmetamethod ( luaVM, "__add", CLuaMatrixDefs::Add );
1799-
lua_classmetamethod ( luaVM, "__sub", CLuaMatrixDefs::Sub );
1800-
lua_classmetamethod ( luaVM, "__mul", CLuaMatrixDefs::Mul );
1801-
lua_classmetamethod ( luaVM, "__div", CLuaMatrixDefs::Div );
1802-
1803-
lua_classfunction ( luaVM, "create", CLuaMatrixDefs::Create );
1804-
1805-
lua_classfunction ( luaVM, "transformPosition", CLuaMatrixDefs::TransformPosition );
1806-
lua_classfunction ( luaVM, "transformDirection", CLuaMatrixDefs::TransformDirection );
1807-
lua_classfunction ( luaVM, "inverse", CLuaMatrixDefs::Inverse );
1808-
1809-
lua_classfunction ( luaVM, "getPosition", CLuaMatrixDefs::GetPosition );
1810-
lua_classfunction ( luaVM, "getRotation", CLuaMatrixDefs::GetRotation );
1811-
lua_classfunction ( luaVM, "getForward", CLuaMatrixDefs::GetForward );
1812-
lua_classfunction ( luaVM, "getRight", CLuaMatrixDefs::GetRight );
1813-
lua_classfunction ( luaVM, "getUp", CLuaMatrixDefs::GetUp );
1814-
1815-
lua_classfunction ( luaVM, "setPosition", CLuaMatrixDefs::SetPosition );
1816-
lua_classfunction ( luaVM, "setRotation", CLuaMatrixDefs::SetRotation );
1817-
lua_classfunction ( luaVM, "setForward", CLuaMatrixDefs::SetForward );
1818-
lua_classfunction ( luaVM, "setRight", CLuaMatrixDefs::SetRight );
1819-
lua_classfunction ( luaVM, "setUp", CLuaMatrixDefs::SetUp );
1820-
1821-
lua_classvariable ( luaVM, "position", CLuaMatrixDefs::SetPosition, CLuaMatrixDefs::GetPosition );
1822-
lua_classvariable ( luaVM, "rotation", CLuaMatrixDefs::SetRotation, CLuaMatrixDefs::GetRotation );
1823-
lua_classvariable ( luaVM, "forward", CLuaMatrixDefs::SetForward, CLuaMatrixDefs::GetForward );
1824-
lua_classvariable ( luaVM, "right", CLuaMatrixDefs::SetRight, CLuaMatrixDefs::GetRight );
1825-
lua_classvariable ( luaVM, "up", CLuaMatrixDefs::SetUp, CLuaMatrixDefs::GetUp );
1826-
1827-
lua_registerclass ( luaVM, "Matrix" );
1828-
}
1829-
1830-
18311661
void CLuaMain::InitClasses ( lua_State* luaVM )
18321662
{
18331663
lua_initclasses ( luaVM );
18341664

1835-
AddVector4DClass ( luaVM );
1836-
AddVector3DClass ( luaVM );
1837-
AddVector2DClass ( luaVM );
1838-
AddMatrixClass ( luaVM );
1665+
CLuaVector4Defs::AddClass ( luaVM );
1666+
CLuaVector3Defs::AddClass ( luaVM );
1667+
CLuaVector2Defs::AddClass ( luaVM );
1668+
CLuaMatrixDefs::AddClass ( luaVM );
18391669

18401670
if ( !m_bEnableOOP )
18411671
return;

MTA10/mods/shared_logic/lua/CLuaMain.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,6 @@ class CLuaMain //: public CClient
124124

125125
void AddCameraClass ( lua_State* luaVM );
126126

127-
void AddVector4DClass ( lua_State* luaVM );
128-
void AddVector3DClass ( lua_State* luaVM );
129-
void AddVector2DClass ( lua_State* luaVM );
130-
void AddMatrixClass ( lua_State* luaVM );
131-
132127
void AddDxMaterialClass ( lua_State* luaVM );
133128
void AddDxTextureClass ( lua_State* luaVM );
134129
void AddDxFontClass ( lua_State* luaVM );

MTA10/mods/shared_logic/luadefs/CLuaMatrixDefs.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,46 @@
1212

1313
#include "StdInc.h"
1414

15+
void CLuaMatrixDefs::AddClass ( lua_State* luaVM )
16+
{
17+
lua_newclass ( luaVM );
18+
19+
lua_classmetamethod ( luaVM, "__tostring", ToString );
20+
lua_classmetamethod ( luaVM, "__gc", Destroy );
21+
22+
lua_classmetamethod ( luaVM, "__add", Add );
23+
lua_classmetamethod ( luaVM, "__sub", Sub );
24+
lua_classmetamethod ( luaVM, "__mul", Mul );
25+
lua_classmetamethod ( luaVM, "__div", Div );
26+
27+
lua_classfunction ( luaVM, "create", Create );
28+
29+
lua_classfunction ( luaVM, "transformPosition", TransformPosition );
30+
lua_classfunction ( luaVM, "transformDirection", TransformDirection );
31+
lua_classfunction ( luaVM, "inverse", Inverse );
32+
33+
lua_classfunction ( luaVM, "getPosition", GetPosition );
34+
lua_classfunction ( luaVM, "getRotation", GetRotation );
35+
lua_classfunction ( luaVM, "getForward", GetForward );
36+
lua_classfunction ( luaVM, "getRight", GetRight );
37+
lua_classfunction ( luaVM, "getUp", GetUp );
38+
39+
lua_classfunction ( luaVM, "setPosition", SetPosition );
40+
lua_classfunction ( luaVM, "setRotation", SetRotation );
41+
lua_classfunction ( luaVM, "setForward", SetForward );
42+
lua_classfunction ( luaVM, "setRight", SetRight );
43+
lua_classfunction ( luaVM, "setUp", SetUp );
44+
45+
lua_classvariable ( luaVM, "position", SetPosition, GetPosition );
46+
lua_classvariable ( luaVM, "rotation", SetRotation, GetRotation );
47+
lua_classvariable ( luaVM, "forward", SetForward, GetForward );
48+
lua_classvariable ( luaVM, "right", SetRight, GetRight );
49+
lua_classvariable ( luaVM, "up", SetUp, GetUp );
50+
51+
lua_registerclass ( luaVM, "Matrix" );
52+
}
53+
54+
1555
int CLuaMatrixDefs::Create ( lua_State* luaVM )
1656
{
1757
CMatrix matrix;

MTA10/mods/shared_logic/luadefs/CLuaMatrixDefs.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
*
1111
*****************************************************************************/
1212

13-
#ifndef __CLUAMATRIXDEFS_H
14-
#define __CLUAMATRIXDEFS_H
13+
#pragma once
1514

1615
extern "C"
1716
{
@@ -23,6 +22,7 @@ extern "C"
2322
class CLuaMatrixDefs: public CLuaDefs
2423
{
2524
public:
25+
static void AddClass ( lua_State* luaVM );
2626
LUA_DECLARE ( Create );
2727
LUA_DECLARE ( Destroy );
2828

@@ -48,6 +48,4 @@ class CLuaMatrixDefs: public CLuaDefs
4848
LUA_DECLARE ( Sub );
4949
LUA_DECLARE ( Mul );
5050
LUA_DECLARE ( Div );
51-
};
52-
53-
#endif
51+
};

MTA10/mods/shared_logic/luadefs/CLuaVector2Defs.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,47 @@
1212

1313
#include "StdInc.h"
1414

15+
void CLuaVector2Defs::AddClass ( lua_State* luaVM )
16+
{
17+
lua_newclass ( luaVM );
18+
19+
20+
lua_classmetamethod ( luaVM, "__tostring", ToString );
21+
lua_classmetamethod ( luaVM, "__gc", Destroy );
22+
23+
lua_classmetamethod ( luaVM, "__add", Add );
24+
lua_classmetamethod ( luaVM, "__sub", Sub );
25+
lua_classmetamethod ( luaVM, "__mul", Mul );
26+
lua_classmetamethod ( luaVM, "__div", Div );
27+
lua_classmetamethod ( luaVM, "__pow", Pow );
28+
lua_classmetamethod ( luaVM, "__unm", Unm );
29+
lua_classmetamethod ( luaVM, "__eq", Eq );
30+
lua_classmetamethod ( luaVM, "__len", GetLength );
31+
32+
lua_classfunction ( luaVM, "create", Create );
33+
lua_classfunction ( luaVM, "normalize", Normalize );
34+
lua_classfunction ( luaVM, "dot", Dot );
35+
36+
lua_classfunction ( luaVM, "getLength", GetLength );
37+
lua_classfunction ( luaVM, "getSquaredLength", GetLengthSquared );
38+
lua_classfunction ( luaVM, "getNormalized", GetNormalized );
39+
lua_classfunction ( luaVM, "getX", GetX );
40+
lua_classfunction ( luaVM, "getY", GetY );
41+
42+
lua_classfunction ( luaVM, "setX", SetX );
43+
lua_classfunction ( luaVM, "setY", SetY );
44+
45+
lua_classvariable ( luaVM, "x", SetX, GetX );
46+
lua_classvariable ( luaVM, "y", SetY, GetY );
47+
48+
lua_classvariable ( luaVM, "length", NULL, GetLength );
49+
lua_classvariable ( luaVM, "squaredLength", NULL, GetLengthSquared );
50+
lua_classvariable ( luaVM, "normalized", NULL, GetNormalized );
51+
52+
lua_registerclass ( luaVM, "Vector2" );
53+
}
54+
55+
1556
int CLuaVector2Defs::Create ( lua_State* luaVM )
1657
{
1758
CVector2D vector;

MTA10/mods/shared_logic/luadefs/CLuaVector2Defs.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
*
1111
*****************************************************************************/
1212

13-
#ifndef __LUAVECTORDEFS_H
14-
#define __LUAVECTORDEFS_H
13+
#pragma once
1514

1615
extern "C"
1716
{
@@ -23,6 +22,7 @@ extern "C"
2322
class CLuaVector2Defs : public CLuaDefs
2423
{
2524
public:
25+
static void AddClass ( lua_State* luaVM );
2626
LUA_DECLARE ( Create );
2727
LUA_DECLARE ( Destroy );
2828

@@ -47,6 +47,4 @@ class CLuaVector2Defs : public CLuaDefs
4747
LUA_DECLARE ( Pow );
4848
LUA_DECLARE ( Unm );
4949
LUA_DECLARE ( Eq );
50-
};
51-
52-
#endif
50+
};

0 commit comments

Comments
 (0)