New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
php: add bindings for PHP 7 #909
Conversation
Hi, What's the minimum PHP version required? |
Min version is 7.0.0. Support for 5.x would require some refactoring and a hairier cmake script :) |
@adsr: OK. |
@flashcode There is a test script here https://github.com/weechat/weechat/pull/909/files#diff-2ddb2c57b4fd43a1745f4692105df66c I added some more hooks to it and fixed a few things. |
What would be the syntax if you don't use anon functions? (for example to declare many hooks with the same callback) |
@flashcode Any callable type should work but I'd recommend this setup: new class {
function __construct() {
...
weechat_hook_x(..., [ $this, 'callbackFunc' ], ...);
weechat_hook_y(..., [ $this, 'callbackFunc' ], ...);
}
function callbackFunc(...) {
...
}
}; |
I see. |
There are a bunch of ways. Instead of $cb = function (...$args) {
weechat_printf(null, json_encode($args));
return WEECHAT_RC_OK;
};
weechat_register('phptest', 'adsr', '0.1', 'GPL3', 'test', '', '');
weechat_hook_signal('*,irc_in2_privmsg', $cb, 'anything');
weechat_hook_completion('phpcompletion', 'desc', $cb, 'anything');
weechat_hook_command('phptestcmd', 'desc1', '', 'desc2', '', $cb, 'anything');
weechat_hook_config('weechat.look.item_time_format', $cb, 'anything');
weechat_hook_process('date', 10, $cb, 'anything'); Yet another way is to tweak the bindings so they automatically convert |
I added two functions |
Rebased |
233186e
to
cb17269
Compare
I've been running a php bot on top of this plugin for several months. It doesn't exercise the entire api, but is stable with the parts it does use. |
fc3cbbb
to
bb44bc4
Compare
Rebased |
Hi @adsr, |
By the way, which PHP packages should I install on Debian (Sid) to compile the PHP plugin? |
@flashcode Great. I am done working on it except for the CMake build script. The last few commits I made were an attempt to get the Travis build to compile the PHP extension via autotools, but it isn't working for some reason. Can we ask Travis for a debug VM to investigate? I will see if I can get a CMake build script working in the mean time. Any version of PHP compiled with |
I tried with these PHP packages installed:
pkg-config reports no php:
So WeeChat doesn't detect PHP and the plugin is not compiled. Did I miss something? |
Hm I'm not sure those packages install any pc files. The autotools script checks [0] https://github.com/adsr/weechat/blob/2b8b56ec6d5b6d2a88b704c1cafe96642fb3524e/configure.ac#L805-L858 |
I'm testing exclusively with cmake, which is recommended over configure (autotools may be removed in a future version, they're here only for historical reasons). |
I updated the CMake script to use |
The autotools and CMake Travis builds compile the plugin successfully now. |
Merged, thanks for this feature. Now I'm testing all functions, I saw some potential problems, I'll check and fix if needed. Not directly related to PHP, but I'm writing tests for the whole script API, that will generate scripts in each language, to test all functions. |
This has been on my todo list for a long time.
Most of weechat-php-api.c is code generated, so any bugs lurking within should at least be consistent / easy to fix. Manual testing runs clean through valgrind. The plugin could use more thorough testing overall though.
A note about script reloading: In PHP it is difficult to isolate the namespace for an individual script. (E.g., there is no equivalent of
lua_State
.) To avoid polluting global namespace, I suggest wrapping all user scripts in an anonymous class instance. (See test.php.) Named classes and top-level functions will work, but will error with "already declared" when reloading the script.Another note: I have a pull request open to fix callbacks on anonymous class methods here: php/php-src#2381 Until that is merged users should do this:weechat_hook_signal("*,irc_in2_privmsg", CLASS . '::' . 'onPrivMsg', '');instead of this:weechat_hook_signal("*,irc_in2_privmsg", [$this, 'onPrivMsg'], '');EDIT: I wrote a work-around to address the above. See #909 (comment)