Author Topic: ScriptBasic 2.1 Beta for Windows - SETUP (Reference Only - Use current source)  (Read 48513 times)

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
This zip file contains the Windows 2.1 setup built by Peter Verhas. The 2.1 version of ScriptBasic was never officially released by Peter. There have been a couple changes since the setup.exe and cab file were built. I have included an updates directory that contains the application server (sbhttpd.exe) and MySQL extension module. (mysql.dll)  Replace the installed version with these updated copies.

ScriptBasic 2.1.1 for Windows  

Note: The setup dialog will indicate that the version being installed is 2.0 which is incorrect. (scriba -v will show 2.1 for the interpreter)

Extension Module Summary
  • BDB - Berkeley DB
  • CGI - CGI helper functions
  • CIO - Console mnemonics
  • cURL - libcurl is a free and easy-to-use client-side URL transfer library, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE. libcurl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, Kerberos4), file transfer resume, http proxy tunneling and more!
  • DBG - ScrptBasic debugger (console and CGI interactive) A Windows GUI version is currently being tested.
  • DYC - This extension allow ScriptBasic to access DLL's without having to created an extension module.
  • GD - GD is an open source code library for the dynamic creation of images by programmers.
  • HASH - A hash is a set of key value pairs. Each value appearing in a hash is assigned to a key when entered into the hash and can be retrieved knowing the key.
  • MT - This module provides session support and interprocess global variables. It is used with the ScriptBasic HTTP application server.
  • MYSQL - C API interface to the MySQL database engine.
  • NT - This module implements some Win32 system calls that are not implemented in the core of ScriptBasic but can be helpful for those who want to write system maintenance scripts using ScriptBasic.
  • ODBC - Open standard database access interface. (Windows / unixODBC)
  • PSQL - PostgreSQL interface module
  • RE - Regular expression handling functions
  • T - Misc functions that didn't fit in the core language and ended up in the (T)oolbox
  • TRIAL - Example extension module to show you how to build your own.
  • XML - Functions that allow you to read/write/create XML data.
  • ZLIB - A free, general-purpose, legally unencumbered -- that is, not covered by any patents -- lossless data-compression library for use on virtually any computer hardware and operating system.
These modules require external libraries that may need to be installed for the extension module to work. All other modules have static linked the libraries as part of the extension module.


Building multi-platform GUI applications with GTK and ScriptBasic



What is GTK+?

GTK+ is a highly usable, feature rich toolkit for creating graphical user interfaces which boasts cross platform compatibility and an easy to use API. GTK+ it is written in C, but has bindings to many other popular programming languages such as C++, Python and C# among others. GTK+ is licensed under the GNU LGPL 2.1 allowing development of both free and proprietary software with GTK+ without any license fees or royalties.

Stability

GTK+ has been developed for over a decade to be able to deliver the enticing features and superb performance that it brings to your application development. GTK+ is supported by a large community of developers and has core maintainers from companies such as Red Hat, Novell, Imendio and Opened Hand.

Cross Platform

Originally GTK+ was developed for X Windows but it has grown over the years to include backend support for other well known windowing systems. Today you can use GTK+ on:
  • GNU/Linux and Unix
  • Windows
  • Mac OS X
I have assembled into one zip (8 MB) everything you need for GTK development with ScriptBasic.
  • GTK runtime for Windows
  • GTK-server for Windows
  • Glade-3 GUI designer
  • libglade - Load Glade XML project files with a few lines of code.
Download GTK for Windows
« Last Edit: September 13, 2009, 02:37:19 AM by support »

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
GTK Installation Tips
« Reply #1 on: April 21, 2008, 06:45:32 PM »
The following tips will help you get your GTK development environment going from the bundled zip provided in the previous post.

1. The first step is to run the gtk-2.12.9-win32-2.exe GTK+ runtime installer. Once this is completed you can run the demo provided from the Windows start menu.

Widget Gallery
GTK+ Reference Manual

