Jump to content
  • Advertisement
Sign in to follow this  
jsol

Angel Code Newbie Question

This topic is 2985 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

Hello All First off I want to say that the angelscript sdk is very cool stuff. I've decided that I would like to add scripting to my application and this feels like the right solution. ok here's my question... I have a class
class Component
{
public:
    void setName (const CScriptString& componentName);
    Component* const getChildComponent (int index);
    void setBounds (int x, int y, int w, int h);
};

This is what I want the script to look like...
// Script...
void componentResized(Component& mainComponent)
{
    mainComponent.getChildComponent (1).setBounds (0, 0, 25, 25);
}

So for now I want the application to pass a reference of the mainComponent to the script. What's the proper way of doing this? How do I register the class? This is what I have so far in terms of "registration".
        int r = -1;

	// Register the class..
	r = getEngine()->RegisterObjectType ("Component", 
		0, 
		asOBJ_REF | asOBJ_NOHANDLE);

	assert (r >= 0);
	
	// Register the methods..
	r = getEngine()->RegisterObjectMethod ("Component", 
		"void setName(const string &in)", 
		asMETHOD (ProductPage, setName), 
		asCALL_THISCALL);
	assert (r >= 0);

	r = getEngine()->RegisterObjectMethod ("Component", 
		"Component& getChildComponent(int)", 
		asMETHOD (ProductPage, getChildComponent), 
		asCALL_THISCALL);
	assert (r >= 0);

	r = getEngine()->RegisterObjectMethod ("Component", 
		"void setBounds(int, int, int, int)", 
		asMETHODPR (ProductPage, setBounds, (int, int, int, int), void), 
		asCALL_THISCALL);
	assert (r >= 0);

This is what I'm getting when I compile the script: "Compiling void componentResized(Component&inout) Only object types that support object handles can use &inout. Use &in or &out instead" Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
asOBJ_NOHANDLE means that no handles, thus no references, can be held for this object. An object type registered with this flag can only be exposed to the script as a global property. This is usually used for singletons.

If you want the object to be passed as a parameter, then you need to register it as asOBJ_REF without asOBJ_HANDLE, and then register the asBEHAVE_ADDREF and asBEHAVE_RELEASE so that the number of active references to the object can be controlled.

If you don't care about the memory management (you should) you can register the behaviours as dummy functions that don't do anything.



Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!