Sign in to follow this  
dutt

Register method as global function

Recommended Posts

I'm writing a ScriptManager c++ class that has a registerType(string& name) method that I would like to register as a global function in the script.

I've got RegisterGlobalFunction working for global methods and I could use a proxy function or make it static but I'm wondering if there's a proper way to do this.


registerEntitypType looks like this:
[code]

void ScriptManager::registerEntityType(string& name) {
cout <<"Registering type \"" <<name <<"\"" <<endl;
}
[/code]

I've tried both of these:
[code]r = mEngine->RegisterGlobalFunction("void registerType(string& in)", asFUNCTION(&ScriptManager::registerEntityType), asCALL_CDECL);[/code]

[code]r = mEngine->RegisterGlobalFunction("void registerType(string& in)", asMETHOD(ScriptManager, registerEntityType), asCALL_THISCALL); [/code]

After a little bit of searching I found [url="http://www.gamedev.net/topic/591814-funcdefs-to-member-functions/"]this[/url], is that still the state?

Share this post


Link to post
Share on other sites
This is what I'm using:
[code] int r;
r = mEngine->RegisterObjectType("ScriptManager", 0, asOBJ_REF | asOBJ_NOHANDLE); assert( r >= 0);
r = mEngine->RegisterObjectMethod("ScriptManager", "void registerEntityType(string)", asMETHOD(ScriptManager, registerEntityType, asCALL_THISCALL); assert( r >= 0);
// Register the singleton's address that the script will use to access it
r = mEngine->RegisterGlobalProperty("ScriptManager scriptmanager", this); assert( r >= 0);
[/code]


You could of course change the way you register the type of the class, but the RegisterGlobalProperty is the function you need. :)

<edit>
D'oh - didn't read the other topic in depth - my post doesn't really apply, does it?
</edit> Edited by jacmoe

Share this post


Link to post
Share on other sites
[quote name='dutt' timestamp='1312747518' post='4845879']
After a little bit of searching I found [url="http://www.gamedev.net/topic/591814-funcdefs-to-member-functions/"]this[/url], is that still the state?
[/quote]

Yes. Unfortunately, this is still the case.

If you want the method to look like a global function in the script you need to use a proxy function.

Share this post


Link to post
Share on other sites
[quote name='WitchLord' timestamp='1312755647' post='4845933']
[quote name='dutt' timestamp='1312747518' post='4845879']
After a little bit of searching I found [url="http://www.gamedev.net/topic/591814-funcdefs-to-member-functions/"]this[/url], is that still the state?
[/quote]

Yes. Unfortunately, this is still the case.

If you want the method to look like a global function in the script you need to use a proxy function.
[/quote]

Ok, I might register a system object and put all my globals in that instead then. "system.registerType" is almost as good as just "registerType".

Do you have a rough idea when you might find the time to include support for registering methods as global functions?

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

Sign in to follow this