Skip to content
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

Closure for typedefs function pointers #45

Open
ghostjat opened this issue Nov 4, 2021 · 1 comment
Open

Closure for typedefs function pointers #45

ghostjat opened this issue Nov 4, 2021 · 1 comment

Comments

@ghostjat
Copy link

ghostjat commented Nov 4, 2021

Hi, i am trying to call IUP toolkit lib click_cb callback function which has following def
typedef int (*IFnii)(Ihandle*, int, int);

in php

function click_cb (FFI\CData $ih, FFI\CData $l, FFI\CData $c) {
      echo $lin = FFI::cast('int',$l)->cdata;
      echo $col = FFI:cast('int', $c)->cdata;
 };

Fatal error: Uncaught FFI\Exception: Attempt to assign an invalid callback, insufficient number of arguments

@dstogov
Copy link
Owner

dstogov commented Nov 8, 2021

I can't guess what is wrong in your code, if you don't show it. In the following example the assignment works without problems. (I hope, you use ext/ffi bundled into PHP-7.4 or above. This git repo is outdated).

<?php
$ffi = FFI::cdef("
typedef int (*IFnii)(void*, int, int);
IFnii zend_printf;
");
function click_cb(FFI\CData $ih, FFI\CData $l, FFI\CData $c) {
      echo $lin = FFI::cast('int',$l)->cdata;
      echo $col = FFI::cast('int', $c)->cdata;
};
$ffi->zend_printf = "click_cb";
($ffi->zend_printf)("%d %d\n", 1, 2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants