Jump to content
  • Advertisement
Michael Marchesan

Having issues adding a class method

Recommended Posts

Hi,

i'm trying to add angelscript to my graph viewing program; the scripts should be written by the user to interact with the graph in the program itself.

Both graph and nodes already exist in the program, and the script shouldn't be able to delete them or create new ones directly. However the graph should have a couple methods through which the script can do so.

in C++ graph.add_node() adds a node to the graph and returns a pointer to it, graph.remove_node(node*) removes the node. graph.get_first_node() returns a pointer to the first node in the list, as starting point for algorithms. node.get_neighbour(unsigned int n) returns a pointer to the nth node connected to that node.

But when i try to register any of these methods that return a pointer to a node i get errors.

engine->RegisterObjectType("graph", 0, asOBJ_REF);
engine->RegisterObjectType("node", 0, asOBJ_REF);

engine->RegisterObjectBehaviour("graph", asBEHAVE_ADDREF, "void f()", asMETHOD(graph, AddRef), asCALL_THISCALL);
engine->RegisterObjectBehaviour("graph", asBEHAVE_RELEASE, "void f()", asMETHOD(graph, ReleaseRef), asCALL_THISCALL);
engine->RegisterObjectBehaviour("node", asBEHAVE_ADDREF, "void f()", asMETHOD(graph::node, AddRef), asCALL_THISCALL);
engine->RegisterObjectBehaviour("node", asBEHAVE_RELEASE, "void f()", asMETHOD(graph::node, ReleaseRef), asCALL_THISCALL);

engine->RegisterObjectMethod("graph", "int test()", asMETHOD(graph, test), asCALL_THISCALL);
engine->RegisterObjectMethod("graph", "node* get_first_node()", asMETHOD(graph, get_first_node), asCALL_THISCALL);
engine->RegisterObjectMethod("node", "int test()", asMETHOD(graph::node, test), asCALL_THISCALL);

engine->RegisterGlobalProperty("graph g", g);

Error: Failed in call to function 'RegisterObjectMethod' with 'graph' and 'node* get_first_node()' (Code: asINVALID_DECLARATION, -10)

It does so with and without *

What am i doing wrong?

Share this post


Link to post
Share on other sites
Advertisement

Write it as "node@" instead. Handles (pointers) are denoted with an @ in Angelscript instead of a *.

Share this post


Link to post
Share on other sites
8 minutes ago, Miss said:

Write it as "node@" instead. Handles (pointers) are denoted with an @ in Angelscript instead of a *.

ouch i must have missed that part in the docs, thanks!

Share this post


Link to post
Share on other sites

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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!