• Create Account

#Actualslicer4ever

Posted 13 June 2013 - 10:14 AM

my problem is described in the generic handle documentation, but i don't know how to implement it.

this is basically what i do, each object is given an local pool of memory, the script can say how big that pool is. what i want to do, is create a struct, or class, with each script, get the size of the class, and tell my object to create a pool of memory for this class to occupy, then the script can request the pool, typecast it to the local class, and modify objects/memory in that pool directly.

it'd look like this:

c++ code:

class Obj{
private:
char *m_Buffer;
public:
void CreateBuffer(int size){
m_Buffer = new char[size];
}

char *GetBuffer(void){ //i tried registering this as an ref object, with the scripthandler add-on.
return m_Buffer;
}

//construct/destructors.
};

as script:

class Data{
int x;
};

void Update(Obj @A){
Data @D = cast<Data@>(A.GetBuffer());
print("x: "+D.x);
}

void Initialize(Obj @A){
A.CreateBuffer(sizeof(Data)); //is there anyway to get the size of an class?
Data @D = cast<Data@>(A.GetBuffer());
D.x = 0;
};

anywho, this causes angelscript to crash. any pointers on how to achieve this?

#1slicer4ever

Posted 13 June 2013 - 10:14 AM

my problem is described in the generic handle documentation, but i don't know how to implement it.

this is basically what i do, each object is given an local pool of memory, the script can say how big that pool is. what i want to do, is create a struct, or class, with each script, get the size of the class, and tell my object to create a pool of memory for this class to occupy, then the script can request the pool, typecast it to the local class, and modify objects/memory in that pool directly.

it'd look like this:

c++ code:

class Obj{
private:
char *m_Buffer;
public:
void CreateBuffer(int size){
m_Buffer = new char[size];
}

char *GetBuffer(void){ //i tried registering this as an ref object, with the scripthandler add-on.
return m_Buffer;
}

//construct/destructors.
};

as script:


class Data{
int x;
};

void Update(Obj @A){
Data @D = cast<Data@>(A.GetBuffer());
print("x: "+D.x);
}

void Initialize(Obj @A){
A.CreateBuffer(sizeof(Data));
Data @D = cast<Data@>(A.GetBuffer());
D.x = 0;
};

anywho, this causes angelscript to crash. any pointers on how to achieve this?

PARTNERS