Skip to content

Commit

Permalink
fixed bug that caused string returning function to not properly work
Browse files Browse the repository at this point in the history
  • Loading branch information
habecker committed Apr 15, 2017
1 parent fdfaa87 commit dcd7c3d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 39 deletions.
17 changes: 14 additions & 3 deletions python/FunctionGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,13 @@ def getReturnString(self):

def toCpp(self):
lines = 'static PyObject* pysamp_'+self.name.lower()+'(PyObject *self, PyObject *args)\n{\n'
i = len(self.params)
pars = self.params.copy()
pars.reverse()

i = len(self.params)
for param in pars:
lines += ' '+param.toDeclaration('arg'+str(i))+'\n'
if not(param.isOut and param.type == 'string'):
lines += ' '+param.toDeclaration('arg'+str(i))+'\n'
i -= 1
lines += ' if (!PyArg_ParseTuple(args, "'+self.toFormatString()+':'+self.name+'"'
for param in self.params:
Expand All @@ -165,6 +167,13 @@ def toCpp(self):
lines += ' PyErr_Print();\n'
lines += ' return NULL;\n'
lines += ' }\n'

i = len(self.params)
for param in pars:
if (param.isOut and param.type == 'string'):
lines += ' '+param.toDeclaration('arg'+str(i))+'\n'
i -= 1

lines += ' ' + self.returns + ' ret = ' + self.name + '('
fl = True
for param in self.params:
Expand All @@ -176,6 +185,8 @@ def toCpp(self):
lines += '&'
lines += param.name
lines += ');\n'


lines += ' '+self.getReturnString() + '\n';
lines += '}\n\n'
return lines
Expand All @@ -194,7 +205,7 @@ def toCpp(self):
methods.append(m)
except Exception as e:
traceback.print_exc()
output = '#ifndef samp_h\n#define samp_h\n#include <Python.h>\n#include "sampgdk.h"\n\n'
output = '#ifndef samp_h\n#define samp_h\n#include <Python.h>\n#include "sampgdk.h"\n#include "const.h"\n\n'
for method in methods:
output += method.toCpp()

Expand Down
33 changes: 17 additions & 16 deletions python/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define samp_h
#include <Python.h>
#include "sampgdk.h"
#include "consts.h"

