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 / DBPro functions into a DLL?

Author
Message
Starshyne Emir
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 10th Feb 2018 02:16
Is there a way to convert directly a set of DBPro functions into a DLL to be used in further projects?

In some other languages, the compilers are fully prepared to convert pure code into useable DLLs, what allows the users to pack their custom made functions easily and reuse them in the future with ease. What I want is a way to do the same in DBPro. Can I? I have TONS of functions I use often and I am tired of re-writing them every new project I start. I want something easier, so I can pack everything into a single file - and them, much probably, share it here so anyone can take benefit of the stuff I made.
[size=+2]Forever and one[/size]
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 10th Feb 2018 14:41
With c++ you can make a dll for dbpro to use as a plugin.

There is a plugins board with some info, and some info in the help docs, but to be honest, I've never had much luck in getting it to work.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 10th Feb 2018 22:39 Edited at: 10th Feb 2018 22:40
DBPro doesn't support creating pre-compiled libraries that can be used by different projects.
The closest you'll get (without funky workarounds; I think someone was working on precompilation via memory copying from executables here a year or two ago, however the DBP runtime performs runtime linking so you'd have to keep that in mind; I don't remember how they dealt with that) is probably to make a master include file and store it in some appropriate directory, say DBPro\Projects\Common\MyLibrary.dba.
This file would in turn look something like so:

Now you'd just have to include that one MyLibrary.dba file in your projects.

This would still have to be fully compiled along with your project each time, but you wouldn't have to copy source files and link them to the main project as much (if you plan on making per-project specific changes that would of course be the recommended way about it though, but I assume you're not).
Starshyne Emir
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 12th Feb 2018 21:01
Rudolpho, let me see if I got your point:

I make a project with all the functions I want to use and then include its .dba files where I need to reuse them. Just that? But they are in different folders, does DBPro keeps track of them?
If is it so, you solved my problem quite easily.
[size=+2]Forever and one[/size]
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Feb 2018 22:12
Starshyne Emir wrote: "But they are in different folders, does DBPro keeps track of them?"

Well no, but you could put a lot of #include "C:\Absolute\Path\To\Source.dba" entries in one master include file, that you preferably keep in some convenient location and then you only have to include that one in your other projects. But yes, you may have to use the full paths to include the other files from there.
Also the #include directive can be a bit buggy with the official DBPro releases at times.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 12th Feb 2018 22:14 Edited at: 12th Feb 2018 22:17
I literally unveiled this whole concept here:
https://forum.thegamecreators.com/thread/220759
Modular Programming

I was sick and tired of making terrible lists and half made UI elements. So I packed everything into a .dba file with simple include. Everything is efficient, polished, and simple 1 line function calls. Now I get awesome mouse support, scrolling lists, auto complete textboxes, file load/save dialogs, bitmap text and a ton of other stuff. All of these controls and functionality are written generically so the functionality can just be dropped into a new program right away.
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 12th Feb 2018 22:39 Edited at: 12th Feb 2018 22:43
I'll add one more comment since this is some top level stuff when using #include.

When including a second DBA file, you are probably going to want to use some additional global variables or arrays which aren't declared or used in the main source code. You will find that ignoring this problem, and simply adding those declarations to the top of the included dba doesn't work. Copying/moving those declarations to the main source file sucks and defeats the purpose of using #include. The solution is to place all of those declarations into an initialization function in the included dba file. Then in the main source after including the dba, call the initialization function. This will cause all of your included dba's global declarations to be processed. Both the main source and the included dba will have access to these global variables after that.

You also should know about Array Insert At Bottom and Dim. You can use Dim on an existing 1 or 2 dimensional array and keep the contents, resizing the array. This is helpful when creating an efficient system.

Rudolpho wrote: "Well no, but you could put a lot of #include "C:\Absolute\Path\To\Source.dba" entries in one master include file"

You can use relative paths too. Helpful when simply dropping the file into the same directory as the main dba file.

Rudolpho wrote: "Also the #include directive can be a bit buggy with the official DBPro releases at times."

I have not run into this. I don't doubt some people may have had problems since you never know. However this could also possibly be that they did not do things correctly like mentioned above. I generally suggest NEVER using the DBPRO file, or side bar menu to setup includes or anything else like display mode since these settings don't show up in the main source code, making the code harder to follow.

The link I mentioned above demonstrates these concepts.
Starshyne Emir
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 13th Feb 2018 13:42 Edited at: 13th Feb 2018 14:22
Thank you Mage and Rudolpho, you made my day!

Now packing my functions all together into a master file following your directions.

EDIT:

Well, it works partially. I tried to use #include with the full path of the .dba file and it didn't work. Then, I copied the .dba to the directory of my current project and it works perfectly. The only boring thing is: it doesn't highlight the functions included. I believe it is the usual behaviour of DBPro and that there is nothing I can do to solve, but it is boring anyway.
[size=+2]Forever and one[/size]
Mage
17
Years of Service
User Offline
Joined: 3rd Feb 2007
Location: Canada
Posted: 14th Feb 2018 03:55
Starshyne Emir wrote: "Well, it works partially. I tried to use #include with the full path of the .dba file and it didn't work. Then, I copied the .dba to the directory of my current project and it works perfectly."

I told you so.

Starshyne Emir wrote: "The only boring thing is: it doesn't highlight the functions included. I believe it is the usual behaviour of DBPro and that there is nothing I can do to solve, but it is boring anyway."

This is a problem since you will forget the names of functions, forget the arguments being passed to the functions, and forget the values being returned from them. This will make programming less convenient and more difficult. I addressed this by writing help documents that organized all of the functions, listed their purpose, arguments, and return values. So I can quickly lookup any information I need without searching the included .dba.

Alternatively you can use the DBPRO file to automatically include the dba like Rudolpho said (and I advised against). This will cause the included dba file to appear as an extra tab in the Synergy editor. This can make searching the included dba more convenient if you aren't going to write documentation. This method does not use an #include statement in the main source.

In any case having good naming conventions for your functions will help you greatly.

If your included dba file is constantly causing errors/crashing/experimental.
You will be better off simply disabling the include and pasting the dba into the end of you main source file temporarily to make it easier to find the proper line numbers.



Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 14th Feb 2018 04:33 Edited at: 14th Feb 2018 04:44
user functions are never highlighted in DBPro just by declaring/including the function.

However! You can create a keywords file very easily in the case of a standard include module that you will use on a regular basis (I did this for Advanced Lighting)

just create an .ini file like "starshyne_lib.ini"

put it in DBpro\editor\keywords\

and fill it with your functions like so:

[functionName]=[helpFilePath]=([parameters])



in the IDE you may need to click 'rebuild key words' in the menu options.

If you want to go all out, pop some associated .html help files into DBpro\Help\ to enable F1 support

Enjoy
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Starshyne Emir
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 15th Feb 2018 06:14
Great! Really easy, indeed.
Guess I'll implement those keywords to help me while coding.
Thank you. You - as always - were of very much help!
[size=+2]Forever and one[/size]
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 23rd Feb 2018 16:04
Yes, good suggestion Ortu. Thanks .
Zep
21
Years of Service
User Offline
Joined: 31st Aug 2002
Location: From PA, USA. Currently reside in Hanoi, Vietnam
Posted: 23rd Feb 2018 22:04
Quote: "user functions are never highlighted in DBPro just by declaring/including the function.
"


I think it may also depend on what Editor you are using. I'm using Synergy and my functions auto-highlight without making a keyword file.

Login to post a reply

Server time is: 2024-03-28 17:26:58
Your offset time is: 2024-03-28 17:26:58