Advertisement

Script class as return object

Started by July 21, 2010 04:32 PM
1 comment, last by WitchLord 14 years, 4 months ago
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.
Never mind, I just noticed the script object manipulation functions in asIScriptEngine...
Sorry for the noise.
Advertisement
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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement