I've tried searching around google for this and couldn't find anything, so I apologize if this is a repeat.
I'm have a problem returning a reference to an internal class in AngelScript.
Basically I have a class like this:
class Engine
{
public:
AudioSystem& getAudioSystem()
{
return m_audioSystem;
}
private:
AudioSystem m_audioSystem;
};
int r= state->RegisterObjectType("Engine", 0, asOBJ_REF | asOBJ_NOCOUNT);
r = state->RegisterObjectMethod("Engine", "AudioSystem@ getAudioSystem()", asMETHODPR(Engine, getAudioSystem, (), AudioSystem&), asCALL_THISCALL); assert(r >= 0);
and AudioSystem like this
int result = state->RegisterObjectType("AudioSystem", 0, asOBJ_REF | asOBJ_NOCOUNT);
result = state->RegisterObjectMethod("AudioSystem", "bool addSound(const string &in, const string &in, const bool overwriteExisting = true, const bool useStoredPath = true, const bool isSoundEffect = false, const string extension = \".mp3\")",
asMETHOD(AudioSystem, addSound), asCALL_THISCALL);
result = state->RegisterObjectMethod("AudioSystem", "void playSound(const string &in, const int channel = 0, const bool loop = true, const float vol = 1.0)",
asMETHOD(AudioSystem, playSound), asCALL_THISCALL);
My angelscript looks like this
void main()
{
AudioSystem& as = engine.getAudioSystem();//.addSound("Dive into the Heart", "Dive into the Heart");
as.addSound("Dive into the Heart", "Dive into the Heart");
as.playSound("Dive into the Heart");
}
AudioSystem@ as = engine.getAudioSystem();
r = state->RegisterObjectMethod("Engine", "AudioSystem@ getAudioSystem()", asMETHOD(Engine, getAudioSystem), asCALL_THISCALL); assert(r >= 0);
Doing this seems to let me go further - I get in to the as.addSound() function call, but the AudioSystem instance it get's called on is uninitialized and not the AudioSystem instance inside Engine.
What am I doing wrong? Any help would be appreciated.
Thanks!