Jump to content
  • Advertisement
Sign in to follow this  
Wizumer

Using C++ Classes within Scripts

This topic is 3155 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
Advertisement
Currently you can not inherit classes defined from c++. If you want to use the class you defined you can use it like

BaseEntity @entity = @BaseEntity();

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!