ScriptBasic
|
|
Introduction
ScriptBasic is a neat open-source Basic for Windows and Linux written by
Peter Verhás. A ScriptBasic-capable
web server (which can run either stand-alone or as a module to Apache) is also
available so you can build web pages that contain ScriptBasic code.
Setup
Windows
- Create a directory eg. c:\scriptb, and extract scriba-vVERSION-bin.zip
into it
- Documentation recommends that you add c:\scriptb\bin to the PATH
environment variable
- Edit c:\scriptb\scriba.conf.lsp to fit your system. See below
for a sample
- Cd to c:\scriptb\bin\, and recompile the configuration file : scriba
-k ..\scriba.conf.lsp . This generates the binary file c:\scriptb\bin\scriba.conf.
Note
that when ScriptBasic starts, it looks for this file in the same directory
where scriba.exe lives. If you prefer to move this configuration file elsewhere,
open the Registry, and set HKEY_LOCAL_MACHINE\Software\ScriptBasic\config
to hold the path to the (binary) configuration file
ScriptBasic is now installed on your Windows host. You can run SB scripts
either from the command line, or as web pages.
Command-line interpreter
Here's the usual "Hello World!" example:
- Create a source file called hello.bas with the following code:
Print
"HELLO WORLD"
- Run the script: scriba hello.bas
To speed things up, you can compile a source file into tokenized code:
- scriba -no hello.bbf hello.bas
- scriba -b hello.bas
(CHECK) You can also associate the extension <.sb> (???) with the ScriptBasic
interpreter. In this case you can start a ScriptBasic program double clicking
on its name in the explorer.
Web server
Now that you have recompiled scriba.conf to fit your host, especially the
httpd section, open a DOS box, and
run "C:\scriptb\bin>sbhttpd -start" to start ScriptBasic's
web server. Run "netstat -an" to check that a program is listening
on TCP 80.
Note: To install the Eszter SB Application Engine as NT Service open a command
prompt, cd into the directory where the file sbhttpd.exe is located and type sbhttpd
-install.
Assuming that the "home" parameter in the httpd section
above is set to "C:\\scriptb\\examples\\", create C:\scriptb\examples\index.html
to contain the following code:
- #! C:\scriptb\bin\scriba.exe -c
- include cgi.bas
- cgi::Header 200,"text/html"
- cgi::FinishHeader
- print """
- <HTML>
- <BODY>
- <PRE>
- """
- print cgi::GetParam("apple")
- print
- """
- </PRE>
- </BODY>
- </HTML>
- """
- stop
Aim your browser at http://localhost:8080/index.html?apple=wozniak
Configuration
Sample configuration file
Here's an example configuration file from a Windows NT installation:
- ; scriba.conf
- ; ScriptBasic sample configuration file
- ;
- ; Note that this configuration file format is from v1.0b19 or later
and has to be compiled
- ; to internal binary format before starting ScriptBasic
-
- ; this is the extension of the dynamic load libraries on this system
- dll ".dll"
-
-
- ; where the modules are to be loaded from
- module "C:\\scriptb\\modules\\"
-
- ; where to search system and module include files
- ; trailing / or \\ is needed
- include "C:\\scriptb\\include\\"
-
- ; define external preprocessors
- preproc (
- internal (
- ;test "T:\\MyProjects\\ScriptBasic\\Debug\\preproc.dll"
- dbg "T:\\MyProjects\\ScriptBasic\\modules\\dbg.dll"
- )
-
- ; extensions that preprocessors are to be applied on
- extensions (
- ; here the key is the file name extension and the value is the symbolic
name of the external preprocessor
- ; for example
- ; lsp "lisp"
- ; would say that all input that has the file name extension '.lsp' should
be preprocessed using the external
- ; preprocessor named 'lisp'. The commad line to start this preprocessor
has to be defined a few lines below
- ; saying:
- ; lisp (
- ; executable "command line"
- ; directory "directory for the temporary
files after preprocessing"
- ; )
- ; Note that this is only an example, there is no 'lisp' preprocessor
for ScriptBasic or at least I do not know any.
- ;
- heb "heb"
- )
- ; the external preprocessors
- external (
- heb (
- executable "C:\\scriptb\\bin\\scriba.exe
t:\\MyProjects\\ScriptBasic\\source\\heber.bas"
- directory "t:\\MyProjects\\ScriptBasic\\hebtemp\\"
- )
- )
- )
-
- ;
- ; LIMIT VALUES TO STOP INIFINITE LOOP
- ;
-
- ; the maximal number of steps allowed for a program to run
- ; comment it out or set to zero to have no limit
- maxstep 0
-
- ; the maximal number of steps allowed for a program to run
- ; inside a function.
- ; comment it out or set to zero to have no limit
- maxlocalstep 0
-
- ; the maximal number of recursive function call deepness
- ; essentially this is the "stack" size
- maxlevel 300
-
-
- ; the maximal memory in bytes that a basic program is allowed to use
- ; for its variables
- maxmem 1000000
-
- ;
- ; ScriptBasic loads the modules before starting the code
- ; in the order they are specified here
- ;
- ;preload "ext_trial"
-
- ;
- ; This is the directory where we store the compiled code
- ; to automatically avoid recompilation
- ;
- cache "C:\\scriptb\\cache\\"
-
- isapi (
- ;
- ; where to write error messages when running the isapi interpreter
- ;
- report "C:\\scriptb\\httpdlog\\error.log"
-
- ;
- ; When an error happens this file is sent to the client after the
- ; listed error messages. Error messages are recorded in the error log
file
- ; if there is configured any and are also sent to the client browser.
- ; after the list of error messages this file is sent. This is actually
the tail
- ; of an HTML file. It has to contain </TT></FONT></BODY></HTML>
tags in this
- ; order with optional extra text between. You probably want to place
the webmaster
- ; eMail address in this text.
- ;
- errmesfile "C:\\scriptb\\examples\\error.html"
-
- ;
- ; If this config key exists scribais.dll will cache the compiled code
- ; into memory. To avoid memory caching during development comment this
- ; config line out.
- ;
- ; Note that if there is a code in memory cache it is used even if the
code on
- ; disk has changed! This results fast execution but may be inconvinient
during
- ; development.
- ;
- ;memcache yes
-
- ;
- ; This parameter is used by the CGI module when the interface is ISAPI
- ; This parameter gives the size of the buffer that the module uses to
handle
- ; POST parameters above 48K (usually uploads). The larger the buffer
is the
- ; faster upload handling can be.
- ;
- buffer "655360"
- )
-
- cgi (
- ;
- ; These are the keys used by the CGI module
- ;
- debugfile "C:\\scriptb\\httpdlog\\cgidebug.txt"
- )
-
- ;
- ; berkeley db config
- ;
- ;bdb (
- ; directories where to store the
- ; dir (
- ; home "C:\\scriptb\\httpdlog\\sampledb" ;
the home directory of operation of the Berkerley DB
- ; data "db" ; database files
- ; log "log" ; log files
- ; temp "tmp" ; temporary files
- ; )
- ; ScriptBasic extension modules can access only string configuration
values
- ; therefore you have to specify these numbers within quotes (later versions
will change it)
- ; limits (
- ; lg_max "1024000"
- ; mp_mmapsize "0000"
- ; mp_size "000"
- ; tx_max "000"
- ; lk_max "000"
- ; )
- ; what lock strategy to use
- ; it can be any of the followings
- ; default oldest random youngest
- ; lockstrategy default
- ; flags (
- ; ; set the value to yes or no
- ; lock_default no
- ; init_lock yes
- ; init_log yes
- ; init_mpool yes
- ; init_txn yes
- ; create yes
- ; )
- ; )
-
- ;
- ; MySQL configuration
- ;
- mysql (
- connections (
- test ( ;
the name of the connection
- host "127.0.0.1"
; the host for the connection
- db "test"
; database for the connection
- user "root"
; user for the connection
- password ""
; 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
- )
- auth (
- host "127.0.0.1"
; the host for the connection
- db "auth"
; database for the connection
- user "root"
; user for the connection
- password ""
; 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
- )
- )
- )
-
- odbc (
- connections (
- test ( ;
the name of the connection
- dsn "test"
; data source name
- user ""
; user for the connection, to test we use MS-Access thus there is no user
or passwd
- password ""
; password for the connection
- )
- )
- )
-
- ;
- ; This type of internal preprocessor was experimental and is not supported
by ScriptBasic
- ; since build v1.0b26
- ; Configure the sample preprocessor
- ;
- ; preproc$sample_uppercase "D:/MyProjects/sb/Debug/preproc.dll"
- ;
- ;break
-
- ;
- ; Configure the simple ScriptBasic httpd daemon
- ;
- ; Note that scripts may change the working directory therefore
- ; all directories should be specified here full path. For example
- ; the directory names here do not include the drive c: or e:
- ; because I develop it on two machines and it was inconvenient
- ; to alter and recompile the config file each time I moved the
- ; source to the other machine. When I run a script that changes
- ; the drive the http daemon stops in a few seconds because the
- ; guard thread do not find the pid file and therefore tells the
- ; engine to stop.
- ;
- httpd (
- threads 20
- listenbacklog 30
- port 8080
- home "C:\\scriptb\\examples\\"
- proxyip 0 ; set it true if you use Eszter engine behind
Apache rewrite and proxy modules
-
- pid (
- file "C:\\scriptb\\httpdlog\\pid.txt"
- delay 10 ; number of seconds to sleep between
the examination of the pid file if that still exists
- wait (
- period 10 ; number of times to wait
for the threads to stop before forcefully exiting
- length 1 ; number of seconds
to wait for the threads to stop (total wait= period*length)
- )
- )
-
- ; vdirs (
- ; dir "/user/:C:\\scriptb\\examples\\user\\"
- ; dir "/cgi-bin/:C:\\scriptb\\examples\\cgi-bin\\"
- ; dir "/sibawa/:C:\\scriptb\\examples\\sibawa\\cgi-bin\\"
- ; )
- client (
- allowed "127.0.0.1/255.255.255.255"
- allowed "16.94.58.4/0.0.0.0"
-
- ; denied "127.0.0.1/0.0.0.0"
- ; denied "16.192.68.5/255.255.0.0"
- )
- ; run (
- ; start "C:\\scriptb\\examples\\runstart.bas"
; start the program in an asynchronous thread