2. Next we are going to install the Glade 3 GUI designer. Unzip the glade-3-0-2-win32-1.zip file into your C:\GTK directory. This will overlay the sub-directory structure already in place created with step 1. You will need to create a short-cut on your desktop manually with the C:\GTK\bin\glade-3.exe program.

Glade Screen Shots

3. In this step we are going to update the libglade files with the most recent versions. Unzip the libglade-2.6.2.zip file into your C:\GTK\bin directory.

ScriptBasic GTK Glade Example


Code: [Select]

' Glade Hello World

' GTK Interface
include gtk.bas

' Initialize GTK & Glade
gtk_init("NULL", "NULL")
glade_init

' Load and show Glade defined window
xml = glade_xml_new("hello.glade")
glade_xml_signal_autoconnect(xml)

' Get window ID and define window close event
win = glade_xml_get_widget(xml, "window1")
gtk_server_connect(win, "delete-event", "window")

' Event Handler
REPEAT
    this_event = gtk_server_callback("WAIT")
UNTIL this_event = "window"

END

Glade XML Project File
Code: [Select]

<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

<glade-interface>

<widget class="GtkWindow" id="window1">
  <property name="visible">True</property>
  <property name="title" translatable="yes">Hello</property>
  <property name="type">GTK_WINDOW_TOPLEVEL</property>
  <property name="window_position">GTK_WIN_POS_NONE</property>
  <property name="modal">False</property>
  <property name="default_width">400</property>
  <property name="default_height">350</property>
  <property name="resizable">True</property>
  <property name="destroy_with_parent">False</property>
  <property name="decorated">True</property>
  <property name="skip_taskbar_hint">False</property>
  <property name="skip_pager_hint">False</property>
  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
  <property name="focus_on_map">True</property>
  <property name="urgency_hint">False</property>

  <child>
    <widget class="GtkFixed" id="fixed1">
      <property name="visible">True</property>

      <child>
   <widget class="GtkLabel" id="label1">
     <property name="width_request">122</property>
     <property name="height_request">17</property>
     <property name="visible">True</property>
     <property name="label" translatable="yes">Hello World !</property>
     <property name="use_underline">False</property>
     <property name="use_markup">False</property>
     <property name="justify">GTK_JUSTIFY_LEFT</property>
     <property name="wrap">False</property>
     <property name="selectable">False</property>
     <property name="xalign">0.5</property>
     <property name="yalign">0.5</property>
     <property name="xpad">0</property>
     <property name="ypad">0</property>
     <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
     <property name="width_chars">-1</property>
     <property name="single_line_mode">False</property>
     <property name="angle">0</property>
   </widget>
   <packing>
     <property name="x">128</property>
     <property name="y">128</property>
   </packing>
      </child>
    </widget>
  </child>
</widget>

</glade-interface>

4. Finally we are going to install GTK-server which is the interface for ScriptBasic to use GTK.

http://www.gtk-server.org

A. Run the gtk-server-2.2.3-installer.exe program.
B. Copy the C:\GTK-server\Modules\Scriptbasic\gtk-server.dll to the C:\scripbasic\modules directory.
C. Copy the C:\GTK-server\Modules\Scriptbasic\gtk.bas file to the C:\scripbasic\include directory.
D. Copy the C:\GTK-server\Modules\Scriptbasic\*.sb ScriptBasic programs to the C:\scripbasic\examples diectory. Note that there is a demo.sb from the ScriptBasic install that should be renamed prior to the copy.

The final step is to add the GTK_SERVER_CONFIG=C:\GTK-server\gtk-server.cfg environment variable. This is done via your Windows control panel --> System --> Advanced --> Environment Variables button.

REBOOT to have the changes take affect.

You should now be able to run the ScriptBasic GTK examples.

Peter's dictionary.sb GTK ScriptBasic example. (Windows)


Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
XAMPP for Windows
« Reply #2 on: April 21, 2008, 07:08:00 PM »


