Code: Select all
/* Copyright (c) 2007 Scott Lembcke
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
typedef struct cpVect{
float x,y;
} cpVect;
#define cpvzero ((cpVect){0.0f, 0.0f})
static inline cpVect
cpv(const float x, const float y)
{
return (cpVect){x, y};
}
static inline cpVect
cpvadd(const cpVect v1, const cpVect v2)
{
return cpv(v1.x + v2.x, v1.y + v2.y);
}
static inline cpVect
cpvneg(const cpVect v)
{
return cpv(-v.x, -v.y);
}
static inline cpVect
cpvsub(const cpVect v1, const cpVect v2)
{
return cpv(v1.x - v2.x, v1.y - v2.y);
}
static inline cpVect
cpvmult(const cpVect v, const float s)
{
return cpv(v.x*s, v.y*s);
}
static inline float
cpvdot(const cpVect v1, const cpVect v2)
{
return v1.x*v2.x + v1.y*v2.y;
}
static inline float
cpvcross(const cpVect v1, const cpVect v2)
{
return v1.x*v2.y - v1.y*v2.x;
}
static inline cpVect
cpvperp(const cpVect v)
{
return cpv(-v.y, v.x);
}
static inline cpVect
cpvproject(const cpVect v1, const cpVect v2)
{
return cpvmult(v2, cpvdot(v1, v2)/cpvdot(v2, v2));
}
static inline cpVect
cpvrotate(const cpVect v1, const cpVect v2)
{
return cpv(v1.x*v2.x - v1.y*v2.y, v1.x*v2.y + v1.y*v2.x);
}
static inline cpVect
cpvunrotate(const cpVect v1, const cpVect v2)
{
return cpv(v1.x*v2.x + v1.y*v2.y, v1.y*v2.x - v1.x*v2.y);
}
extern inline float cpvlength(const cpVect v);
extern inline float cpvlengthsq(const cpVect v);
extern inline cpVect cpvnormalize(const cpVect v);
extern inline cpVect cpvforangle(const float a);
extern inline float cpvtoangle(const cpVect v);
extern char *cpvstr(const cpVect v);
gives me this fb header:
Code: Select all
''
''
'' cpVect -- header translated with help of SWIG FB wrapper
''
'' NOTICE: This file is part of the FreeBASIC Compiler package and can't
'' be included in other distributions without authorization.
''
''
#ifndef __cpVect_bi__
#define __cpVect_bi__
type cpVect
x as single
y as single
end type
type cpVect as any
declare function cpvdot cdecl alias "cpvdot" (byval v1 as cpVect, byval v2 as cpVect) as single
declare function cpvcross cdecl alias "cpvcross" (byval v1 as cpVect, byval v2 as cpVect) as single
declare function cpvlength cdecl alias "cpvlength" (byval v as cpVect) as single
declare function cpvlengthsq cdecl alias "cpvlengthsq" (byval v as cpVect) as single
declare function cpvtoangle cdecl alias "cpvtoangle" (byval v as cpVect) as single
declare function cpvstr cdecl alias "cpvstr" (byval v as cpVect) as zstring ptr
#endif
I know I have to change "type cpVect as any" to "type cpVect as any ptr"
I'm not sure what to do with "#define cpvzero ((cpVect){0.0f, 0.0f})". It looks like its defining something with a casted type. How do I handle that?
As far as the function definitions go, I don't mind recoding them, if that's what I have to do, but I'm not sure how to handle those return values. Any help?
Also, another translation seems a bit odd to me.
.h:
Code: Select all
typedef int (*cpHashSetEqlFunc)(void *ptr, void *elt);
typedef void *(*cpHashSetTransFunc)(void *ptr, void *data);
typedef void (*cpHashSetIterFunc)(void *elt, void *data);
typedef int (*cpHashSetRejectFunc)(void *elt, void *data);
to .bi:
Code: Select all
type cpHashSetEqlFunc as function cdecl(byval as any ptr, byval as any ptr) as integer
type cpHashSetTransFunc as sub cdecl(byval as any ptr, byval as any ptr)
type cpHashSetIterFunc as sub cdecl(byval as any ptr, byval as any ptr)
type cpHashSetRejectFunc as function cdecl(byval as any ptr, byval as any ptr) as integer
That looks like some pretty spooky pointer referencing going on there. Did swig get this one right?
Thanks for any help you can offer!