Sign in to follow this  

"?&in" to function?

This topic is 2049 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

Hello! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

So, a create GUI in game engine, and need use callback's

cur time i use this code:

[CODE]
class SomeClass
{
void MyCallbackFuciton() {}

void Load()
{
GetWidget( "Start" ).AddEvent( "MyCallbackFuciton" );
}
}

c++:

r = en->RegisterObjectMethod(type,"void AddEvent( const string &)",asMETHOD( T, AddEvent), asCALL_THISCALL ); assert( r >= 0 );

void AddEvent( const std::string &_method )
{
asIScriptContext *ctx = asGetActiveContext();
asIObjectType *obj_type = ctx->GetEngine()->GetObjectTypeById( ctx->GetThisTypeId() );

// get method by name
funcId = obj_type->GetMethodByName( method.c_str() );
}

[/CODE]
whether it is possible to make so?


[CODE]
class SomeClass
{

void MyCallbackFuciton() {}

void Load()
{
GetWidget( "Start" ).AddEvent( MyCallbackFuciton );
}

}

c++:

r = en->RegisterObjectMethod(type,"void AddEvent( func_id or int or asIScriptFunction or.. )",asMETHOD( T, AddEvent), asCALL_THISCALL ); assert( r >= 0 );

void AddEvent( int _funct_id or asIScriptFunction *_fucnt )
{
// ...
}

[/CODE]
all sense in checking correctness at a compilation stage

i.e. this code work, but no correct GetWidget( "Start" ).AddEvent( "MyCallbackFuciton_ololo" ); Edited by FDsagizi

Share this post


Link to post
Share on other sites
[quote name='FDsagizi' timestamp='1336112196' post='4937298']
Hello! [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

So, a create GUI in game engine, and need use callback's

cur time i use this code:

[CODE]
class SomeClass
{
void MyCallbackFuciton() {}

void Load()
{
GetWidget( "Start" ).AddEvent( "MyCallbackFuciton" );
}
}

c++:

r = en->RegisterObjectMethod(type,"void AddEvent( const string &)",asMETHOD( T, AddEvent), asCALL_THISCALL ); assert( r >= 0 );

void AddEvent( const std::string &_method )
{
asIScriptContext *ctx = asGetActiveContext();
asIObjectType *obj_type = ctx->GetEngine()->GetObjectTypeById( ctx->GetThisTypeId() );

// get method by name
funcId = obj_type->GetMethodByName( method.c_str() );
}

[/CODE]
whether it is possible to make so?


[CODE]
class SomeClass
{

void MyCallbackFuciton() {}

void Load()
{
GetWidget( "Start" ).AddEvent( MyCallbackFuciton );
}

}

c++:

r = en->RegisterObjectMethod(type,"void AddEvent( func_id or int or asIScriptFunction or.. )",asMETHOD( T, AddEvent), asCALL_THISCALL ); assert( r >= 0 );

void AddEvent( int _funct_id or asIScriptFunction *_fucnt )
{
// ...
}

[/CODE]
all sense in checking correctness at a compilation stage

i.e. this code work, but no correct GetWidget( "Start" ).AddEvent( "MyCallbackFuciton_ololo" );
[/quote]

i asked the same question last night :)

check my post.

not as easy as passing a function pointer.

Share this post


Link to post
Share on other sites
[quote name='saejox' timestamp='1336126399' post='4937334']
i asked the same question last night

check my post.

not as easy as passing a function pointer.
[/quote]


It would be very convenient!
Let's wait for the new version![img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

Share this post


Link to post
Share on other sites
Without support for delegates in the language (on to-do list), the best solution is to use interfaces. Interfaces will provide the proper compile time checks that you're looking for.

Example:

[code]

// This interface should be registered by the application
interface IWidgetEventHandler
{
void Callback();
}


class SomeClass : IWidgetEventHandler
{
// The class is guaranteed to implement the Callback method, since it implements the inteface
void Callback() {}

void Load()
{
// The AddEvent method takes a handle to IWidgetEventHandler
GetWidget( "Start" ).AddEvent( this );
}
}

//c++:

r = en->RegisterObjectMethod(type,"void AddEvent(IWidgetEventHandler @+)",asMETHOD( T, AddEvent), asCALL_THISCALL ); assert( r >= 0 );

void AddEvent( asIScriptObject *obj )
{
asIObjectType *obj_type = obj->GetObjectType();

// The object type is guaranteed to be a IWidgetEventHandler
funcId = obj_type->GetMethodByName( "Callback" );
}
[/code]

Share this post


Link to post
Share on other sites

This topic is 2049 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.

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