Changeset 0147ca9 for protocols/python/src/bpython.c
- Timestamp:
- 2013-03-17T15:06:34Z (12 years ago)
- Children:
- e38c6d8
- Parents:
- 0075527
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/python/src/bpython.c
r0075527 r0147ca9 28 28 void init_plugin() { 29 29 struct prpl *ret = g_new0(struct prpl, 1); 30 GDir *dir; 31 GError *error = NULL; 30 32 31 33 printf("Initialising Python... "); 32 34 Py_Initialize(); 33 35 PyRun_SimpleString("print 'Python initialised!'\n"); 34 // Py_Finalize(); // TODO - there's no plugin_unload for us to do this in. 36 37 /* Get a reference to the main module. */ 38 PyObject* main_module = PyImport_AddModule("__main__"); 39 40 /* Get the main module's dictionary */ 41 PyObject* main_dict = PyModule_GetDict(main_module); 42 43 dir = g_dir_open(global.conf->plugindir, 0, &error); 44 if (dir) { 45 const gchar *entry; 46 char * path; 47 while ((entry = g_dir_read_name(dir))) { 48 path = g_build_filename(global.conf->plugindir, entry, NULL); 49 if (!path) { 50 log_message(LOGLVL_WARNING, "Can't build path for %s\n", entry); 51 continue; 52 } 53 54 if (g_str_has_suffix(path, ".py")) { 55 printf("Loading python file %s\n", path); 56 FILE* pyfile = fopen(path, "r"); 57 /* Copy main dict to make sure that separate plugins 58 run in separate environments */ 59 PyObject* main_dict_copy = PyDict_Copy(main_dict); 60 PyRun_File(pyfile, path, Py_file_input, main_dict_copy, main_dict_copy); 61 62 } 63 64 g_free(path); 65 } 66 } 67 35 68 36 69 ret->name = "bpython"; 37 70 38 71 register_protocol(ret); 72 73 // Py_Finalize(); // TODO - there's no plugin_unload for us to do this in. 39 74 } 40 75
Note: See TracChangeset
for help on using the changeset viewer.