Skip to content

Commit

Permalink
[luadefs-server] Clean up Vectors, Matrix and File
Browse files Browse the repository at this point in the history
  • Loading branch information
qaisjp committed Sep 9, 2015
1 parent 16d64b7 commit fa46e04
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 273 deletions.
208 changes: 6 additions & 202 deletions MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.cpp
Expand Up @@ -164,173 +164,6 @@ void CLuaMain::InitSecurity ( void )
lua_register ( m_luaVM, "newproxy", CLuaFunctionDefs::DisabledFunction );
}

void CLuaMain::AddVector4DClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );

lua_classmetamethod ( luaVM, "__tostring", CLuaVector4Defs::ToString );
lua_classmetamethod ( luaVM, "__gc", CLuaVector4Defs::Destroy );

lua_classmetamethod ( luaVM, "__add", CLuaVector4Defs::Add );
lua_classmetamethod ( luaVM, "__sub", CLuaVector4Defs::Sub );
lua_classmetamethod ( luaVM, "__mul", CLuaVector4Defs::Mul );
lua_classmetamethod ( luaVM, "__div", CLuaVector4Defs::Div );
lua_classmetamethod ( luaVM, "__pow", CLuaVector4Defs::Pow );
lua_classmetamethod ( luaVM, "__unm", CLuaVector4Defs::Unm );
lua_classmetamethod ( luaVM, "__eq", CLuaVector4Defs::Eq );
lua_classmetamethod ( luaVM, "__len", CLuaVector4Defs::GetLength );

lua_classfunction ( luaVM, "create", "", CLuaVector4Defs::Create );
lua_classfunction ( luaVM, "normalize", "", CLuaVector4Defs::Normalize );
lua_classfunction ( luaVM, "dot", "", CLuaVector4Defs::Dot );

lua_classfunction ( luaVM, "getLength", "", CLuaVector4Defs::GetLength );
lua_classfunction ( luaVM, "getSquaredLength", "", CLuaVector4Defs::GetLengthSquared );
lua_classfunction ( luaVM, "getNormalized", "", CLuaVector4Defs::GetNormalized );
lua_classfunction ( luaVM, "getX", "", CLuaVector4Defs::GetX );
lua_classfunction ( luaVM, "getY", "", CLuaVector4Defs::GetY );
lua_classfunction ( luaVM, "getZ", "", CLuaVector4Defs::GetZ );
lua_classfunction ( luaVM, "getW", "", CLuaVector4Defs::GetW );

lua_classfunction ( luaVM, "setX", "", CLuaVector4Defs::SetX );
lua_classfunction ( luaVM, "setY", "", CLuaVector4Defs::SetY );
lua_classfunction ( luaVM, "setZ", "", CLuaVector4Defs::SetZ );
lua_classfunction ( luaVM, "setW", "", CLuaVector4Defs::SetW );

lua_classvariable ( luaVM, "x", "", "", CLuaVector4Defs::SetX, CLuaVector4Defs::GetX );
lua_classvariable ( luaVM, "y", "", "", CLuaVector4Defs::SetY, CLuaVector4Defs::GetY );
lua_classvariable ( luaVM, "z", "", "", CLuaVector4Defs::SetZ, CLuaVector4Defs::GetZ );
lua_classvariable ( luaVM, "w", "", "", CLuaVector4Defs::SetW, CLuaVector4Defs::GetW );

lua_classvariable ( luaVM, "length", "", "", NULL, CLuaVector4Defs::GetLength );
lua_classvariable ( luaVM, "squaredLength", "", "", NULL, CLuaVector4Defs::GetLengthSquared );
lua_classvariable ( luaVM, "normalized", "", "", NULL, CLuaVector4Defs::GetNormalized );

lua_registerclass ( luaVM, "Vector4" );
}


void CLuaMain::AddVector3DClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );

lua_classmetamethod ( luaVM, "__tostring", CLuaVector3Defs::ToString );
lua_classmetamethod ( luaVM, "__gc", CLuaVector3Defs::Destroy );

lua_classmetamethod ( luaVM, "__add", CLuaVector3Defs::Add );
lua_classmetamethod ( luaVM, "__sub", CLuaVector3Defs::Sub );
lua_classmetamethod ( luaVM, "__mul", CLuaVector3Defs::Mul );
lua_classmetamethod ( luaVM, "__div", CLuaVector3Defs::Div );
lua_classmetamethod ( luaVM, "__pow", CLuaVector3Defs::Pow );
lua_classmetamethod ( luaVM, "__unm", CLuaVector3Defs::Unm );
lua_classmetamethod ( luaVM, "__eq", CLuaVector3Defs::Eq );
lua_classmetamethod ( luaVM, "__len", CLuaVector3Defs::GetLength );

