Any in host classes

Started by
0 comments, last by WitchLord 18 years, 3 months ago
Hey Sorry for not spinning off one of the existing "any" discussions, but GameDev wouldn't let me reply to them. Anyway... I'd like to have an "any" member in a class defined in the host application (C++), and exposed to the script with RegisterObjectProperty. (Basically I want my script to be able to store user data in host objects.) Any ideas on how to do that? /Anders
Advertisement
You could have the class store a pointer to an asIScriptAny class and register it as a handle.

engine->RegisterObjectProperty("myclass", "any @user", offsetof(myclass,user));


You could also have the class automatically initialize this handle in the constructor by calling

int anyTypeId = engine->GetTypeIdByDecl(0, "any");this->any_obj = (asIScriptAny*)engine->CreateScriptObject(anyTypeId);


You may be able to register the any property as a reference to an any object. But I don't remember if I implemented support for that.

engine->RegisterObjectProperty("myclass", "any &user", offsetof(myclass,user));


Regards,
Andreas

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