Sign in to follow this  
Shurwint

Simulate function/method call at run-time

Recommended Posts

Shurwint    122
Is there way to simulate a function/class method call at run-time? I need turn on/off some script functionality at run-time. f.e.: //C++ code int Summ( int a, int b) { return a + b; } //Script code: void test() { ... int a = 1; int b = 2; int c = 0; c = Summ(a, b); ... } Sometimes I would like the Summ() function acts like "Nothing to do": Turn on: c = 3; // Summ(a, b) executed Turn off: c = 0; // Execution of Summ(a, b) omitted I try next steps: 1. RegisterObjectMethod() with funcPointer=NULL (success) 2. Execute() fails at CallThisCallFunction() with func=NULL, there is exception at call[func] (as_callfunc_x86.cpp, line 1104).

Share this post


Link to post
Share on other sites
WitchLord    4677
You could register a dummy function.

I could change AngelScript to skip calls to functions that have been registered with a null pointer, but only if they've been registered with a void return type. If the function returns a value then AngelScript won't know what to do if the function isn't executed.

Share this post


Link to post
Share on other sites
Shurwint    122
If any function doesn't returns a value, but as specified in the function prototype - it must return a value - could AngelScript skip execution of whole line "c = Summ(a, b);"?

Is it possible to implement such behaviour?

Share this post


Link to post
Share on other sites
WitchLord    4677
Anything's possible, though I don't understand the benefit of this. This sounds like it would just confuse the users.

Can you help me understand the advantage of what you're asking?

Share this post


Link to post
Share on other sites
Shurwint    122
My app is based on plug-in and script systems.

Any Plugin:
- exports plugin functionality;
- may be in one of two states: started or stoped. (There is a simple check box in UI).

Any Script:
- calls at functions (app or plugin doesn't matter);

If script calls at function of "stopped plugin", script system must acts like "Nothing To Do" and skip whole expression.

Main idea - Do not re-write any script if some plugins are not used currently, but may be turned on later, just setting up check in UI.

Is it clear to you?

Share this post


Link to post
Share on other sites
WitchLord    4677
I'll have to give this some more thought.

In the mean time I think you can probably solve your problem by using a default plugin implementation, so that when a plugin is turned off your application switches to the default plugin instead (one that doesn't really do anything).

Share this post


Link to post
Share on other sites
Shurwint    122
>I'll have to give this some more thought.
>In the mean time I think you can probably solve your problem by using a default plugin implementation, so that when a plugin is turned off your application switches to the default plugin instead (one that doesn't really do anything).

Such plugin must have implementation all of the functions prototypes of all plugins? Plugins export functions prototypes are basically different from each other, so "default" plugin needs to be updated when a new plugin have been released.

Share this post


Link to post
Share on other sites
WitchLord    4677
Well, you know what functions each plugin is registering, so you can just substitute the null function pointers for a pointer to a default function with a generic calling convention:


void DoNothing(asIScriptGeneric *gen)
{
}


Being of the generic calling convention it can represent any global function and class member without any problems. It will also take care of the memory allocations for you, e.g. if an object handle is passed to the function, as the generic interface automatically releases it when returning.

Regards,
Andreas

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