• Advertisement
Sign in to follow this  

Script class as return object

This topic is 2774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I 'm playing around with Angelscript and I 've hit a problem.

I follow the "Using script classes" page in the docs (http://www.angelcode.com/angelscript/sdk/docs/manual/doc_use_script_class.html) and to this end I have declared a script class named CTest.
I can get its factory function and call it which effectively creates a new script object for me of type CTest.

Now I want to call a method of that instance (CTest::test()). According to the docs, I have to use ctx->SetObject() accordingly for use as the 'this' pointer in the script.

The problem I 'm having is that I have to copy the returned object from the factory function (as mentioned in http://www.angelcode.com/angelscript/sdk/docs/manual/doc_call_script_func.html) before I can use it in the same context as an argument of ctx->SetObject().
In order for me to copy this object though I need to know its C-side type so I can cast it to the correct type. Is there a C-side class for script classes? Or, how can I copy the returned object (from the factory method call)?

I have only managed to accomplish what I 'm after by using a second context to make the method call on the instance. Is that the only solution?

Thanks a lot for any help in advance,
Yiannis.

Share this post


Link to post
Share on other sites
Advertisement
Never mind, I just noticed the script object manipulation functions in asIScriptEngine...
Sorry for the noise.

Share this post


Link to post
Share on other sites
Yes, the only way to create a script object is by calling the factory using a asIScriptContext. The factory will return the script object handle, which can be manipulated through the asIScriptObject interface.

The asIScriptEngine::CreateScriptObject can be used to create script objects, however, internally it will create the asIScriptContext anyway.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement