Ok, so I'd like to know if using function pointers in the design of my scripting engine would be a good way to go. My idea is that each command in the command set has a corresponding function pointer that is referenced and then called whenever the command is executed by the actual engine. Are there any major disadvantages to using this approach and are there any speed costs?
Function Pointers In A Scripting Engine
Page 1 of 11 Replies - 200 Views - Last Post: 11 September 2012 - 09:36 AM
Replies To: Function Pointers In A Scripting Engine
#2
Re: Function Pointers In A Scripting Engine
Posted 11 September 2012 - 09:36 AM
Is your scripting engine meant to run single threaded or multithreaded? If your engine is single threaded, are you allowed to have multiple engine instances in different threads? Should the functions being pointed to by the engine support being re-entered by multiple threads?
With the use of function pointers there is the overhead of the indirection. Will there be cases of functions being called in tight loops? Are you willing to pay the price of that indirection?
Do you know ahead of time what the function signature will look like for every command in your command set? A command that looks like "LOOKAT(closestThreat)" will probably have a different signature than "PROMPT('What is your first and last name?', firstName, lastName)".
In general, yes, function pointers will work. What will be better, though, would be to follow the Command design pattern. http://en.wikipedia....Command_pattern
With the use of function pointers there is the overhead of the indirection. Will there be cases of functions being called in tight loops? Are you willing to pay the price of that indirection?
Do you know ahead of time what the function signature will look like for every command in your command set? A command that looks like "LOOKAT(closestThreat)" will probably have a different signature than "PROMPT('What is your first and last name?', firstName, lastName)".
In general, yes, function pointers will work. What will be better, though, would be to follow the Command design pattern. http://en.wikipedia....Command_pattern
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|