static PyObject* pysamp_createactor(PyObject *self, PyObject *args)
{
Expand Down Expand Up @@ -1449,13 +1450,13 @@ static PyObject* pysamp_getplayerstate(PyObject *self, PyObject *args)
static PyObject* pysamp_getplayerip(PyObject *self, PyObject *args)
{
int arg2 = -1;
char* arg1 = new char[arg2];
int arg0 = -1;
if (!PyArg_ParseTuple(args, "ii:GetPlayerIp", &arg0, &arg2))
{
PyErr_Print();
return NULL;
}
char* arg1 = new char[arg2];
bool ret = GetPlayerIp(arg0, arg1, arg2);
PyObject* out = Py_BuildValue("s", arg1);
delete[] arg1;
Expand Down Expand Up @@ -1507,13 +1508,13 @@ static PyObject* pysamp_getplayerkeys(PyObject *self, PyObject *args)
static PyObject* pysamp_getplayername(PyObject *self, PyObject *args)
{
int arg2 = -1;
char* arg1 = new char[arg2];
int arg0 = -1;
if (!PyArg_ParseTuple(args, "ii:GetPlayerName", &arg0, &arg2))
{
PyErr_Print();
return NULL;
}
char* arg1 = new char[arg2];
int ret = GetPlayerName(arg0, arg1, arg2);
PyObject* out = Py_BuildValue("s", arg1);
delete[] arg1;
Expand Down Expand Up @@ -2244,14 +2245,14 @@ static PyObject* pysamp_setpvarstring(PyObject *self, PyObject *args)
static PyObject* pysamp_getpvarstring(PyObject *self, PyObject *args)
{
int arg3 = -1;
char* arg2 = new char[arg3];
const char* arg1 = "";
int arg0 = -1;
if (!PyArg_ParseTuple(args, "isi:GetPVarString", &arg0, &arg1, &arg3))
{
PyErr_Print();
return NULL;
}
char* arg2 = new char[arg3];
bool ret = GetPVarString(arg0, arg1, arg2, arg3);
PyObject* out = Py_BuildValue("s", arg2);
delete[] arg1;
Expand Down Expand Up @@ -2321,14 +2322,14 @@ static PyObject* pysamp_getpvarsupperindex(PyObject *self, PyObject *args)
static PyObject* pysamp_getpvarnameatindex(PyObject *self, PyObject *args)
{
int arg3 = -1;
char* arg2 = new char[arg3];
int arg1 = -1;
int arg0 = -1;
if (!PyArg_ParseTuple(args, "iii:GetPVarNameAtIndex", &arg0, &arg1, &arg3))
{
PyErr_Print();
return NULL;
}
char* arg2 = new char[arg3];
bool ret = GetPVarNameAtIndex(arg0, arg1, arg2, arg3);
PyObject* out = Py_BuildValue("s", arg2);
delete[] arg2;
Expand Down Expand Up @@ -2507,15 +2508,15 @@ static PyObject* pysamp_getplayeranimationindex(PyObject *self, PyObject *args)
static PyObject* pysamp_getanimationname(PyObject *self, PyObject *args)
{
int arg4 = -1;
char* arg3 = new char[arg4];
int arg2 = -1;
char* arg1 = new char[arg2];
int arg0 = -1;
if (!PyArg_ParseTuple(args, "iii:GetAnimationName", &arg0, &arg2, &arg4))
{
PyErr_Print();
return NULL;
}
char* arg3 = new char[arg4];
char* arg1 = new char[arg2];
bool ret = GetAnimationName(arg0, arg1, arg2, arg3, arg4);
PyObject* out = Py_BuildValue("ss", arg1, arg3);
delete[] arg1;
Expand Down Expand Up @@ -3436,13 +3437,13 @@ static PyObject* pysamp_setsvarstring(PyObject *self, PyObject *args)
static PyObject* pysamp_getsvarstring(PyObject *self, PyObject *args)
{
int arg2 = -1;
char* arg1 = new char[arg2];
const char* arg0 = "";
if (!PyArg_ParseTuple(args, "si:GetSVarString", &arg0, &arg2))
{
PyErr_Print();
return NULL;
}
char* arg1 = new char[arg2];
bool ret = GetSVarString(arg0, arg1, arg2);
PyObject* out = Py_BuildValue("s", arg1);
delete[] arg0;
Expand Down Expand Up @@ -3508,13 +3509,13 @@ static PyObject* pysamp_getsvarsupperindex(PyObject *self, PyObject *args)
static PyObject* pysamp_getsvarnameatindex(PyObject *self, PyObject *args)
{
int arg2 = -1;
char* arg1 = new char[arg2];
int arg0 = -1;
if (!PyArg_ParseTuple(args, "ii:GetSVarNameAtIndex", &arg0, &arg2))
{
PyErr_Print();
return NULL;
}
char* arg1 = new char[arg2];
bool ret = GetSVarNameAtIndex(arg0, arg1, arg2);
PyObject* out = Py_BuildValue("s", arg1);
delete[] arg1;
Expand Down Expand Up @@ -3752,13 +3753,13 @@ static PyObject* pysamp_setworldtime(PyObject *self, PyObject *args)
static PyObject* pysamp_getweaponname(PyObject *self, PyObject *args)
{
int arg2 = -1;
char* arg1 = new char[arg2];
int arg0 = -1;
if (!PyArg_ParseTuple(args, "ii:GetWeaponName", &arg0, &arg2))
{
PyErr_Print();
return NULL;
}
char* arg1 = new char[arg2];
bool ret = GetWeaponName(arg0, arg1, arg2);
PyObject* out = Py_BuildValue("s", arg1);
delete[] arg1;
Expand Down Expand Up @@ -4072,13 +4073,13 @@ static PyObject* pysamp_sendrconcommand(PyObject *self, PyObject *args)
static PyObject* pysamp_getplayernetworkstats(PyObject *self, PyObject *args)
{
int arg2 = -1;
char* arg1 = new char[arg2];
int arg0 = -1;
if (!PyArg_ParseTuple(args, "ii:GetPlayerNetworkStats", &arg0, &arg2))
{
PyErr_Print();
return NULL;
}
char* arg1 = new char[arg2];
bool ret = GetPlayerNetworkStats(arg0, arg1, arg2);
PyObject* out = Py_BuildValue("s", arg1);
delete[] arg1;
Expand All @@ -4088,12 +4089,12 @@ static PyObject* pysamp_getplayernetworkstats(PyObject *self, PyObject *args)
static PyObject* pysamp_getnetworkstats(PyObject *self, PyObject *args)
{
int arg1 = -1;
char* arg0 = new char[arg1];
if (!PyArg_ParseTuple(args, "i:GetNetworkStats", &arg1))
{
PyErr_Print();
return NULL;
}
char* arg0 = new char[arg1];
bool ret = GetNetworkStats(arg0, arg1);
PyObject* out = Py_BuildValue("s", arg0);
delete[] arg0;
Expand All @@ -4103,13 +4104,13 @@ static PyObject* pysamp_getnetworkstats(PyObject *self, PyObject *args)
static PyObject* pysamp_getplayerversion(PyObject *self, PyObject *args)
{
int arg2 = -1;
char* arg1 = new char[arg2];
int arg0 = -1;
if (!PyArg_ParseTuple(args, "ii:GetPlayerVersion", &arg0, &arg2))
{
PyErr_Print();
return NULL;
}
char* arg1 = new char[arg2];
bool ret = GetPlayerVersion(arg0, arg1, arg2);
PyObject* out = Py_BuildValue("s", arg1);
delete[] arg1;
Expand Down Expand Up @@ -4148,13 +4149,13 @@ static PyObject* pysamp_unblockipaddress(PyObject *self, PyObject *args)
static PyObject* pysamp_getservervarasstring(PyObject *self, PyObject *args)
{
int arg2 = -1;
char* arg1 = new char[arg2];
const char* arg0 = "";
if (!PyArg_ParseTuple(args, "si:GetServerVarAsString", &arg0, &arg2))
{
PyErr_Print();
return NULL;
}
char* arg1 = new char[arg2];
bool ret = GetServerVarAsString(arg0, arg1, arg2);
PyObject* out = Py_BuildValue("s", arg1);
delete[] arg0;
Expand Down Expand Up @@ -4193,13 +4194,13 @@ static PyObject* pysamp_getservervarasbool(PyObject *self, PyObject *args)
static PyObject* pysamp_getconsolevarasstring(PyObject *self, PyObject *args)
{
int arg2 = -1;
char* arg1 = new char[arg2];
const char* arg0 = "";
if (!PyArg_ParseTuple(args, "si:GetConsoleVarAsString", &arg0, &arg2))
{
PyErr_Print();
return NULL;
}
char* arg1 = new char[arg2];
bool ret = GetConsoleVarAsString(arg0, arg1, arg2);
PyObject* out = Py_BuildValue("s", arg1);
delete[] arg0;
Expand Down Expand Up @@ -4354,13 +4355,13 @@ static PyObject* pysamp_netstats_connectionstatus(PyObject *self, PyObject *args
static PyObject* pysamp_netstats_getipport(PyObject *self, PyObject *args)
{
int arg2 = -1;
char* arg1 = new char[arg2];
int arg0 = -1;
if (!PyArg_ParseTuple(args, "ii:NetStats_GetIpPort", &arg0, &arg2))
{
PyErr_Print();
return NULL;
}
char* arg1 = new char[arg2];
bool ret = NetStats_GetIpPort(arg0, arg1, arg2);
PyObject* out = Py_BuildValue("s", arg1);
delete[] arg1;
Expand Down Expand Up @@ -5020,13 +5021,13 @@ static PyObject* pysamp_showplayerdialog(PyObject *self, PyObject *args)
static PyObject* pysamp_gpci(PyObject *self, PyObject *args)
{
int arg2 = -1;
char* arg1 = new char[arg2];
int arg0 = -1;
if (!PyArg_ParseTuple(args, "ii:gpci", &arg0, &arg2))
{
PyErr_Print();
return NULL;
}
char* arg1 = new char[arg2];
bool ret = gpci(arg0, arg1, arg2);
PyObject* out = Py_BuildValue("s", arg1);
delete[] arg1;
Expand Down
Loading

0 comments on commit dcd7c3d

Please sign in to comment.