Skip to content

Commit bfee233

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master' into python-examples
2 parents 849e1b4 + dcd7c3d commit bfee233

File tree

5 files changed

+60
-39
lines changed

5 files changed

+60
-39
lines changed

python/FunctionGenerator.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,13 @@ def getReturnString(self):
149149

150150
def toCpp(self):
151151
lines = 'static PyObject* pysamp_'+self.name.lower()+'(PyObject *self, PyObject *args)\n{\n'
152-
i = len(self.params)
153152
pars = self.params.copy()
154153
pars.reverse()
154+
155+
i = len(self.params)
155156
for param in pars:
156-
lines += ' '+param.toDeclaration('arg'+str(i))+'\n'
157+
if not(param.isOut and param.type == 'string'):
158+
lines += ' '+param.toDeclaration('arg'+str(i))+'\n'
157159
i -= 1
158160
lines += ' if (!PyArg_ParseTuple(args, "'+self.toFormatString()+':'+self.name+'"'
159161
for param in self.params:
@@ -165,6 +167,13 @@ def toCpp(self):
165167
lines += ' PyErr_Print();\n'
166168
lines += ' return NULL;\n'
167169
lines += ' }\n'
170+
171+
i = len(self.params)
172+
for param in pars:
173+
if (param.isOut and param.type == 'string'):
174+
lines += ' '+param.toDeclaration('arg'+str(i))+'\n'
175+
i -= 1
176+
168177
lines += ' ' + self.returns + ' ret = ' + self.name + '('
169178
fl = True
170179
for param in self.params:
@@ -176,6 +185,8 @@ def toCpp(self):
176185
lines += '&'
177186
lines += param.name
178187
lines += ');\n'
188+
189+
179190
lines += ' '+self.getReturnString() + '\n';
180191
lines += '}\n\n'
181192
return lines
@@ -194,7 +205,7 @@ def toCpp(self):
194205
methods.append(m)
195206
except Exception as e:
196207
traceback.print_exc()
197-
output = '#ifndef samp_h\n#define samp_h\n#include <Python.h>\n#include "sampgdk.h"\n\n'
208+
output = '#ifndef samp_h\n#define samp_h\n#include <Python.h>\n#include "sampgdk.h"\n#include "const.h"\n\n'
198209
for method in methods:
199210
output += method.toCpp()
200211

python/functions.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define samp_h
33
#include <Python.h>
44
#include "sampgdk.h"
5+
#include "consts.h"
56

