28 |
#include "../../weechat-plugin.h" |
#include "../../weechat-plugin.h" |
29 |
#include "../weechat-script.h" |
#include "../weechat-script.h" |
30 |
|
|
|
#ifdef HAVE_CONFIG_H |
|
|
#include "config.h" |
|
|
#endif |
|
|
|
|
31 |
char plugin_name[] = "Perl"; |
char plugin_name[] = "Perl"; |
32 |
char plugin_version[] = "0.1"; |
char plugin_version[] = "0.1"; |
33 |
char plugin_description[] = "Perl scripts support"; |
char plugin_description[] = "Perl scripts support"; |
40 |
|
|
41 |
extern void boot_DynaLoader (pTHX_ CV* cv); |
extern void boot_DynaLoader (pTHX_ CV* cv); |
42 |
|
|
43 |
#ifdef PERL_NOTHREAD |
#ifdef NO_PERL_MULTIPLICITY |
44 |
|
#undef MULTIPLICITY |
45 |
|
#endif |
46 |
|
|
47 |
|
#ifndef MULTIPLICITY |
48 |
#define PKG_NAME_PREFIX "WeechatPerlPackage" |
#define PKG_NAME_PREFIX "WeechatPerlPackage" |
49 |
static PerlInterpreter *main_perl = NULL; |
static PerlInterpreter *main_perl = NULL; |
50 |
int packnum = 0; |
int packnum = 0; |
52 |
|
|
53 |
char *weechat_perl_code = |
char *weechat_perl_code = |
54 |
{ |
{ |
55 |
#ifdef PERL_NOTHREAD |
#ifndef MULTIPLICITY |
56 |
"package WeechatPerlScriptLoader;" |
"package WeechatPerlScriptLoader;" |
57 |
#endif |
#endif |
58 |
"$weechat_perl_load_eval_file_error = \"\";" |
"$weechat_perl_load_eval_file_error = \"\";" |
67 |
"}" |
"}" |
68 |
"sub weechat_perl_load_eval_file" |
"sub weechat_perl_load_eval_file" |
69 |
"{" |
"{" |
70 |
#ifdef PERL_NOTHREAD |
#ifndef MULTIPLICITY |
71 |
" my ($filename, $package) = @_;" |
" my ($filename, $package) = @_;" |
72 |
#else |
#else |
73 |
" my $filename = shift;" |
" my $filename = shift;" |
77 |
" {" |
" {" |
78 |
" return 1;" |
" return 1;" |
79 |
" }" |
" }" |
80 |
#ifdef PERL_NOTHREAD |
#ifndef MULTIPLICITY |
81 |
" my $eval = qq{package $package; $content;};" |
" my $eval = qq{package $package; $content;};" |
82 |
#else |
#else |
83 |
" my $eval = $content;" |
" my $eval = $content;" |
112 |
int return_code; |
int return_code; |
113 |
SV *sv; |
SV *sv; |
114 |
|
|
115 |
#ifdef PERL_NOTHREAD |
#ifndef MULTIPLICITY |
116 |
int size = strlen(script->interpreter) + strlen(function) + 3; |
int size = strlen(script->interpreter) + strlen(function) + 3; |
117 |
func = (char *) malloc ( size * sizeof(char)); |
func = (char *) malloc ( size * sizeof(char)); |
118 |
if (func == NULL) |
if (func == NULL) |
161 |
FREETMPS; |
FREETMPS; |
162 |
LEAVE; |
LEAVE; |
163 |
|
|
164 |
#ifdef PERL_NOTHREAD |
#ifndef MULTIPLICITY |
165 |
free(func); |
free(func); |
166 |
#endif |
#endif |
167 |
|
|
840 |
t_plugin_script tempscript; |
t_plugin_script tempscript; |
841 |
int eval; |
int eval; |
842 |
|
|
843 |
#ifdef PERL_NOTHREAD |
#ifndef MULTIPLICITY |
844 |
char pkgname[64]; |
char pkgname[64]; |
845 |
#else |
#else |
846 |
PerlInterpreter *perl_current_interpreter; |
PerlInterpreter *perl_current_interpreter; |
850 |
plugin->printf_server (plugin, "Loading Perl script \"%s\"", filename); |
plugin->printf_server (plugin, "Loading Perl script \"%s\"", filename); |
851 |
perl_current_script = NULL; |
perl_current_script = NULL; |
852 |
|
|
853 |
#ifdef PERL_NOTHREAD |
#ifndef MULTIPLICITY |
854 |
snprintf(pkgname, sizeof(pkgname), "%s%d", PKG_NAME_PREFIX, packnum); |
snprintf(pkgname, sizeof(pkgname), "%s%d", PKG_NAME_PREFIX, packnum); |
855 |
packnum++; |
packnum++; |
856 |
tempscript.interpreter = "WeechatPerlScriptLoader"; |
tempscript.interpreter = "WeechatPerlScriptLoader"; |
883 |
filename); |
filename); |
884 |
plugin->printf_server (plugin, |
plugin->printf_server (plugin, |
885 |
"Perl error: %s", |
"Perl error: %s", |
886 |
#ifdef PERL_NOTHREAD |
#ifndef MULTIPLICITY |
887 |
SvPV(perl_get_sv("WeechatPerlScriptLoader::weechat_perl_load_eval_file_error", FALSE), len)); |
SvPV(perl_get_sv("WeechatPerlScriptLoader::weechat_perl_load_eval_file_error", FALSE), len)); |
888 |
#else |
#else |
889 |
SvPV(perl_get_sv("weechat_perl_load_eval_file_error", FALSE), len)); |
SvPV(perl_get_sv("weechat_perl_load_eval_file_error", FALSE), len)); |
900 |
"Perl error: unknown error while loading file \"%s\"", |
"Perl error: unknown error while loading file \"%s\"", |
901 |
filename); |
filename); |
902 |
} |
} |
903 |
#ifndef PERL_NOTHREAD |
#ifdef MULTIPLICITY |
904 |
perl_destruct (perl_current_interpreter); |
perl_destruct (perl_current_interpreter); |
905 |
perl_free (perl_current_interpreter); |
perl_free (perl_current_interpreter); |
906 |
#endif |
#endif |
917 |
"Perl error: function \"register\" not found " |
"Perl error: function \"register\" not found " |
918 |
"in file \"%s\"", |
"in file \"%s\"", |
919 |
filename); |
filename); |
920 |
#ifndef PERL_NOTHREAD |
#ifdef MULTIPLICITY |
921 |
perl_destruct (perl_current_interpreter); |
perl_destruct (perl_current_interpreter); |
922 |
perl_free (perl_current_interpreter); |
perl_free (perl_current_interpreter); |
923 |
#endif |
#endif |
924 |
return 0; |
return 0; |
925 |
} |
} |
926 |
|
|
927 |
#ifdef PERL_NOTHREAD |
#ifndef MULTIPLICITY |
928 |
perl_current_script->interpreter = strdup(pkgname); |
perl_current_script->interpreter = strdup(pkgname); |
929 |
#else |
#else |
930 |
perl_current_script->interpreter = (PerlInterpreter *) perl_current_interpreter; |
perl_current_script->interpreter = (PerlInterpreter *) perl_current_interpreter; |
944 |
"Unloading Perl script \"%s\"", |
"Unloading Perl script \"%s\"", |
945 |
script->name); |
script->name); |
946 |
|
|
947 |
#ifdef PERL_NOTHREAD |
#ifndef MULTIPLICITY |
948 |
eval_pv(script->interpreter, TRUE); |
eval_pv(script->interpreter, TRUE); |
949 |
#else |
#else |
950 |
PERL_SET_CONTEXT (script->interpreter); |
PERL_SET_CONTEXT (script->interpreter); |
953 |
if (script->shutdown_func[0]) |
if (script->shutdown_func[0]) |
954 |
weechat_perl_exec (plugin, script, script->shutdown_func, "", ""); |
weechat_perl_exec (plugin, script, script->shutdown_func, "", ""); |
955 |
|
|
956 |
#ifdef PERL_NOTHREAD |
#ifndef MULTIPLICITY |
957 |
if (script->interpreter) |
if (script->interpreter) |
958 |
free (script->interpreter); |
free (script->interpreter); |
959 |
#else |
#else |
1161 |
weechat_plugin_init (t_weechat_plugin *plugin) |
weechat_plugin_init (t_weechat_plugin *plugin) |
1162 |
{ |
{ |
1163 |
perl_plugin = plugin; |
perl_plugin = plugin; |
1164 |
|
|
1165 |
|
#ifdef MULTIPLICITY |
1166 |
plugin->printf_server (plugin, "Loading Perl module \"weechat\""); |
plugin->printf_server (plugin, "Loading Perl module \"weechat\""); |
1167 |
|
#else |
1168 |
|
plugin->printf_server (plugin, "Loading Perl module \"weechat\" (without multiplicity)"); |
1169 |
|
|
|
#ifdef PERL_NOTHREAD |
|
1170 |
char *perl_args[] = { "", "-e", "0" }; |
char *perl_args[] = { "", "-e", "0" }; |
1171 |
|
|
1172 |
main_perl = perl_alloc (); |
main_perl = perl_alloc (); |
1209 |
/* unload all scripts */ |
/* unload all scripts */ |
1210 |
weechat_perl_unload_all (plugin); |
weechat_perl_unload_all (plugin); |
1211 |
|
|
1212 |
#ifdef PERL_NOTHREAD |
#ifndef MULTIPLICITY |
1213 |
/* free perl intepreter */ |
/* free perl intepreter */ |
1214 |
if (main_perl) |
if (main_perl) |
1215 |
{ |
{ |