The fastest way to install MySQL, phpMyAdmin, PHP and Apache with an easy to administer control panel is to install XAMPP for Windows.



Download Installer

I will be using this install method to interface with the ScriptBasic extensions and application server. This will give you a local web server and MySQL database to develop with.

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
Testing Apache with ScriptBasic
« Reply #3 on: April 22, 2008, 12:33:50 AM »
The next step in our setup process is to test if ScriptBasic (scriba.exe) can be used for CGI programming. The following echo.bas ScriptBasic CGI program will display the POST/GET header and environment variables by running itself.

Copy this program and place it in your C:\xampp\cgi-bin directory.
Code: [Select]

#!C:/scriptbasic/bin/scriba.exe -c
global const nl = "\n"
Const NumberOfCookies = 3

include cgi.bas

option cgi$Method cgi::Get or cgi::Upload

' cgi::RequestBasicAuthentication "login password"
cgi::Header 200,"text/html"

'
' We are setting several cookies. The expiry time is ten seconds so you can test that
' the cookies are sent by the browser if you press some of the buttons fast enough,
' but it does not if you are slow
'
for i=1 to NumberOfCookies
  ' cookie(i) is i, no domain is defined, path is /, expires after 10 seconds, not secure
  cgi::SetCookie "cookie" & i,i,undef,"/",gmtime()+10,false
next i

cgi::FinishHeader

'-------------------------------------------------------
print """<HTML>
<HEAD>
<title>CGI parameter testing</title>
</HEAD>
<BODY><font face="VERDANA" size="2">
<H1>View CGI Parameters</H1>
This page shows the cgi parameters the way it was uploaded.
<!-- here is the result of the previous HTTP request -->
<FONT SIZE="3">
<PRE>

CGI system variables
--------------------

"""
'-------------------------------------------------------

print "ServerSoftware  = ",cgi::ServerSoftware(), nl
print "ServerName      = ",cgi::ServerName(), nl
print "GatewayInterface= ",cgi::GatewayInterface(),nl
print "ServerProtocol  = ",cgi::ServerProtocol(), nl
print "ServerPort      = ",cgi::ServerPort(), nl
print "RequestMethod   = ",cgi::RequestMethod(), nl
print "PathInfo        = ",cgi::PathInfo(), nl
print "PathTranslated  = ",cgi::PathTranslated(), nl
print "ScriptName      = ",cgi::ScriptName(), nl
print "QueryString     = ",cgi::QueryString(), nl
print "RemoteHost      = ",cgi::RemoteHost(), nl
print "RemoteAddress   = ",cgi::RemoteAddress(), nl
print "AuthType        = ",cgi::AuthType(), nl
print "RemoteUser      = ",cgi::RemoteUser(), nl
print "RemoteIdent     = ",cgi::RemoteIdent(), nl
print "ContentType     = ",cgi::ContentType(), nl
print "ContentLength   = ",cgi::ContentLength(), nl
print "UserAgent       = ",cgi::UserAgent(), nl
print "Cookie          = ",cgi::RawCookie(), nl

print "Referer         = ",cgi::Referer(),nl
print "Password        = ",Environ("HTTP_PASSWORD"),nl
print "Full auth string= ",Environ("HTTP_AUTHORIZATION"),nl
print "\nCookies:\n"
for i=1 to NumberOfCookies
  print "cookie" & i," ",cgi::Cookie("cookie" & i),"\n"
next i

print "Text field using Param(\"TEXT-FIELD\") is ",cgi::Param("TEXT-FIELD"),nl,nl


if cgi::RequestMethod() = "GET" then
  print "GET text field using GetParam(\"TEXT-FIELD\") is ",cgi::GetParam("TEXT-FIELD"),nl
end if

