Hi all,
I'm still trying to interface the same c++ 3d engine with gambit and I
am currently encountering some problems which seems out of my range of
knowledge... I'm currently trying to define a type corresponding to a 2d
position which I would like to interface with a simple scheme vector.
Here is the code I wrote for it:
(c-declare #<<c-declare-end
typedef position2d<s32> position2d_s32;
___SCMOBJ SCMOBJ_to_POSITION2D_S32 (___SCMOBJ src, position2d_s32
*dst, int arg_num)
{
___SCMOBJ ___err = ___FIX(___NO_ERR);
___SCMOBJ ___temp;
if (!(___S32VECTORP(src) && (___S32VECTORLENGTH(src) == ___FIX(2))))
___err = ___FIX(___UNKNOWN_ERR);
else
{
dst->X = ___S32VECTORREF(src,___FIX(0));
dst->Y = ___S32VECTORREF(src,___FIX(1));
}
return ___err;
}
___SCMOBJ POSITION2D_S32_to_SCMOBJ (position2d_s32 src, ___SCMOBJ
*dst, int arg_num)
{
___SCMOBJ ___err = ___FIX(___NO_ERR);
*dst = ___alloc_scmobj (___sS32VECTOR, 2<<3, ___STILL);
if (___FIXNUMP(*dst))
___err = ___FIX(___CTOS_HEAP_OVERFLOW_ERR+arg_num);
else
{
___S32VECTORSET(*dst,___FIX(0),src.X)
___S32VECTORSET(*dst,___FIX(1),src.Y)
}
return ___err;
}
#define ___BEGIN_CFUN_SCMOBJ_to_POSITION2D_S32(src,dst,i) \
if ((___err = SCMOBJ_to_POSITION2D_S32 (src, &dst, i)) ==
___FIX(___NO_ERR)) {
#define ___END_CFUN_SCMOBJ_to_POSITION2D_S32(src,dst,i) }
#define ___BEGIN_CFUN_POSITION2D_S32_to_SCMOBJ(src,dst) \
if ((___err = POSITION2D_S32_to_SCMOBJ (src, &dst, ___RETURN_POS))
== ___FIX(___NO_ERR)) {
#define ___END_CFUN_POSITION2D_S32_to_SCMOBJ(src,dst) \
___EXT(___release_scmobj) (dst); }
#define ___BEGIN_SFUN_POSITION2D_S32_to_SCMOBJ(src,dst,i) \
if ((___err = POSITION2D_S32_to_SCMOBJ (src, &dst, i)) ==
___FIX(___NO_ERR)) {
#define ___END_SFUN_POSITION2D_S32_to_SCMOBJ(src,dst,i) \
___EXT(___release_scmobj) (dst); }
#define ___BEGIN_SFUN_SCMOBJ_to_POSITION2D_S32(src,dst) \
{ ___err = SCMOBJ_to_POSITION2D_S32 (src, &dst, ___RETURN_POS);
#define ___END_SFUN_SCMOBJ_to_POSITION2D_S32(src,dst) }
c-declare-end
)
(c-define-type position2d_s32 "position2d_s32"
"POSITION2D_S32_to_SCMOBJ"
"SCMOBJ_to_POSITION2D_S32"
#f)
This code is a mere quasi-copy of one of Marc Feeley's code which
originally was:
(c-declare #<<c-declare-end
___SCMOBJ SCMOBJ_to_VECTOR3DF (___SCMOBJ src, vector3df *dst, int
arg_num)
{
___SCMOBJ ___err = ___FIX(___NO_ERR);
___SCMOBJ ___temp;
if (!(___F64VECTORP(src) && (___F64VECTORLENGTH(src) == ___FIX(3))))
___err = ___FIX(___UNKNOWN_ERR);
else
{
dst->X = ___F64VECTORREF(src,___FIX(0));
dst->Y = ___F64VECTORREF(src,___FIX(1));
dst->Z = ___F64VECTORREF(src,___FIX(2));
}
return ___err;
}
___SCMOBJ VECTOR3DF_to_SCMOBJ (vector3df src, ___SCMOBJ *dst, int
arg_num)
{
___SCMOBJ ___err = ___FIX(___NO_ERR);
*dst = ___alloc_scmobj (___sF64VECTOR, 3<<3, ___STILL);
if (___FIXNUMP(*dst))
___err = ___FIX(___CTOS_HEAP_OVERFLOW_ERR+arg_num);
else
{
___F64VECTORSET(*dst,___FIX(0),src.X)
___F64VECTORSET(*dst,___FIX(1),src.Y)
___F64VECTORSET(*dst,___FIX(2),src.Z)
}
return ___err;
}
#define ___BEGIN_CFUN_SCMOBJ_to_VECTOR3DF(src,dst,i) \
if ((___err = SCMOBJ_to_VECTOR3DF (src, &dst, i)) ==
___FIX(___NO_ERR)) {
#define ___END_CFUN_SCMOBJ_to_VECTOR3DF(src,dst,i) }
#define ___BEGIN_CFUN_VECTOR3DF_to_SCMOBJ(src,dst) \
if ((___err = VECTOR3DF_to_SCMOBJ (src, &dst, ___RETURN_POS)) ==
___FIX(___NO_ERR)) {
#define ___END_CFUN_VECTOR3DF_to_SCMOBJ(src,dst) \
___EXT(___release_scmobj) (dst); }
#define ___BEGIN_SFUN_VECTOR3DF_to_SCMOBJ(src,dst,i) \
if ((___err = VECTOR3DF_to_SCMOBJ (src, &dst, i)) ==
___FIX(___NO_ERR)) {
#define ___END_SFUN_VECTOR3DF_to_SCMOBJ(src,dst,i) \
___EXT(___release_scmobj) (dst); }
#define ___BEGIN_SFUN_SCMOBJ_to_VECTOR3DF(src,dst) \
{ ___err = SCMOBJ_to_VECTOR3DF (src, &dst, ___RETURN_POS);
#define ___END_SFUN_SCMOBJ_to_VECTOR3DF(src,dst) }
c-declare-end
)
(c-define-type vector3df "vector3df"
"VECTOR3DF_to_SCMOBJ"
"SCMOBJ_to_VECTOR3DF"
#f)
Marc's code worked perfectly fine, but mine compiles from scm to c, but
won't from .c to object file .o. The error message I get from g++ is the
following:
gsc -c irr-interface.scm
g++ -rdynamic -I/opt/g4/current/include
-I/home/dave/irrlicht-1.3/include -I/usr/X11R6/include
-D___SINGLE_HOST -O3 -ffast-math -c irr-interface.c
irr-interface.c: In function ‘int SCMOBJ_to_POSITION2D_S32(int,
position2d_s32*, int)’:
irr-interface.c:995: error: ‘___s32_temp’ was not declared in this scope
irr-interface.c:995: error: ‘___hp’ was not declared in this scope
irr-interface.c: In function ‘int
POSITION2D_S32_to_SCMOBJ(position2d_s32, int*, int)’:
irr-interface.c:1009: error: ‘___temp’ was not declared in this scope
I don't understant why the almost exact same definitions works with
F64VECTOR but not with S32VECTOR... Can anyone help me??
Thank you!
David St-Hilaire