🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Simulate function/method call at run-time

Started by
6 comments, last by WitchLord 16 years, 3 months ago
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).
Advertisement
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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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?
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?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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?
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).

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

>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.
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

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