Advertisement

Register method as global function

Started by August 07, 2011 08:05 PM
3 comments, last by WitchLord 13 years, 3 months ago
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)
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. :)

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

Too many projects; too much time

Advertisement

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 - Tower - free puzzle game


[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)
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 - Tower - free puzzle game

This topic is closed to new replies.

Advertisement