Skip to main content
gamedev.net
🔒 Locked

Binding user data to iScriptGeneric

Started by pifor106 Sep 15, 2010 at 10:38 AM 3 replies 900+ views
Original Post
pifor106
pifor106
Hi !

I'm currently developping a meta programming system for the registration of class which takes automatically of the generation of generic bindings if and only if the AX_MAX_PORTABILITY is set. Otherwise, the native calling convention is used.

This makes the following possible in C++ code:

Class< MyClass > class("MyClass")
[
MemberFunction( "void DoSomethingA()", MyClass::&DoSomethingA ),
MemberFunction( "void DoSomethingB()", MyClass::&DoSomethingB )
];

GlobalRegistry registry(GetASEngine());

class.Register(registry);

Ultimately, a single function is called for each member function receiving a asIScriptGeneric* pointer when I compile on a platform with AS_MAX_PORTABILITY defined.

template< InvokerType >
void GenericMemberFunctionDispatch( asIScriptGeneric* generic )
{
ASSERT( generic, "AngelScript failed to provide a generic interface.");

MarshallingAgent agent(generic);

InvokerType invoker(functionPtr);
invoker(agent);
}

I'll spare you the details of the Invoker system, which is heavy on meta-programming ( but we have used it extensively in other areas of our pipeline and in other instances where we did integrate scripting solutions ).

However, I have a small (huge) problem. I need to pass a function pointer to the invoker, the real function to call actually.

I either have two choices :

Maintain a mapping of function id to function pointer : I don't particularly like this solution since I'll probably generate a lot of cache misses due to the nature of a map object and that would pain me dearly.

Add user data to a function registration, i.e.: in my case the function ptr. Therefore I could do :

InvokerType invoker(generic->GetUserData());

I know that you're probably wondering : What the hell, why isn't he using the autowrapper ?

Well, mainly, because I want to keep it as simple as possible for people to register their object types and the system in all circumstances, without having to worry about the generic convention, since I work with some platforms not yet supporting the native calling convention.

So, do you think it would be possible to add a user data as an optional parameter ? If so I might get to it !

registry->RegisterObjectMethod(GetName(), asFUNCTION((GenericMemberFunctionInvoker)), asCALL_GENERIC, m_functionPtr);

WitchLord
WitchLord
I can add a SetUserData/GetUserData method pair to the asIScriptFunction interface. This would allow you to store the information you want to have available to the asIScriptGeneric interface.

This would also be available for script functions, and not just registered functions, if anyone would like to store some extra information for functions obtained from the script (e.g. meta data).

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
pifor106
pifor106
Hi !

That's what I've started doing as well. I was thinking of modifying asCScriptFunction and adding a void* SetUserData/GetUserData and modifying both the asIScriptGeneric and asIScriptFunction interface to expose the parameter.

Is that fine with you ?

If so I'll send the code afterwards.

Quote:
Original post by WitchLord
I can add a SetUserData/GetUserData method pair to the asIScriptFunction interface. This would allow you to store the information you want to have available to the asIScriptGeneric interface.

This would also be available for script functions, and not just registered functions, if anyone would like to store some extra information for functions obtained from the script (e.g. meta data).


pifor106
pifor106
I'd like your input on the idea as well. If you think that I'm really doing something I shouldn't be then feel free to comment :)
WitchLord
WitchLord
Rather than changing the asIScriptGeneric to add the GetUserData method, change it to have a GetFunctionDescriptor method (instead of GetFunctionId).

The user data would be accessible with:

void *userData = generic->GetFunctionDescriptor()->GetUserData();


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.