Embedding ScriptBasic in FreeBASIC

User projects written in or related to FreeBASIC.
Site Admin
Posts: 5317
Joined: May 27, 2005 6:42
Location: Illinois

Postby cha0s » Sep 19, 2009 22:18

I think you guys are being lame as #%$@.

No one asked you what you think about embedding scripting languages into FreeBASIC. The fact that you'd even question doing it is indicative of your unsuitability to be on this topic in the first place.

John was just showing an example of how to embed a scripting language into FB. Take it as it is!

I think you guys go crazy because of some past issues you've had with John, but it's unacceptable far as I'm concerned.

That said, John I'd second the recommendation to check out Lua... I'm using it in a project currently. Well, to be fair I'm still grokking it, but it's pretty cool :)
Posts: 264
Joined: Jul 26, 2007 2:40

Postby Eponasoft » Sep 19, 2009 22:46

Lua is pretty decent but not really suited for high-performance apps IMHUO. Tis great for traditional RPGs though...Ruby makes a good candidate for that too (RPGXP anyone?).

cha0s, I don't really see anyone being out of line here. I just don't think jcfuller and aurelVZAB understand the purpose of embedded scripting languages. English doesn't seem to be their first languages.
John Spikowski
Posts: 453
Joined: Dec 24, 2005 2:32
Location: WA - USA

Postby John Spikowski » Sep 19, 2009 22:56

Thanks cha0s for the heads-up about Lua. I'm still struggling with C. ;-)

I thought ScriptBasic might be attractive to this group because you don't have to learn a new language syntax. I think SB did rather well in the All Basic QuickBasic compatible code challenge. (FreeBASIC require zero changes)

James is a long time PowerBASIC developer and beta tester. He has earned my respect years ago. As for Aurel, he should spend more time on promoting his interpreter in Russian forums where folks might understand what his point might be.
Posts: 342
Joined: Jul 02, 2008 14:55
Location: Croatia

Postby aurelVZAB » Sep 19, 2009 22:59

I understand very well what you or what he mean.
Rusia - ha ha i'm not from Rusia - you obviusly dont know nothing
about geography- maby becose you speak only one language -ha ha...
But i'm really tired of that man speaches - if you wana this use SB if you
wana that use SB - it looks that we all need just SB for everything.
That is the point of universe....experts.....
Posts: 255
Joined: Jan 05, 2006 0:56

Postby BastetFurry » Sep 20, 2009 0:12

This. Is. Cool!
John Spikowski
Posts: 453
Joined: Dec 24, 2005 2:32
Location: WA - USA

Postby John Spikowski » Sep 20, 2009 16:27

I put a zip together for embedding ScriptBasic in your FreeBASIC application. This code was generated by Charles Pegge and part of the All Basic code challenge.

Code: Select all

#include once "windows.bi"
#include once "win/ole2.bi"
#include once "scriba.bi"

Dim as long pProgram,iError

function newmem CDECL (ByVal le As Long) As bstr Export
  function=SysAllocStringByteLen (0,le)
end function

sub freemem CDECL (ByVal p As bstr) Export
  SysFreeString p
end sub

SetConsoleTitle "FreeBasic ScriptBasic Embedding Test"

pProgram=scriba_new (cast(long,@newmem), cast(long,@freemem))

This example shows running a simple ScriptBasic script from FreeBASIC. I (or Charles) will post an example of loading a SB script of functions and subs and calling them from a FB application and allowing access to the scripts variables.

Project Files

Note: If you want to run the FB_embeds.exe included in the zip, you should first download the Windows version of ScriptBasic from the www.scriptbasic.org/forum (downloads) and unzip it in your root of C: which will create a C:\scriptbasic directory. Make sure your grab the zip of open source DLL libraries used by the ScriptBasic extension modules. (see last post in SB Windows download sticky post)

The SB install zip contains a default scriba.conf that is referenced in the example. If you haven't installed ScriptBasic and want to try the example, remove the reference to scriba.conf and recompile the example.
John Spikowski
Posts: 453
Joined: Dec 24, 2005 2:32
Location: WA - USA

Postby John Spikowski » Sep 23, 2009 0:12

I was curious if anyone here on the forum gave ScriptBasic a try with FreeBASIC? ScriptBasic comes as a console mode interpreter if you want to work with the scripting language before trying to embed it in your application.
Posts: 135
Joined: Aug 29, 2008 21:13

Postby Hard » Sep 23, 2009 0:38

actually i did. i think the idea behind it is great (usability, syntax). but i hate dlls and the whole installation stuff of scriba and so ill continue to use lua ...
John Spikowski
Posts: 453
Joined: Dec 24, 2005 2:32
Location: WA - USA

Postby John Spikowski » Sep 23, 2009 5:42

You can link to libscriba.lib statically if using the DLL is not your cup of tea. The Windows download contains per-compiled binaries and there is no need to install anything. Just unzip and run. If you add the C:\scriptbasic\bin directory to your path, you can run the command line interpreter from anywhere.

It couldn't be any simpler other then me doing your programming for you. ;-)
Posts: 74
Joined: Feb 12, 2007 10:19
Location: Wales

Postby cevpegge » Sep 23, 2009 9:15


If you wanted to distribute embedded ScriptBasic with an FB application, what files would you need to include apart from libscriba.dll and the manual?(assuming no extension modules were needed.)


PS: I have a more developed example in the pipeline demonstrating access to SB global variables and also passing parameters to and from SB functions.
- might need to make a few adjustments to the header file for easier pointering.
John Spikowski
Posts: 453
Joined: Dec 24, 2005 2:32
Location: WA - USA

Postby John Spikowski » Sep 23, 2009 9:43


Only libscriba.dll is needed to embed ScriptBasic in FreeBasic for Windows. Under Linux you may need to link in pthreads and the lmt_none.c stub (or equivalent)

If you want to static link you will need to install ScriptBasic which includes the source.

Glad to hear you made progress with ScriptBasic embedding to use a set of functions and subs and access to the scripts variables.

When your done, I'll show in a few lines of code a script returning a results set in an array from a MySQL database. (using a SB extension module)

Thanks for all your help with the SB embedding in the popular Windows Basic compilers.
Posts: 74
Joined: Feb 12, 2007 10:19
Location: Wales

Postby cevpegge » Sep 24, 2009 10:10

This is not quite so minimalist - it demonstrates how to access global variables and pass parameters to and from ScriptBasic functions and get return values. - Just about all you need for embedding SB into an FB application.


PS: updated `A` file and header file included.

http://www.allbasic.info/forum/index.ph ... 35#msg2735
Posts: 1759
Joined: May 23, 2007 21:52
Location: Cut Bank, MT

Postby notthecheatr » Sep 24, 2009 20:04

I love Lua, but I'll certainly take a look at this.

Basic syntax is always a nice thing, and being able to embed it in FreeBASIC is extremely helpful.
Posts: 61
Joined: Jul 15, 2005 21:11
Location: Oregon, USA

Postby Michael » Sep 24, 2009 20:19

For those who have to ask about why you would add scripting obviously, you don't have have a need for it. However you all use applications that depend almost entirely on scripts, such as your web browser, mIRC, Office, etc. Digest this for just a second; without scripting your web browser would be totally useless because no-one is going to download a web page and recompile it for viewing.
John Spikowski
Posts: 453
Joined: Dec 24, 2005 2:32
Location: WA - USA

Postby John Spikowski » Sep 24, 2009 21:04

I haven't tried Lua but ScriptBasic is available as a feature rich command line interpreter as a variation and is a great way to run/debug your scripts before embedding them in your application. I use the command line interpreter for all my utility/cron projects. (Linux) I use the multithreaded webserver variation as my server side scripting engine that includes session support.

The extension module interface API is a tight integration with the Basic and allows you expand the functionality of the language with other libraries available. The distribution comes with MySQL, PostgreSQL, ODBC/iODBC, Berkely DB, cURL, libxml2, zlib along with other SB specific extensions as part of the package.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 4 guests