Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Variable Functions

Author
Message
Mew151
18
Years of Service
User Offline
Joined: 1st Jun 2008
Location: Glitch city
Posted: 16th Apr 2010 03:00
Basically I want to know if DBPro supports (and it probably doesn't) variable functions. (http://www.php.net/manual/en/functions.variable-functions.php) If not, is there some way to run commands written in a string?

Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 16th Apr 2010 09:24
Quote: "Basically I want to know if DBPro supports (and it probably doesn't) variable functions"


Nope

Quote: "If not, is there some way to run commands written in a string?"


You'd have to parse them out manually. There's some plug in's that implement function pointers, which could make the task a little easier, but it's still going to be a bit of messing around.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Apr 2010 15:49
Supported by plug-ins, then you can do it. Here's a link to the help files for my own function pointer plug-in, which I believe is the most feature-complete one available: http://www.matrix1.demon.co.uk/Matrix1Utils_Help/Matrix1Util_20_index.html

It allows you to call functions by name or by pointer, and to pass variable numbers of parameters although it's your responsibility to pass and read the correct type (being as DBPro is a statically typed language).

It also provides coroutines so that you can switch between functions at will, no matter where execution is within those functions - useful for running long functions but where you need to keep quick response times in your main program for example.

Mew151
18
Years of Service
User Offline
Joined: 1st Jun 2008
Location: Glitch city
Posted: 16th Apr 2010 16:30
Thanks! I'll try it out!

So on coroutines you could, basically run two functions at once?
(By switching between functions)

basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 16th Apr 2010 19:03
remember that DBpro is not a scripting language. even if you decided to use a dll to support your argument, the dll will use a string reading then will use a pointer manipulation which will slow the program run time.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Apr 2010 20:28
It won't have as much effect as you might think. For a one-off call (such as during initialisation), then you may as well use function names. However if you are planning to call a function pointer over and over again, then use the name to get the address, then use the address instead.

The overhead of function pointers is relatively low - for example, I wouldn't replace 1 or 2 if statements with a jump table of function pointers, but over that, then yes it would definitely be a consideration.



Quote: "So on coroutines you could, basically run two functions at once?"

Yes. I have an incomplete example somewhere on my hard-drive where I load some terrain data, and create and populate a multi-limbed object from that data, and while doing so, keep a fixed frame rate.

The function that does this runs in its own coroutine. When initiated, it creates a blank object then yields control, then loads the data and yields control, then in a loop, updates each limb data, yielding control each time the current limb is completed, then finally, carries out a few final settings before yielding control again. This will then be repeated for any other object creation requests that have been made.

This would work just as well with any other long-running process, for example path-finding.

If I can track down the code for this then I'll post it.

Login to post a reply

Server time is: 2026-07-26 07:36:15
Your offset time is: 2026-07-26 07:36:15