lua_classfunction ( luaVM, "create", "", CLuaVector3Defs::Create );
lua_classfunction ( luaVM, "normalize", "", CLuaVector3Defs::Normalize );
lua_classfunction ( luaVM, "cross", "", CLuaVector3Defs::Cross );
lua_classfunction ( luaVM, "dot", "", CLuaVector3Defs::Dot );

lua_classfunction ( luaVM, "getLength", "", CLuaVector3Defs::GetLength );
lua_classfunction ( luaVM, "getSquaredLength", "", CLuaVector3Defs::GetLengthSquared );
lua_classfunction ( luaVM, "getNormalized", "", CLuaVector3Defs::GetNormalized );
lua_classfunction ( luaVM, "getX", "", CLuaVector3Defs::GetX );
lua_classfunction ( luaVM, "getY", "", CLuaVector3Defs::GetY );
lua_classfunction ( luaVM, "getZ", "", CLuaVector3Defs::GetZ );

lua_classfunction ( luaVM, "setX", "", CLuaVector3Defs::SetX );
lua_classfunction ( luaVM, "setY", "", CLuaVector3Defs::SetY );
lua_classfunction ( luaVM, "setZ", "", CLuaVector3Defs::SetZ );

lua_classvariable ( luaVM, "x", "", "", CLuaVector3Defs::SetX, CLuaVector3Defs::GetX );
lua_classvariable ( luaVM, "y", "", "", CLuaVector3Defs::SetY, CLuaVector3Defs::GetY );
lua_classvariable ( luaVM, "z", "", "", CLuaVector3Defs::SetZ, CLuaVector3Defs::GetZ );
lua_classvariable ( luaVM, "length", "", "", NULL, CLuaVector3Defs::GetLength );
lua_classvariable ( luaVM, "squaredLength", "", "", NULL, CLuaVector3Defs::GetLengthSquared );
lua_classvariable ( luaVM, "normalized", "", "", NULL, CLuaVector3Defs::GetNormalized );

lua_registerclass ( luaVM, "Vector3" );
}


void CLuaMain::AddVector2DClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );

lua_classmetamethod ( luaVM, "__tostring", CLuaVector2Defs::ToString );
lua_classmetamethod ( luaVM, "__gc", CLuaVector2Defs::Destroy );

lua_classmetamethod ( luaVM, "__add", CLuaVector2Defs::Add );
lua_classmetamethod ( luaVM, "__sub", CLuaVector2Defs::Sub );
lua_classmetamethod ( luaVM, "__mul", CLuaVector2Defs::Mul );
lua_classmetamethod ( luaVM, "__div", CLuaVector2Defs::Div );
lua_classmetamethod ( luaVM, "__pow", CLuaVector2Defs::Pow );
lua_classmetamethod ( luaVM, "__unm", CLuaVector2Defs::Unm );
lua_classmetamethod ( luaVM, "__eq", CLuaVector2Defs::Eq );
lua_classmetamethod ( luaVM, "__len", CLuaVector2Defs::GetLength );

lua_classfunction ( luaVM, "create", "", CLuaVector2Defs::Create );
lua_classfunction ( luaVM, "normalize", "", CLuaVector2Defs::Normalize );
lua_classfunction ( luaVM, "dot", "", CLuaVector2Defs::Dot );

lua_classfunction ( luaVM, "getLength", "", CLuaVector2Defs::GetLength );
lua_classfunction ( luaVM, "getSquaredLength", "", CLuaVector2Defs::GetLengthSquared );
lua_classfunction ( luaVM, "getNormalized", "", CLuaVector2Defs::GetNormalized );
lua_classfunction ( luaVM, "getX", "", CLuaVector2Defs::GetX );
lua_classfunction ( luaVM, "getY", "", CLuaVector2Defs::GetY );

lua_classfunction ( luaVM, "setX", "", CLuaVector2Defs::SetX );
lua_classfunction ( luaVM, "setY", "", CLuaVector2Defs::SetY );

lua_classvariable ( luaVM, "x", "", "", CLuaVector2Defs::SetX, CLuaVector2Defs::GetX );
lua_classvariable ( luaVM, "y", "", "", CLuaVector2Defs::SetY, CLuaVector2Defs::GetY );

lua_classvariable ( luaVM, "length", "", "", NULL, CLuaVector2Defs::GetLength );
lua_classvariable ( luaVM, "squaredLength", "", "", NULL, CLuaVector2Defs::GetLengthSquared );
lua_classvariable ( luaVM, "normalized", "", "", NULL, CLuaVector2Defs::GetNormalized );

lua_registerclass ( luaVM, "Vector2" );
}


void CLuaMain::AddMatrixClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );

lua_classmetamethod ( luaVM, "__tostring", CLuaMatrixDefs::ToString );
lua_classmetamethod ( luaVM, "__gc", CLuaMatrixDefs::Destroy );

lua_classmetamethod ( luaVM, "__add", CLuaMatrixDefs::Add );
lua_classmetamethod ( luaVM, "__sub", CLuaMatrixDefs::Sub );
lua_classmetamethod ( luaVM, "__mul", CLuaMatrixDefs::Mul );
lua_classmetamethod ( luaVM, "__div", CLuaMatrixDefs::Div );

lua_classfunction ( luaVM, "create", "", CLuaMatrixDefs::Create );
lua_classfunction ( luaVM, "transformPosition", "", CLuaMatrixDefs::TransformPosition );
lua_classfunction ( luaVM, "transformDirection", "", CLuaMatrixDefs::TransformDirection );
lua_classfunction ( luaVM, "inverse", "", CLuaMatrixDefs::Inverse );

lua_classfunction ( luaVM, "getPosition", "", CLuaMatrixDefs::GetPosition );
lua_classfunction ( luaVM, "getRotation", "", CLuaMatrixDefs::GetRotation );
lua_classfunction ( luaVM, "getForward", "", CLuaMatrixDefs::GetForward );
lua_classfunction ( luaVM, "getRight", "", CLuaMatrixDefs::GetRight );
lua_classfunction ( luaVM, "getUp", "", CLuaMatrixDefs::GetUp );

lua_classfunction ( luaVM, "setPosition", "", CLuaMatrixDefs::SetPosition );
lua_classfunction ( luaVM, "setRotation", "", CLuaMatrixDefs::SetRotation );
lua_classfunction ( luaVM, "setForward", "", CLuaMatrixDefs::SetForward );
lua_classfunction ( luaVM, "setRight", "", CLuaMatrixDefs::SetRight );
lua_classfunction ( luaVM, "setUp", "", CLuaMatrixDefs::SetUp );

lua_classvariable ( luaVM, "position", "", "", CLuaMatrixDefs::SetPosition, CLuaMatrixDefs::GetPosition );
lua_classvariable ( luaVM, "rotation", "", "", CLuaMatrixDefs::SetRotation, CLuaMatrixDefs::GetRotation );
lua_classvariable ( luaVM, "forward", "", "", CLuaMatrixDefs::SetForward, CLuaMatrixDefs::GetForward );
lua_classvariable ( luaVM, "right", "", "", CLuaMatrixDefs::SetRight, CLuaMatrixDefs::GetRight );
lua_classvariable ( luaVM, "up", "", "", CLuaMatrixDefs::SetUp, CLuaMatrixDefs::GetUp );

lua_registerclass ( luaVM, "Matrix" );
}


// TODO: specials
void CLuaMain::AddElementClass ( lua_State* luaVM )
Expand Down Expand Up @@ -610,35 +443,6 @@ void CLuaMain::AddColShapeClass ( lua_State* luaVM )
}


void CLuaMain::AddFileClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );

lua_classfunction ( luaVM, "create", "fileOpen" );
lua_classfunction ( luaVM, "destroy", "fileClose" );
lua_classfunction ( luaVM, "close", "fileClose" );
lua_classfunction ( luaVM, "new", "fileCreate" );

lua_classfunction ( luaVM, "delete", "fileDelete" );
lua_classfunction ( luaVM, "exists", "fileExists" );
lua_classfunction ( luaVM, "flush", "fileFlush" );
lua_classfunction ( luaVM, "getPos", "fileGetPos" );
lua_classfunction ( luaVM, "getSize", "fileGetSize" );
lua_classfunction ( luaVM, "isEOF", "fileIsEOF" );
lua_classfunction ( luaVM, "read", "fileRead" );
lua_classfunction ( luaVM, "rename", "fileRename" );
lua_classfunction ( luaVM, "setPos", "fileSetPos" );
lua_classfunction ( luaVM, "write", "fileWrite" );
lua_classfunction ( luaVM, "copy", "fileCopy" );