67
static PyObject* pysamp_createactor(PyObject *self, PyObject *args)
78
{
@@ -1449,13 +1450,13 @@ static PyObject* pysamp_getplayerstate(PyObject *self, PyObject *args)
14491450
static PyObject* pysamp_getplayerip(PyObject *self, PyObject *args)
14501451
{
14511452
int arg2 = -1;
1452-
char* arg1 = new char[arg2];
14531453
int arg0 = -1;
14541454
if (!PyArg_ParseTuple(args, "ii:GetPlayerIp", &arg0, &arg2))
14551455
{
14561456
PyErr_Print();
14571457
return NULL;
14581458
}
1459+
char* arg1 = new char[arg2];
14591460
bool ret = GetPlayerIp(arg0, arg1, arg2);
14601461
PyObject* out = Py_BuildValue("s", arg1);
14611462
delete[] arg1;
@@ -1507,13 +1508,13 @@ static PyObject* pysamp_getplayerkeys(PyObject *self, PyObject *args)
15071508
static PyObject* pysamp_getplayername(PyObject *self, PyObject *args)
15081509
{
15091510
int arg2 = -1;
1510-
char* arg1 = new char[arg2];
15111511
int arg0 = -1;
15121512
if (!PyArg_ParseTuple(args, "ii:GetPlayerName", &arg0, &arg2))
15131513
{
15141514
PyErr_Print();
15151515
return NULL;
15161516
}
1517+
char* arg1 = new char[arg2];
15171518
int ret = GetPlayerName(arg0, arg1, arg2);
15181519
PyObject* out = Py_BuildValue("s", arg1);
15191520
delete[] arg1;
@@ -2244,14 +2245,14 @@ static PyObject* pysamp_setpvarstring(PyObject *self, PyObject *args)
22442245
static PyObject* pysamp_getpvarstring(PyObject *self, PyObject *args)
22452246
{
22462247
int arg3 = -1;
2247-
char* arg2 = new char[arg3];
22482248
const char* arg1 = "";
22492249
int arg0 = -1;
22502250
if (!PyArg_ParseTuple(args, "isi:GetPVarString", &arg0, &arg1, &arg3))
22512251
{
22522252
PyErr_Print();
22532253
return NULL;
22542254
}
2255+
char* arg2 = new char[arg3];
22552256
bool ret = GetPVarString(arg0, arg1, arg2, arg3);
22562257
PyObject* out = Py_BuildValue("s", arg2);
22572258
delete[] arg1;
@@ -2321,14 +2322,14 @@ static PyObject* pysamp_getpvarsupperindex(PyObject *self, PyObject *args)
23212322
static PyObject* pysamp_getpvarnameatindex(PyObject *self, PyObject *args)
23222323
{
23232324
int arg3 = -1;
2324-
char* arg2 = new char[arg3];
23252325
int arg1 = -1;
23262326
int arg0 = -1;
23272327
if (!PyArg_ParseTuple(args, "iii:GetPVarNameAtIndex", &arg0, &arg1, &arg3))
23282328
{
23292329
PyErr_Print();
23302330
return NULL;
23312331
}
2332+
char* arg2 = new char[arg3];
23322333
bool ret = GetPVarNameAtIndex(arg0, arg1, arg2, arg3);
23332334
PyObject* out = Py_BuildValue("s", arg2);
23342335
delete[] arg2;
@@ -2507,15 +2508,15 @@ static PyObject* pysamp_getplayeranimationindex(PyObject *self, PyObject *args)
25072508
static PyObject* pysamp_getanimationname(PyObject *self, PyObject *args)
25082509
{
25092510
int arg4 = -1;
2510-
char* arg3 = new char[arg4];
25112511
int arg2 = -1;
2512-
char* arg1 = new char[arg2];
25132512
int arg0 = -1;
25142513
if (!PyArg_ParseTuple(args, "iii:GetAnimationName", &arg0, &arg2, &arg4))
25152514
{
25162515
PyErr_Print();
25172516
return NULL;
25182517
}
2518+
char* arg3 = new char[arg4];
2519+
char* arg1 = new char[arg2];
25192520
bool ret = GetAnimationName(arg0, arg1, arg2, arg3, arg4);
25202521
PyObject* out = Py_BuildValue("ss", arg1, arg3);
25212522
delete[] arg1;
@@ -3436,13 +3437,13 @@ static PyObject* pysamp_setsvarstring(PyObject *self, PyObject *args)
34363437
static PyObject* pysamp_getsvarstring(PyObject *self, PyObject *args)
34373438
{
34383439
int arg2 = -1;
3439-
char* arg1 = new char[arg2];
34403440
const char* arg0 = "";
34413441
if (!PyArg_ParseTuple(args, "si:GetSVarString", &arg0, &arg2))
34423442
{
34433443
PyErr_Print();
34443444
return NULL;
34453445
}
3446+
char* arg1 = new char[arg2];
34463447
bool ret = GetSVarString(arg0, arg1, arg2);
34473448
PyObject* out = Py_BuildValue("s", arg1);
34483449
delete[] arg0;
@@ -3508,13 +3509,13 @@ static PyObject* pysamp_getsvarsupperindex(PyObject *self, PyObject *args)
35083509
static PyObject* pysamp_getsvarnameatindex(PyObject *self, PyObject *args)
35093510
{
35103511
int arg2 = -1;
3511-
char* arg1 = new char[arg2];
35123512
int arg0 = -1;
35133513
if (!PyArg_ParseTuple(args, "ii:GetSVarNameAtIndex", &arg0, &arg2))
35143514
{
35153515
PyErr_Print();
35163516
return NULL;
35173517
}
3518+
char* arg1 = new char[arg2];
35183519
bool ret = GetSVarNameAtIndex(arg0, arg1, arg2);
35193520
PyObject* out = Py_BuildValue("s", arg1);
35203521
delete[] arg1;
@@ -3752,13 +3753,13 @@ static PyObject* pysamp_setworldtime(PyObject *self, PyObject *args)
37523753
static PyObject* pysamp_getweaponname(PyObject *self, PyObject *args)
37533754
{
37543755
int arg2 = -1;
3755-
char* arg1 = new char[arg2];
37563756
int arg0 = -1;
37573757
if (!PyArg_ParseTuple(args, "ii:GetWeaponName", &arg0, &arg2))
37583758
{
37593759
PyErr_Print();
37603760
return NULL;
37613761
}
3762+
char* arg1 = new char[arg2];
37623763
bool ret = GetWeaponName(arg0, arg1, arg2);
37633764
PyObject* out = Py_BuildValue("s", arg1);
37643765
delete[] arg1;
@@ -4072,13 +4073,13 @@ static PyObject* pysamp_sendrconcommand(PyObject *self, PyObject *args)
40724073
static PyObject* pysamp_getplayernetworkstats(PyObject *self, PyObject *args)
40734074
{
40744075
int arg2 = -1;
4075-
char* arg1 = new char[arg2];
40764076
int arg0 = -1;
40774077
if (!PyArg_ParseTuple(args, "ii:GetPlayerNetworkStats", &arg0, &arg2))
40784078
{
40794079
PyErr_Print();
40804080
return NULL;
40814081
}
4082+
char* arg1 = new char[arg2];
40824083
bool ret = GetPlayerNetworkStats(arg0, arg1, arg2);
40834084
PyObject* out = Py_BuildValue("s", arg1);
40844085
delete[] arg1;
@@ -4088,12 +4089,12 @@ static PyObject* pysamp_getplayernetworkstats(PyObject *self, PyObject *args)
40884089
static PyObject* pysamp_getnetworkstats(PyObject *self, PyObject *args)
40894090
{
40904091
int arg1 = -1;
4091-
char* arg0 = new char[arg1];
40924092
if (!PyArg_ParseTuple(args, "i:GetNetworkStats", &arg1))
40934093
{
40944094
PyErr_Print();
40954095
return NULL;
40964096
}
4097+
char* arg0 = new char[arg1];
40974098
bool ret = GetNetworkStats(arg0, arg1);
40984099
PyObject* out = Py_BuildValue("s", arg0);
40994100
delete[] arg0;
@@ -4103,13 +4104,13 @@ static PyObject* pysamp_getnetworkstats(PyObject *self, PyObject *args)
41034104
static PyObject* pysamp_getplayerversion(PyObject *self, PyObject *args)
41044105
{
41054106
int arg2 = -1;
4106-
char* arg1 = new char[arg2];
41074107
int arg0 = -1;
41084108
if (!PyArg_ParseTuple(args, "ii:GetPlayerVersion", &arg0, &arg2))
41094109
{
41104110
PyErr_Print();
41114111
return NULL;
41124112
}
4113+
char* arg1 = new char[arg2];
41134114
bool ret = GetPlayerVersion(arg0, arg1, arg2);
41144115
PyObject* out = Py_BuildValue("s", arg1);
41154116
delete[] arg1;
@@ -4148,13 +4149,13 @@ static PyObject* pysamp_unblockipaddress(PyObject *self, PyObject *args)
41484149
static PyObject* pysamp_getservervarasstring(PyObject *self, PyObject *args)
41494150
{
41504151
int arg2 = -1;
4151-
char* arg1 = new char[arg2];
41524152
const char* arg0 = "";
41534153
if (!PyArg_ParseTuple(args, "si:GetServerVarAsString", &arg0, &arg2))
41544154
{
41554155
PyErr_Print();
41564156
return NULL;
41574157
}
4158+
char* arg1 = new char[arg2];
41584159
bool ret = GetServerVarAsString(arg0, arg1, arg2);
41594160
PyObject* out = Py_BuildValue("s", arg1);
41604161
delete[] arg0;
@@ -4193,13 +4194,13 @@ static PyObject* pysamp_getservervarasbool(PyObject *self, PyObject *args)
41934194
static PyObject* pysamp_getconsolevarasstring(PyObject *self, PyObject *args)
41944195
{
41954196
int arg2 = -1;
4196-
char* arg1 = new char[arg2];
41974197
const char* arg0 = "";
41984198
if (!PyArg_ParseTuple(args, "si:GetConsoleVarAsString", &arg0, &arg2))
41994199
{
42004200
PyErr_Print();
42014201
return NULL;
42024202
}
4203+
char* arg1 = new char[arg2];
42034204
bool ret = GetConsoleVarAsString(arg0, arg1, arg2);
42044205
PyObject* out = Py_BuildValue("s", arg1);
42054206
delete[] arg0;
@@ -4354,13 +4355,13 @@ static PyObject* pysamp_netstats_connectionstatus(PyObject *self, PyObject *args
43544355
static PyObject* pysamp_netstats_getipport(PyObject *self, PyObject *args)
43554356
{
43564357
int arg2 = -1;
4357-
char* arg1 = new char[arg2];
43584358
int arg0 = -1;
43594359
if (!PyArg_ParseTuple(args, "ii:NetStats_GetIpPort", &arg0, &arg2))
43604360
{
43614361
PyErr_Print();
43624362
return NULL;
43634363
}
4364+
char* arg1 = new char[arg2];
43644365
bool ret = NetStats_GetIpPort(arg0, arg1, arg2);
43654366
PyObject* out = Py_BuildValue("s", arg1);
43664367
delete[] arg1;
@@ -5020,13 +5021,13 @@ static PyObject* pysamp_showplayerdialog(PyObject *self, PyObject *args)
50205021
static PyObject* pysamp_gpci(PyObject *self, PyObject *args)
50215022
{
50225023
int arg2 = -1;
5023-
char* arg1 = new char[arg2];
50245024
int arg0 = -1;
50255025
if (!PyArg_ParseTuple(args, "ii:gpci", &arg0, &arg2))
50265026
{
50275027
PyErr_Print();
50285028
return NULL;
50295029
}
5030+
char* arg1 = new char[arg2];
50305031
bool ret = gpci(arg0, arg1, arg2);
50315032
PyObject* out = Py_BuildValue("s", arg1);
50325033
delete[] arg1;

0 commit comments

Comments
 (0)