version 1.16 | | version 1.17 |
---|
| | |
return NULL; | | return NULL; |
} | | } |
| | |
| | static int do_script(CFPContext* context) |
| | { |
| | FILE* scriptfile; |
| | PyObject* dict; |
| | |
| | scriptfile = fopen(context->script,"r"); |
| | if (scriptfile == NULL) |
| | { |
| | printf( "cfpython - The Script file %s can't be opened\n",context->script); |
| | return 0; |
| | } |
| | pushContext(context); |
| | dict = PyDict_New(); |
| | PyDict_SetItemString(dict, "__builtins__", PyEval_GetBuiltins()); |
| | PyRun_File(scriptfile, context->script, Py_file_input, dict, dict); |
| | if (PyErr_Occurred()) |
| | { |
| | PyErr_Print(); |
| | } |
| | Py_DECREF(dict); |
| | fclose(scriptfile); |
| | return 1; |
| | } |
| | |
CF_PLUGIN int initPlugin(const char* iversion, f_plug_api gethooksptr) | | CF_PLUGIN int initPlugin(const char* iversion, f_plug_api gethooksptr) |
{ | | { |
PyObject *m, *d; | | PyObject *m, *d; |
| | |
| | |
CF_PLUGIN int runPluginCommand(object* op, char* params) | | CF_PLUGIN int runPluginCommand(object* op, char* params) |
{ | | { |
FILE* scriptfile; | | |
char buf[1024]; | | char buf[1024]; |
CFPContext* context; | | CFPContext* context; |
static int rv = 0; | | static int rv = 0; |
| | |
| | rv = 0; |
| | |
if (current_command < -999) | | if (current_command < -999) |
{ | | { |
printf("Illegal call of runPluginCommand, call find_plugin_command first.\n"); | | printf("Illegal call of runPluginCommand, call find_plugin_command first.\n"); |
| | |
| | |
Py_XINCREF(context->who); | | Py_XINCREF(context->who); |
| | |
scriptfile = fopen(context->script,"r"); | | if (!do_script(context)) |
if (scriptfile == NULL) | | |
{ | | { |
printf( "cfpython - The Script file %s can't be opened\n",context->script); | | free(context); |
return rv; | | return rv; |
} | | } |
pushContext(context); | | |
PyRun_SimpleFile(scriptfile, context->script); | | |
fclose(scriptfile); | | |
context = popContext(); | | context = popContext(); |
rv = context->returnvalue; | | rv = context->returnvalue; |
Py_XDECREF(context->who); | | Py_XDECREF(context->who); |
| | |
{ | | { |
va_list args; | | va_list args; |
static int rv=0; | | static int rv=0; |
FILE* scriptfile; | | |
CFPContext* context; | | CFPContext* context; |
Crossfire_Player* cfpl; | | Crossfire_Player* cfpl; |
Crossfire_Object* cfob; | | Crossfire_Object* cfob; |
| | |
object* op; | | object* op; |
context = malloc(sizeof(CFPContext)); | | context = malloc(sizeof(CFPContext)); |
| | |
| | rv = 0; |
| | |
va_start(args, type); | | va_start(args, type); |
context->event_code = va_arg(args, int); | | context->event_code = va_arg(args, int); |
| | |
| | |
va_end(args); | | va_end(args); |
context->returnvalue = 0; | | context->returnvalue = 0; |
| | |
scriptfile = fopen(context->script,"r"); | | if (!do_script(context)) |
if (scriptfile == NULL) | | |
{ | | { |
printf( "cfpython - The Script file %s can't be opened\n",context->script); | | free(context); |
return &rv; | | return &rv; |
} | | } |
pushContext(context); | | |
PyRun_SimpleFile(scriptfile, context->script); | | |
fclose(scriptfile); | | |
context = popContext(); | | context = popContext(); |
rv = context->returnvalue; | | rv = context->returnvalue; |
Py_XDECREF(context->who); | | Py_XDECREF(context->who); |
| | |
static int rv=0; | | static int rv=0; |
va_list args; | | va_list args; |
char* buf; | | char* buf; |
FILE* scriptfile; | | |
CFPContext* context; | | CFPContext* context; |
| | |
| | rv = 0; |
| | |
context = malloc(sizeof(CFPContext)); | | context = malloc(sizeof(CFPContext)); |
| | |
context->message[0]=0; | | context->message[0]=0; |
| | |
context->returnvalue = 0; | | context->returnvalue = 0; |
| | |
va_end(args); | | va_end(args); |
scriptfile = fopen(context->script,"r"); | | |
if (scriptfile == NULL) | | if (!do_script(context)) |
{ | | { |
printf( "cfpython - The Script file %s can't be opened\n",context->script); | | free(context); |
return &rv; | | return &rv; |
} | | } |
pushContext(context); | | |
PyRun_SimpleFile(scriptfile, context->script); | | |
fclose(scriptfile); | | |
context = popContext(); | | context = popContext(); |
rv = context->returnvalue; | | rv = context->returnvalue; |
Py_XDECREF(context->who); | | Py_XDECREF(context->who); |