lua_classvariable ( luaVM, "pos", "fileSetPos", "fileGetPos" );
lua_classvariable ( luaVM, "size", NULL, "fileGetSize" );
lua_classvariable ( luaVM, "isEOF", NULL, "fileIsEOF" );

lua_registerclass ( luaVM, "File" );
}


void CLuaMain::AddMarkerClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );
Expand Down Expand Up @@ -1325,26 +1129,26 @@ void CLuaMain::AddTimerClass ( lua_State* luaVM )
void CLuaMain::InitClasses ( lua_State* luaVM )
{
lua_initclasses ( luaVM );
lua_newclass ( luaVM );
lua_newclass ( luaVM );

// Vector and Matrix classes
AddVector4DClass ( luaVM );
AddVector3DClass ( luaVM );
AddVector2DClass ( luaVM );
AddMatrixClass ( luaVM );
CLuaVector4Defs::AddClass ( luaVM );
CLuaVector3Defs::AddClass ( luaVM );
CLuaVector2Defs::AddClass ( luaVM );
CLuaMatrixDefs ::AddClass ( luaVM );

// OOP based classes
if ( !m_bEnableOOP )
return;

CLuaFileDefs::AddClass ( luaVM );
AddElementClass ( luaVM );
AddACLClass ( luaVM );
AddACLGroupClass ( luaVM );
AddAccountClass ( luaVM );
AddBanClass ( luaVM );
AddBlipClass ( luaVM );
AddColShapeClass ( luaVM );
AddFileClass ( luaVM );
AddMarkerClass ( luaVM );
AddObjectClass ( luaVM );
AddPedClass ( luaVM );
Expand Down
7 changes: 0 additions & 7 deletions MTA10_Server/mods/deathmatch/logic/lua/CLuaMain.h
Expand Up @@ -129,20 +129,13 @@ class CLuaMain //: public CClient
void InitClasses ( lua_State* luaVM );

public:

void AddVector4DClass ( lua_State* luaVM );
void AddVector3DClass ( lua_State* luaVM );
void AddVector2DClass ( lua_State* luaVM );
void AddMatrixClass ( lua_State* luaVM );

void AddElementClass ( lua_State* luaVM );
void AddACLClass ( lua_State* luaVM );
void AddACLGroupClass ( lua_State* luaVM );
void AddAccountClass ( lua_State* luaVM );
void AddBanClass ( lua_State* luaVM );
void AddBlipClass ( lua_State* luaVM );
void AddColShapeClass ( lua_State* luaVM );
void AddFileClass ( lua_State* luaVM );
void AddMarkerClass ( lua_State* luaVM );
void AddObjectClass ( lua_State* luaVM );
void AddPedClass ( lua_State* luaVM );
Expand Down
33 changes: 31 additions & 2 deletions MTA10_Server/mods/deathmatch/logic/luadefs/CLuaFileDefs.cpp
Expand Up @@ -32,8 +32,37 @@ void CLuaFileDefs::LoadFunctions ( void )
CLuaCFunctions::AddFunction ( "fileClose", CLuaFileDefs::fileClose );
CLuaCFunctions::AddFunction ( "fileDelete", CLuaFileDefs::fileDelete );
CLuaCFunctions::AddFunction ( "fileRename", CLuaFileDefs::fileRename );
CLuaCFunctions::AddFunction ( "fileCopy", CLuaFileDefs::fileCopy );
CLuaCFunctions::AddFunction ( "fileGetPath", CLuaFileDefs::fileGetPath );
CLuaCFunctions::AddFunction ( "fileCopy", CLuaFileDefs::fileCopy );
CLuaCFunctions::AddFunction ( "fileGetPath", CLuaFileDefs::fileGetPath );
}


void CLuaFileDefs::AddClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );

lua_classfunction ( luaVM, "create", "fileOpen" );
lua_classfunction ( luaVM, "destroy", "fileClose" );
lua_classfunction ( luaVM, "close", "fileClose" );
lua_classfunction ( luaVM, "new", "fileCreate" );

