Yep, I'm back already with more questions! (I should probably write up a tutorial of my own after all this. ;) )
Okay, so I'm having a bit of trouble using objects instantiated from classes from the host C++ program. I was able to successfully expose my ScriptingEngine object from before; however, I'm getting some errors/lockups when it comes to creating a new object within AS from a class I exposed. Here's my code:
C++ code
r = engine->RegisterObjectType("CondVar", sizeof(CondVar), asOBJ_CLASS); assert (r >= 0);
r = engine->RegisterObjectMethod("CondVar", "void Set_Name(string)", asMETHOD(CondVar,Set_Name), asCALL_THISCALL); assert (r >= 0);
r = engine->RegisterObjectMethod("CondVar", "void Set_Value(string)", asMETHOD(CondVar,Set_Name), asCALL_THISCALL); assert (r >= 0);
r = engine->RegisterObjectMethod("CondVar", "string Get_Name()", asMETHOD(CondVar,Get_Name), asCALL_THISCALL); assert (r >= 0);
r = engine->RegisterObjectMethod("CondVar", "string Get_Value()", asMETHOD(CondVar,Get_Value), asCALL_THISCALL); assert (r >= 0);
CondVar definition
class CondVar : public Object
{
public:
CondVar() {}
CondVar(string n, string v) { name = n; value = v; }
~CondVar() {}
// accessors
void Set_Name(string n) { name = n; }
void Set_Value(string n) { value = n; }
string Get_Name() { return name; }
string Get_Value() { return value; }
private:
string name,
value;
};
AS function that's being called (ignore the part about taking floats; it originally did a calculation and printed it)
void PrintResult(float x, float y)
{
CondVar cv;
cv.Set_Name("foo");
cv.Set_Value("bar");
}
As you can see, CondVar is just a simple key, with a string name and a string value. Whenever I type a command to have PrintResult() called, I get the whole "Send error report to Microsoft" deal. I thought at first that it could be that I needed to register the Object class as well, but I tried and to no avail. Plus, now that I better (but not *much* better) understand how AS method registration works, it wouldn't make sense to have to do that.
Am I missing something here?
Thanks in advance for your help, as always.