Skip to main content
GameDev.net gamedev.net
🔒 Locked

Register method as global function

Started by dutt Aug 7, 2011 at 8:05 PM 3 replies 2.7k views
Original Post
dutt
dutt
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:


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


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

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

After a little bit of searching I found this, is that still the state?
[size="1"]trassel (thread lib)
jacmoe
jacmoe
This is what I'm using:
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);



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


D'oh - didn't read the other topic in depth - my post doesn't really apply, does it?
Too many projects; too much time
WitchLord
WitchLord

After a little bit of searching I found this, is that still the state?


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.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
dutt
dutt

[quote name='dutt' timestamp='1312747518' post='4845879']
After a little bit of searching I found this, is that still the state?


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?
[size="1"]trassel (thread lib)
WitchLord
WitchLord
I tend to focus on the features that cannot easily be accomplished from the application side, so this addition is quite low on my to-do list.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.