if cgi::RequestMethod() = "POST" then
  print "POST text field using PostParam(\"TEXT-FIELD\") is ",cgi::PostParam("TEXT-FIELD"),nl
  if cgi::ContentType() like "multipart*" then
    print "Original file name is ",cgi::FileName("FILE-UPLOAD-NAME"),nl
    if cgi::FileLength("FILE-UPLOAD-NAME") > 0 then
      print "File of length ",cgi::FileLength("FILE-UPLOAD-NAME")," bytes is saved\n"
      on error goto NoSave
      cgi::SaveFile "FILE-UPLOAD-NAME",""
    else
      print "There is no uploaded file."
    end if
  end if
end if

print """</PRE><TABLE><TR><TD BORDER=0 BGCOLOR="EEEEEE"><PRE>
A simple form to POST parameters:<BR>
<FORM METHOD="POST" ACTION="/cgi-bin/echo.bas">
<INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
<INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE=" POST ">
</FORM>
</PRE></TD><TD BORDER=1 width="20">&nbsp;</TD><TD BORDER=0 BGCOLOR="EEEEEE"><PRE>
A simple form to GET parameters:<BR>
<FORM METHOD="GET" ACTION="/cgi-bin/echo.bas">
<INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
<INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE=" GET ">
</FORM>
</PRE></TD></TR></TABLE><PRE>
<hr>
A simple form to UPLOAD a file:<BR>
<FORM METHOD="POST" ACTION="/cgi-bin/echo.bas" ENCTYPE="multipart/form-data">
<INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
<INPUT TYPE="FILE" VALUE="FILE-UPLOAD-VALUE" NAME="FILE-UPLOAD-NAME">
<INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE="UPLOAD FILE">
</FORM>
<hr>
</BODY>
</HTML>
"""
stop
NoSave:

print "An error has happened saving the file. Code =",error(),nl

resume next


This is what the output should look like after a post.


Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
MySQL Testing
« Reply #4 on: April 23, 2008, 12:47:13 AM »
I guess this would be a good time to test the MySQL XAMPP install with ScriptBasic. XAMPP installed a demo CD Collection MySQL database that is used in this example.



Database: cdcol - Table: cds


Code: [Select]

' mycds.sb

INCLUDE mysql.bas

dbh = mysql::RealConnect("localhost","root","","cdcol")
mysql::query(dbh,"SELECT * FROM cds")

WHILE mysql::FetchHash(dbh,flds)
  PRINT flds{"titel"} & " | " & flds{"interpret"} & " | " & flds{"jahr"} & " | " & flds{"id"} & "\n"
WEND

mysql::Close(dbh)

END

Code: [Select]

C:\scriptbasic\examples>mycds
Beauty | Ryuichi Sakamoto | 1990 | 1
Goodbye Country (Hello Nightclub) | Groove Armada | 2001 | 4
Glee | Bran Van 3000 | 1997 | 5

C:\scriptbasic\examples>


Note: While the above code is a simple way to dump a table to the console, in a production environment you would want to use the mysql::Connect("Accounting") method. "Accounting" is a name you assign in the scriba.conf to a MySQL definition key.
Code: [Select]

mysql (
  connections (
    Accounting ( ; the name of the connection
 host "127.0.0.1" ; the host for the connection
 db "ABC" ; database for the connection
 user "accountant" ; user for the connection
 password "PostIt" ; password for the connection
 port 0 ; the port to use
 socket "" ; the name of the socket or ""
 flag 0 ; the client flag
 clients 10 ; how many clients to serve before really closing the connections
 )
    )
  )


The mysql::FetchHash() function is a nice feature using ScriptBasic's associative arrays when working with one table. This makes your code more readable when referring to columns by name. When using joins or other complex SQL statements, you can use the mysql::FetchArray() function to load the result set row into a normal array.

P.S.

