My weekend was taken by boring academic stuff. More specifically, I’ve built a validator in C, including a tokenizer, a parser, and a scope system, to check for a small subset of the C language syntax. Anyway.. I was still able to do something interesting after all. :-)
Taking further my research about pyperl, I’ve wondered if it would be possible to wrap the XchatPython plugin interface for perl usage. Actually, it turned out that besides being possible, it was easy. It was just a matter of putting the following wrapper in the ~/.xchat2 directory:
import xchat import perl perl.eval("$xchat = Python::eval('xchat')") perl.eval("do '" + __file__[:-3] + ".pyl'") __module_name__ = perl.eval("$__module_name__") __module_version__ = perl.eval("$__module_version__") __module_description__ = perl.eval("$__module_description__")
This wrapper will load a file with the same name as itself, but with a .pyl extension, which should contain perl code defining the plugin (I haven’t used the .pl extension because this would conflict with the internal perl plugin of xchat). That code may access the $xchat object to interface with xchat, using the same API as defined in XchatPython.
Here is a small sample module in perl, defining the /test command:
#!/usr/bin/perl $__module_name__ = "perlwrap"; $__module_version__ = "1.0"; $__module_description__ = "Testing perlwrap."; sub test { $xchat->prnt("Test command!"); return $xchat->EAT_ALL; } $xchat->hook_command("test", &test); $xchat->prnt("Plugin perlwrap loaded!n");
Notice that the interface is exactly the same, including the meta-information.
Unfortunately, there seems to exist some bug in the MULTI_PERL support of pyperl which makes it lose track of function references once the python support commutes the thread states. To make this trick work, remove the MULTI_PERL support by deleting the MULTI_PERL file in the root of the pyperl distribution.
I’ve removed multi_perl file, but it doesn’t work. Any ideas?