Advertisement

Angel Code Newbie Question

Started by April 15, 2010 01:23 AM
0 comments, last by WitchLord 14 years, 7 months ago
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 ∈ or &out instead" Thanks in advance!
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.



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