Plugin ( C++) Calling constructor of a class

Started by habi2, Dec 02, 2024, 12:03 PM

Previous topic - Next topic

habi2

Hi in this short tutorial i will show you how to create an instance of a class. We are creating one from 'blob' class.
I will just paste the entire code:
SQInteger fn_test_blob(HSQUIRRELVM v)
{
int top = sq->gettop(v);
sq->pushroottable(v);
sq->pushstring(v, "blob", -1);
if (SQ_SUCCEEDED(sq->get(v, -2)))
{
//We have class on top
sq->pushnull(v); //dummy parameter for constructor's this parameter ref http://squirrel-lang.org/squirreldoc/reference/api/calls.html
sq->call(v, 1, SQTrue, SQTrue);
return 1;
}
else return sq->throwerror(v, "Failed getting blob class from root table");
return 0;
}
The point to be noted is how pushing a dummy parameter( we pushed null) to call constructor.
I hope this will be useful for anybody in future.