FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Python: Use keywords for attributes in emit_print() · jacob1/hexchat@bf9276f · GitHub

Repository navigation

Commit bf9276f

Browse files
committed
Python: Use keywords for attributes in emit_print()
1 parent f45487e commit bf9276f

1 file changed

Lines changed: 33 additions & 44 deletions

File tree

‎plugins/python/python.c‎

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,22 +1018,31 @@ Context_prnt(ContextObject *self, PyObject *args)
10181018
}
10191019

10201020
static PyObject *
1021-
Context_emit_print(ContextObject *self, PyObject *args)
1021+
Context_emit_print(ContextObject *self, PyObject *args, PyObject *kwargs)
10221022
{
1023-
char *argv[10];
1023+
char *argv[6];
10241024
char *name;
10251025
int res;
1026-
memset(&argv, 0, sizeof(char*)*10);
1027-
if (!PyArg_ParseTuple(args, "s|ssssss:print_event", &name,
1026+
long time = 0;
1027+
hexchat_event_attrs *attrs;
1028+
char *kwlist[] = {"name", "arg1", "arg2", "arg3",
1029+
"arg4", "arg5", "arg6",
1030+
"time", NULL};
1031+
memset(&argv, 0, sizeof(char*)*6);
1032+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|ssssssl:print_event", kwlist, &name,
10281033
&argv[0], &argv[1], &argv[2],
10291034
&argv[3], &argv[4], &argv[5],
1030-
&argv[6], &argv[7], &argv[8]))
1035+
&time))
10311036
return NULL;
10321037
BEGIN_XCHAT_CALLS(ALLOW_THREADS);
10331038
hexchat_set_context(ph, self->context);
1034-
res = hexchat_emit_print(ph, name, argv[0], argv[1], argv[2],
1035-
argv[3], argv[4], argv[5],
1036-
argv[6], argv[7], argv[8]);
1039+
attrs = hexchat_event_attrs_create(ph);
1040+
attrs->server_time_utc = (time_t)time;
1041+
1042+
res = hexchat_emit_print_attrs(ph, attrs, name, argv[0], argv[1], argv[2],
1043+
argv[3], argv[4], argv[5], NULL);
1044+
1045+
hexchat_event_attrs_free(ph, attrs);
10371046
END_XCHAT_CALLS();
10381047
return PyLong_FromLong(res);
10391048
}
@@ -1094,7 +1103,7 @@ static PyMethodDef Context_methods[] = {
10941103
{"set", (PyCFunction) Context_set, METH_NOARGS},
10951104
{"command", (PyCFunction) Context_command, METH_VARARGS},
10961105
{"prnt", (PyCFunction) Context_prnt, METH_VARARGS},
1097-
{"emit_print", (PyCFunction) Context_emit_print, METH_VARARGS},
1106+
{"emit_print", (PyCFunction) Context_emit_print, METH_VARARGS|METH_KEYWORDS},
10981107
{"get_info", (PyCFunction) Context_get_info, METH_VARARGS},
10991108
{"get_list", (PyCFunction) Context_get_list, METH_VARARGS},
11001109
{NULL, NULL}
@@ -1660,46 +1669,28 @@ Module_xchat_prnt(PyObject *self, PyObject *args)
16601669
}
16611670

16621671
static PyObject *
1663-
Module_hexchat_emit_print(PyObject *self, PyObject *args)
1664-
{
1665-
char *argv[10];
1666-
char *name;
1667-
int res;
1668-
memset(&argv, 0, sizeof(char*)*10);
1669-
if (!PyArg_ParseTuple(args, "s|ssssss:print_event", &name,
1670-
&argv[0], &argv[1], &argv[2],
1671-
&argv[3], &argv[4], &argv[5],
1672-
&argv[6], &argv[7], &argv[8]))
1673-
return NULL;
1674-
BEGIN_XCHAT_CALLS(RESTORE_CONTEXT|ALLOW_THREADS);
1675-
res = hexchat_emit_print(ph, name, argv[0], argv[1], argv[2],
1676-
argv[3], argv[4], argv[5],
1677-
argv[6], argv[7], argv[8]);
1678-
END_XCHAT_CALLS();
1679-
return PyLong_FromLong(res);
1680-
}
1681-
1682-
static PyObject *
1683-
Module_hexchat_emit_print_at(PyObject *self, PyObject *args)
1672+
Module_hexchat_emit_print(PyObject *self, PyObject *args, PyObject *kwargs)
16841673
{
1685-
char *argv[10];
1674+
char *argv[6];
16861675
char *name;
1687-
long time;
16881676
int res;
1689-
hexchat_event_attrs* attrs;
1690-
memset(&argv, 0, sizeof(char*)*10);
1691-
if (!PyArg_ParseTuple(args, "ls|ssssss:print_event_at", &time, &name,
1677+
long time = 0;
1678+
hexchat_event_attrs *attrs;
1679+
char *kwlist[] = {"name", "arg1", "arg2", "arg3",
1680+
"arg4", "arg5", "arg6",
1681+
"time", NULL};
1682+
memset(&argv, 0, sizeof(char*)*6);
1683+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|ssssssl:print_event", kwlist, &name,
16921684
&argv[0], &argv[1], &argv[2],
16931685
&argv[3], &argv[4], &argv[5],
1694-
&argv[6], &argv[7], &argv[8]))
1686+
&time))
16951687
return NULL;
16961688
BEGIN_XCHAT_CALLS(RESTORE_CONTEXT|ALLOW_THREADS);
16971689
attrs = hexchat_event_attrs_create(ph);
1698-
attrs->server_time_utc = (time_t)time;
1699-
1690+
attrs->server_time_utc = (time_t)time;
1691+
17001692
res = hexchat_emit_print_attrs(ph, attrs, name, argv[0], argv[1], argv[2],
1701-
argv[3], argv[4], argv[5],
1702-
argv[6], argv[7], argv[8]);
1693+
argv[3], argv[4], argv[5], NULL);
17031694

17041695
hexchat_event_attrs_free(ph, attrs);
17051696
END_XCHAT_CALLS();
@@ -2314,10 +2305,8 @@ static PyMethodDef Module_xchat_methods[] = {
23142305
METH_VARARGS},
23152306
{"prnt", Module_xchat_prnt,
23162307
METH_VARARGS},
2317-
{"emit_print", Module_hexchat_emit_print,
2318-
METH_VARARGS},
2319-
{"emit_print_at", Module_hexchat_emit_print_at,
2320-
METH_VARARGS},
2308+
{"emit_print", (PyCFunction)Module_hexchat_emit_print,
2309+
METH_VARARGS|METH_KEYWORDS},
23212310
{"get_info", Module_hexchat_get_info,
23222311
METH_VARARGS},
23232312
{"get_prefs", Module_xchat_get_prefs,

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL