Sign in to follow this  

Using C++ Classes within Scripts

This topic is 2849 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 guys, Realise this might be a bit of a stupid question, but although the C++ code for exposing a class to AngelScript is available all over the place, I can't seem to find an example of how to use such a class in the actual .as file. I have set all the factory functions and (I think) covered all the bases as regards exposing the class, but when I try to use it in AngelScript by simply using the class name, it gives an error. Below is the C++ code:
#include "f_baseentity.h"
#include "f_script.h"
#include "angelscript.h"

BaseEntity::BaseEntity()
{
	refCount = 1;
}

BaseEntity* Ref_Factory()
{
	return new BaseEntity();
}

void BaseEntity::Addref()
{
	refCount++;
}

void BaseEntity::Release()
{
	if( --refCount == 0 )
		delete this;
}

BaseEntity::~BaseEntity()
{
}

void BaseEntity::RegisterClass(FScript *script)
{
	asIScriptEngine *engine = script->getEngine();
	engine->RegisterObjectType("BaseEntity", 0, asOBJ_REF);
	engine->RegisterObjectBehaviour("BaseEntity", asBEHAVE_FACTORY, "BaseEntity@ f()", asFUNCTION(Ref_Factory), asCALL_CDECL);
	engine->RegisterObjectBehaviour("BaseEntity", asBEHAVE_ADDREF, "void f()", asMETHOD(BaseEntity, Addref), asCALL_THISCALL);
	engine->RegisterObjectBehaviour("BaseEntity", asBEHAVE_RELEASE, "void f()", asMETHOD(BaseEntity, Release), asCALL_THISCALL);
}
I have tried a number of things in AngelScript, including inheritance, and also defining a class in AS with the same name and then inheriting from that, but no dice. Any help is much appreciated.

Share this post


Link to post
Share on other sites

This topic is 2849 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this