Don't forget to copy the mysql.dll from the updates directory that was included in the ScriptBasic install zip and replace C:\scriptbasic\modules\mysql.dll with the updated version.

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
ScriptBasic Application Server Install
« Reply #5 on: April 23, 2008, 10:36:08 PM »
In this post I will show how to install the ScriptBasic application server. (sbhttpd.exe) Just like scriba.exe, the sbhttpd.exe application server uses the scriba.conf file for it's configuration. The file is in a binary format created with the scriba -k option. For this demonstration, we are going to use a minimal server configuration and add other options later.

The first step is to save a text copy of the current scriba.conf file. This is done using the following console mode command in the C:\scriptbasic\bin directory.

scriba -D > scriba.conf.save

Copy the below configuration to a scriba.conf.txt file in your C:\scriptbasic\bin directory. We need to convert this text version of scriba.conf to it's needed binary form.

scriba -k scriba.conf.txt

This will create a new binary scriba.conf file that ScriptBasic needs.
Code: [Select]

dll ".dll"
module "c:\\scriptbasic\\modules\\"
include "c:\\scriptbasic\\include\\"
docu "c:\\scriptbasic\\doc\\"
maxinclude 100
maxstep 0
maxlocalstep 0
maxlevel 3000
maxmem 0
servers (
  server (
    port 8080
    ip "127.0.0.1"
    protocol "http"
  )  
  threads 20
  listenbacklog 3
  home "C:\\xampp\\htdocs\\app-bin\\"
  proxyip 1
  pid (
    file "c:\\scriptbasic\\httpdlog\\pid.txt"
    delay 10
    wait (
      period 10
      length 1
     )
   )
  vdirs (
    dir "/util/:c:\\scriptbasic\\web\\"
   )
  errmsgdest 3
  nolog 0
  log (
    panic (
      file "c:\\scriptbasic\\httpdlog\\panic.log"
     )
    app (
      file "c:\\scriptbasic\\httpdlog\\app.log"
     )
    err (
      file "c:\\scriptbasic\\httpdlog\\err.log"
     )
    hit (
      file "c:\\scriptbasic\\httpdlog\\hit.log"
     )
    stat (
      file "c:\\scriptbasic\\httpdlog\\stat.log"
     )
   )
  msg404 """
<HTML>
<HEAD>
<TITLE>Error 404 page not found</TITLE>
</HEAD>
<BODY>
<FONT FACE=\"Verdana\" SIZE=\"2\">
<H1>Page not found</H1>
We regretfully inform you that the page you have requested can not be found on this server.
<p>
In case you are sure that this is a server configuration error, please contact
<FONT SIZE=\"3\"><TT>root@localhost</TT></FONT>
</FONT>
</BODY>
</HTML>
 """
  code404 "200 OK"
 )


Create a C:\xampp\htdocs\app-bin directory as a 'stub' for the proxy to ScriptBasic.

Create a C:\scriptbasic\web directory and copy the C:\xampp\cgi-bin\echo.bas into this directory. You will need to edit the three references to "/cgi-bin/echo.bas" in the form section and change it to "/app-bin/util/echo.bas". This allows mapping your web apps outside the Apache web root for an extra level of security.


To install the ScriptBasic application server as a NT service, type the following  command.

sbhttpd -install



Setting the sbhttpd to automatic will start the server at boot time. Use the Windows services feature to start/stop the server if changes to the scriba.conf are made.

Next we need to modify the Apache C:\xampp\apache\conf\httpd.conf file to add the proxy support for ScriptBasic.

Enable the following Apache modules by removing the "#" character at the beginning of the line.

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Add the following lines to httpd.conf file to configure the ScriptBasic application server as a proxy server. All URL requests made to the /app-bin (and it's virtual assigned directories) will be forwarded to sbhttpd.exe for processing.

ProxyRequests Off
ProxyPass /app-bin/ http://127.0.0.1:8080/
ProxyPassReverse /app-bin/ http://127.0.0.1:8080/

Save the file and restart the Apache web server for the changes to take affect.

The following browser screen shot shows echo.bas running on the application server rather then a CGI program on Apache.



The next post will cover how to use the MT extension for in memory session support.