1 Replies - 200 Views - Last Post: 11 September 2012 - 09:36 AM Rate Topic: -----

#1 halfahack  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 18
  • Joined: 10-December 09

Function Pointers In A Scripting Engine

Posted 11 September 2012 - 07:27 AM

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?
Is This A Good Question/Topic? 0
  • +

Replies To: Function Pointers In A Scripting Engine

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 1939
  • View blog
  • Posts: 5,774
  • Joined: 05-May 12

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1