[m-users.] Undefined predicate in C FFI code, present in generated C file.
Sean Charles (emacstheviking)
objitsu at gmail.com
Thu Sep 21 17:16:55 AEST 2023
Hi,
I have a wrapper around a graphics library called Raylib, it has so far wrapped about 80 functions, then I added a new one and I am getting an undefined predicate error, it's the first one I've created that is 'semidet', although having experimented with the problem before this post, I don't think that's the cause, I've used SUCCESS_INDICATOR as specified, here is there predicate:
:- pred check_collision_point_circle(float::in, float::in, float::in, float::in, float::in) is semidet.
:- pragma foreign_proc(
"C", check_collision_point_circle(Px::in, Py::in, Cx::in, Cy::in, Radius::in),
[ promise_pure, will_not_call_mercury, will_not_throw_exception
, will_not_modify_trail, thread_safe, does_not_affect_liveness],
"
Vector2 point = { Px, Py };
Vector2 center = { Cx, Cy };
SUCCESS_INDICATOR = CheckCollisionPointCircle(point, center, Radius);
").
and here is the test code I added, the testing module concerned already correctly imports the raylib module, and has used many predicates from it without issue up until this point:
collision_detection(!S, !Player, !IO) :-
( if check_collision_point_cirle(
100.0, 100.0, 100.0, 100.0, 100.0, !IO
) then
trace [io(!IO2)] (
io.format("hit!\n", [], !IO2)
)
else
trace [io(!IO2)] (
io.format("miss :(\n", [], !IO2)
)
), ...
The error I get is:
level_ufo.m:240: In clause for predicate `collision_detection'/6:
level_ufo.m:240: error: undefined predicate `check_collision_point_cirle'/5.
** Error making `Mercury/cs/level_ufo.c'.
When I examine the generated C code I can see that the function is present:
MR_bool MR_CALL
raylib__check_collision_point_circle_5_p_0(
MR_Float Px_1,
MR_Float Py_2,
MR_Float Cx_3,
MR_Float Cy_4,
MR_Float Radius_5)
{
{
MR_bool succeeded;
{
#define MR_PROC_LABEL raylib__check_collision_point_circle_5_p_0
MR_Float Px;
MR_Float Py;
MR_Float Cx;
MR_Float Cy;
MR_Float Radius;
MR_bool SUCCESS_INDICATOR;
Px = Px_1 ;
Py = Py_2 ;
Cx = Cx_3 ;
Cy = Cy_4 ;
Radius = Radius_5 ;
{
Vector2 point = { Px, Py };
Vector2 center = { Cx, Cy };
SUCCESS_INDICATOR = CheckCollisionPointCircle(point, center, Radius);
;}
#undef MR_PROC_LABEL
succeeded = SUCCESS_INDICATOR;
}
return succeeded;
}
}
So I can't really see how I have managed to get it wrong!
What did I get wrong?
Thanks,
Sean.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20230921/fa9d47ea/attachment.html>
More information about the users
mailing list