Hello! Is it posible to attach my data to Squirrel table?
Here is the C++ code for piece creation.
class Piece
{
public:
HSQOBJECT mScriptObject;
};
int createPiece(HSQUIRRELVM v)
{
Piece* piece = new Piece();
sq_newtable(v); //create table
//set the table's data to piece
sq_pushstring(v, "ID", -1);
sq_pushinteger(v, 2);
sq_newslot(v, -3, SQFalse);
sq_resetobject(&piece->mScriptObject); //initialize the handle
sq_getstackobj(v,-1,&piece->mScriptObject); //retrieve an object handle from the pos –2
sq_addref(v,&piece->mScriptObject); //adds a reference to the object
return 1;
}
And to delete piece, I use this:
int bgwDestroyPiece(HSQUIRRELVM v)
{
Piece* piece;
//get user data of table
sq_release(v,&piece->mScriptObject); //relese the object
delete piece;
return 0;
}
Here is how it looks in Squirrel scripts:
local piece = createPiece();
piece.posX <- 10;
destroyPiece(piece);
I don't want user to be able to change the user data of the table and I
need it to be table, so that script can add slots to table like this:
piece.posX <- 10. Is it possible with Squirrel?
Thanks in advance!