Skip to content

refactor and restructure entire project #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/src",
"${workspaceFolder}/vendor/lua/include",
"${workspaceFolder}/vendor/libpq/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"WINDOWS",
"WIN32"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Lua.diagnostics.globals": [
"workspace",
"configurations",
"location"
]
}
45 changes: 45 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Postgre.SQL module for MTA-SA
## Build instructions

### Linux
Note: This guide will use Arch Linux as an example. For Red Hat/RHEL based systems, check our Dockerfile.


Install premake5, build tools and pgsql libs
```
sudo pacman -S base-devel premake postgresql-libs
```

Compile
```
premake5 gmake2
cd build
make
```

### Windows
Note: This guide assumes you have scoop installed. If you do not, then install it [here](https://scoop.sh).

Install premake5 and GNU make
```
scoop install premake make
```

Install tdm-gcc, or VS 2019
```
TDM-GCC: https://github.com/jmeubank/tdm-gcc/releases/download/v9.2.0-tdm64-1/tdm64-gcc-9.2.0.exe
VS 2019: Microsoft's website.
```

Compile
```
# for gcc/mingw
premake5 gmake2
cd build
make

# for vs2019
premake5 vs2019
cd build
explorer .
```
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM centos:centos7

ENV PREMAKE_VERSION="5.0.0-alpha15"

##
# Update system
##
RUN \
yum update -y && \
yum upgrade -y

##
# Install packages
##
RUN \
yum install -y \
gcc \
gcc-c++ \
make \
kernel-devel \
postgresql-libs \
postgresql-dev \
wget \
curl \
tar

##
# Add premake5 to /usr/local/bin
##
RUN \
mkdir premake5 && \
cd premake5 && \
wget https://github.com/premake/premake-core/releases/download/v${PREMAKE_VERSION}/premake-${PREMAKE_VERSION}-linux.tar.gz && \
tar -zxvf premake-${PREMAKE_VERSION}-linux.tar.gz && \
cp premake5 /usr/local/bin && \
cd .. && \
rm -rf premake5

##
# Configure workdir
##
WORKDIR /app
COPY . /app

##
# Start building...
##
RUN \
premake5 gmake2 && \
cd build && \
make
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ I accept any support regarding the module development. Feel free to make PRs and
# Installation
Information about **Installation** provided on the **[Releases](https://github.com/Disinterpreter/ml_pgsql/releases)** page.

# Build from source
Check our [builds](BUILD.md) file.

# Functions
## pg_conn function
### Syntax
Expand Down
21 changes: 0 additions & 21 deletions linux-build.sh

This file was deleted.

32 changes: 0 additions & 32 deletions ml_pgsql/premake5.lua

This file was deleted.

57 changes: 40 additions & 17 deletions premake5.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
solution "ml_pgsql"
workspace "ml_pgsql"
configurations { "Debug", "Release" }
location ( "Build" )
targetdir "Bin/%{cfg.platform}/%{cfg.buildcfg}"
platforms { "x86", "x64" }

targetprefix ""

pic "On"
symbols "On"

filter "system:windows"
location "build"

project "ml_pgsql"
kind "SharedLib"
language "C++"

cppdialect "C++17"
files { "src/**.cpp", "src/**.hpp" }

includedirs {
"src/",
"vendor/lua/include",
"vendor/lua/include/lua",
"vendor/libpq/include"
}

filter { "architecture:x86", "system:windows" }
defines { "WINDOWS", "WIN32" }
libdirs { "vendor/lua/lib/x86", "vendor/libpq/lib/x86" }
links { "lua5.1", "libpq" }

filter { "architecture:x64", "system:windows" }
defines { "WINDOWS", "WIN32" }
libdirs { "vendor/lua/lib/x64", "vendor/libpq/lib/x64" }
links { "lua5.1", "libpq" }

filter { "architecture:x86", "system:linux" }
defines { "LINUX" }
links { "pq" }

filter { "architecture:x64", "system:linux" }
defines { "LINUX" }
links { "pq" }

filter { "configurations:Debug" }
defines { "DEBUG" }
symbols "On"

filter "configurations:Debug"
defines { "DEBUG" }
filter { "configurations:Release" }
defines { "NDEBUG" }
optimize "On"

filter "configurations:Release"
optimize "On"

include "ml_pgsql"
6 changes: 3 additions & 3 deletions ml_pgsql/src/CFunctions.cpp → src/CFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* PROVIDED WITH THIS PACKAGE.
*
*********************************************************/
#include "ml_pgsql.h"
#include "CFunctions.h"
#include "CPostgresManager.h"
#include "ml_pgsql.hpp"
#include "CFunctions.hpp"
#include "CPostgresManager.hpp"

int CFunctions::pg_conn(lua_State* luaVM)
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*********************************************************/

#include "CPostgresConnection.h"
#include "CPostgresConnection.hpp"

CPostgresConnection::CPostgresConnection(lua_State* pLuaVM, const char* szConnectionInfo) : m_pLuaVM{pLuaVM}
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#pragma once

#include "ml_pgsql.h"
#include "ml_pgsql.hpp"

class CPostgresConnection
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* PROVIDED WITH THIS PACKAGE.
*
*********************************************************/
#include "CPostgresManager.h"
#include "CPostgresManager.hpp"


CPostgresManager::CPostgresManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

#pragma once

#include "ml_pgsql.h"
#include "CPostgresConnection.h"
#include "ml_pgsql.hpp"
#include "CPostgresConnection.hpp"

#include <vector>

Expand Down
11 changes: 3 additions & 8 deletions ml_pgsql/include/Common.h → src/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*
* ml_base, External lua add-on module
*
* Copyright � 2003-2008 MTA. All Rights Reserved.
* Copyright � 2003-2008 MTA. All Rights Reserved.
*
* Grand Theft Auto is � 2002-2003 Rockstar North
* Grand Theft Auto is � 2002-2003 Rockstar North
*
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
Expand All @@ -16,12 +16,7 @@
*
*********************************************************/

extern "C"
{
#include "lua/lua.h"
#include "lua/lualib.h"
#include "lua/lauxlib.h"
}
#include <lua/lua.hpp>

#ifdef WIN32
#define MTAEXPORT extern "C" __declspec(dllexport)
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions ml_pgsql/src/ml_pgsql.cpp → src/ml_pgsql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* PROVIDED WITH THIS PACKAGE.
*
*********************************************************/
#include "ml_pgsql.h"
#include "CFunctions.h"
#include "CPostgresManager.h"
#include "ml_pgsql.hpp"
#include "CFunctions.hpp"
#include "CPostgresManager.hpp"

std::unique_ptr<ILuaModuleManager10> g_pLuaModuleManager;
std::unique_ptr<CPostgresManager> g_pPostgresManager;
Expand Down
8 changes: 4 additions & 4 deletions ml_pgsql/include/ml_pgsql.h → src/ml_pgsql.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#define MODULE_VERSION 0.6f

/* MTA-SA Module SDK */
#include "Common.h"
#include "ILuaModuleManager.h"
#include "lua/lua.h"
#include "Common.hpp"
#include "ILuaModuleManager.hpp"
#include <lua/lua.h>

/* Function-related defines for easier working with API */
#define LUA_FUNCTION_DECLARE(function) static int function(lua_State* luaVM)
Expand All @@ -38,7 +38,7 @@
#define SAFE_DELETE(ptr) { delete ptr; ptr = nullptr; }

/* LUA imports */
#include "lua/luaimports.h"
#include <lua/luaimports.h>

/* Standard Library useful includes */
#include <memory> // smart pointers
Expand Down
Binary file removed utils/premake5
Binary file not shown.
Binary file removed utils/premake5.exe
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 0 additions & 18 deletions win-create-project.bat

This file was deleted.