define-foreign-callable
Hello,
We would need
a C function that, after receiving a MIDI event
from some
external MIDI device,
would in turn
call a Lisp function to notify LW that the system has
received a MIDI
event. After reading the FLI manual we tried to
solve this problem by using the LW 'define-foreign-callable' macro.
solve this problem by using the LW 'define-foreign-callable' macro.
To simulate this
behavior in C code we tried this :
int notify_lisp(int x)
{
return(x);
}
int receive_midi(int x)
{
notify_lisp(x);
return(0);
}
{
notify_lisp(x);
return(0);
}
The
foreign-callable LW code in turn is defined like this:
(fli:define-foreign-callable
("notify_lisp" :result-type :int)
((in-arg :int)) (print (format t "MIDI received ~a" in-arg)))
To test this from LW we do the following:
(fli:define-foreign-function (test-midi-info "receive_midi")
((in-arg :int)) :result-type :int)
But when calling:
(test-midi-info 60)
(fli:define-foreign-callable
("notify_lisp" :result-type :int)
((in-arg :int)) (print (format t "MIDI received ~a" in-arg)))
To test this from LW we do the following:
(fli:define-foreign-function (test-midi-info "receive_midi")
((in-arg :int)) :result-type :int)
But when calling:
(test-midi-info 60)
'test-midi-info'
returns only 0 and does not call the 'notify_lisp' function in Lisp as we
hoped.
Probably the C
function 'receive_midi' only calls the 'notify_lisp' that is defined
in C.
How can we force
the C function 'receive_midi' to call the
foreign-callable function 'notify_lisp' that would print the MIDI message in LW?
foreign-callable function 'notify_lisp' that would print the MIDI message in LW?
Do we need to deal
with function pointers in C, and if this is the case,
how can we pass a
function pointer of a foreign-callable from Lisp to C?
We are using LWM
4.3.7.
Any help
appreciated.
Mikael