lua_classfunction ( luaVM, "delete", "fileDelete" );
lua_classfunction ( luaVM, "exists", "fileExists" );
lua_classfunction ( luaVM, "flush", "fileFlush" );
lua_classfunction ( luaVM, "getPos", "fileGetPos" );
lua_classfunction ( luaVM, "getSize", "fileGetSize" );
lua_classfunction ( luaVM, "isEOF", "fileIsEOF" );
lua_classfunction ( luaVM, "read", "fileRead" );
lua_classfunction ( luaVM, "rename", "fileRename" );
lua_classfunction ( luaVM, "setPos", "fileSetPos" );
lua_classfunction ( luaVM, "write", "fileWrite" );
lua_classfunction ( luaVM, "copy", "fileCopy" );

lua_classvariable ( luaVM, "pos", "fileSetPos", "fileGetPos" );
lua_classvariable ( luaVM, "size", NULL, "fileGetSize" );
lua_classvariable ( luaVM, "isEOF", NULL, "fileIsEOF" );

lua_registerclass ( luaVM, "File" );
}


Expand Down
11 changes: 4 additions & 7 deletions MTA10_Server/mods/deathmatch/logic/luadefs/CLuaFileDefs.h
Expand Up @@ -13,14 +13,13 @@
*
*****************************************************************************/

#ifndef __CLUAFILEDEFS_H
#define __CLUAFILEDEFS_H

#pragma once
#include "CLuaDefs.h"

class CLuaFileDefs: public CLuaDefs
{
public:
static void AddClass ( lua_State* luaVM );
static void LoadFunctions ( void );

static int fileCreate ( lua_State* luaVM );
Expand All @@ -36,8 +35,6 @@ class CLuaFileDefs: public CLuaDefs
static int fileClose ( lua_State* luaVM );
static int fileDelete ( lua_State* luaVM );
static int fileRename ( lua_State* luaVM );
static int fileCopy ( lua_State* luaVM );
static int fileCopy ( lua_State* luaVM );
static int fileGetPath ( lua_State* luaVM );
};

#endif
};
39 changes: 39 additions & 0 deletions MTA10_Server/mods/deathmatch/logic/luadefs/CLuaMatrixDefs.cpp
Expand Up @@ -11,6 +11,45 @@
*****************************************************************************/

#include "StdInc.h"

void CLuaMatrixDefs::AddClass ( lua_State* luaVM )
{
lua_newclass ( luaVM );

lua_classmetamethod ( luaVM, "__tostring", ToString );
lua_classmetamethod ( luaVM, "__gc", Destroy );

lua_classmetamethod ( luaVM, "__add", Add );
lua_classmetamethod ( luaVM, "__sub", Sub );
lua_classmetamethod ( luaVM, "__mul", Mul );
lua_classmetamethod ( luaVM, "__div", Div );

lua_classfunction ( luaVM, "create", "", Create );
lua_classfunction ( luaVM, "transformPosition", "", TransformPosition );
lua_classfunction ( luaVM, "transformDirection", "", TransformDirection );
lua_classfunction ( luaVM, "inverse", "", Inverse );

lua_classfunction ( luaVM, "getPosition", "", GetPosition );
lua_classfunction ( luaVM, "getRotation", "", GetRotation );
lua_classfunction ( luaVM, "getForward", "", GetForward );
lua_classfunction ( luaVM, "getRight", "", GetRight );
lua_classfunction ( luaVM, "getUp", "", GetUp );

lua_classfunction ( luaVM, "setPosition", "", SetPosition );
lua_classfunction ( luaVM, "setRotation", "", SetRotation );
lua_classfunction ( luaVM, "setForward", "", SetForward );
lua_classfunction ( luaVM, "setRight", "", SetRight );
lua_classfunction ( luaVM, "setUp", "", SetUp );

lua_classvariable ( luaVM, "position", "", "", SetPosition, GetPosition );
lua_classvariable ( luaVM, "rotation", "", "", SetRotation, GetRotation );
lua_classvariable ( luaVM, "forward", "", "", SetForward, GetForward );
lua_classvariable ( luaVM, "right", "", "", SetRight, GetRight );
lua_classvariable ( luaVM, "up", "", "", SetUp, GetUp );

lua_registerclass ( luaVM, "Matrix" );
}


int CLuaMatrixDefs::Create ( lua_State* luaVM )
{
Expand Down
Expand Up @@ -23,6 +23,7 @@ extern "C"
class CLuaMatrixDefs: public CLuaDefs
{
public:
static void AddClass ( lua_State* luaVM );
static int Create ( lua_State* luaVM );
static int Destroy ( lua_State* luaVM );

Expand Down

0 comments on commit fa46e04

Please sign in to comment.