Hi There
I'm trying to pass arrays from angelscript to C - and having a few problems
The problems being it doesn't work at all - doesn't fill the vec array - and probably will eventually crash - I can't really tell what is going - because the C code is compiled at run time and my shabby system has no really debugging at the moment.
here's my C code:
typedef struct
{
int maxElements;
int numElements;
unsigned char data[1];
} SArrayBuffer;
typedef struct
{
int refCount;
_Bool gcFlag;
void* objType;
SArrayBuffer* buffer;
int elementSize;
int subTypeId;
} ASarray;
void Init(void)
{
Debug("TCC init called");
//asRegisterGlobalFunction("float TestFunk(float)",TestFunk);
//asRegisterGlobalFunction("vec3 vectest(vec3)",vectest);
//asRegisterGlobalFunction("vec3 vecpointer(const vec3 &in)",vecpointer);
asRegisterGlobalFunction("void vecfill(vec3[]@,int)",vecfill);
}
void vecfill(ASarray *a,int l)
{
vec3* v=(vec3*)a->buffer->data;
for (int a=0;a<l;a++)
{
v[a].x=counter++;
v[a].y=counter++;
v[a].z=counter++;
}
}
here's my angelscript code
array<vec3> TestArray(50);
vecfill(TestArray,2);
I am doing it this way because 1) I want to be able to pass arrays anonymously without having to define a specific class or struct
2) I'm using TCC so the C code is compile at runtime - it's actually called from angelscript:
ExecuteTCC("./NewDir2/Test.c","Init");
I realise this is probably as dodgy as hell - but it's not a commercial thing, pure R&D - so I just hope it is possible.
thanks!