ScriptBasic Introduction

Started by John Spikowski, July 21, 2013, 10:13:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

John Spikowski

First and foremost, thanks Charles for creating this board for ScriptBasic.

For those unfamiliar with ScriptBasic, it was written by Peter Verhas when the race for dominance in the scripting space was in full force. (Perl, PHP, Python, Cold Fusion, ...) ScriptBasic is an embeddable scripting API in an object like form written in ANSI/ISO C for portability. Peter wrote scriba which is a command line interpreter using C for the client wrapper. The goal with scriba was to show a real world example of using the embedded scripting engine. I posted on this forum a while back a PowerBASIC example of wrapping SB. It was under a dozen lines of PB code if I remember. Peter also wrote a multi-threaded HTTP/FTP server in ScriptBasic to demonstrate the thread safe features of the language. As icing, the webserver also runs as a service and has a shared memory API for thread inter-communications.

ScriptBasic is commercially used in embedded controllers for building control/energy management and in routers and gateways as a scripting tool. Charles Pegge of the OxygenBasic project created what started off as a FFI replacement for the ScriptBasic DYC extension module and by the time Charles was finished the only thing DLLC doesn't do is spin hay into gold.   8)

ScriptBasic runs on Windows, Linux, OS X in 32/64 bit flavors. Android Linux native is also supported. I'm working on getting the long overdue ScriptBasic 2.2 release out which has a lot of exciting enhancements that should make ScriptBasic attractive and hopefully earns a place in your software toolbox.

John Spikowski

Here is an example of PowerBASIC replacing the role of scriba. (SB embedded in a PBCC program) It's a bare bones shell but all the core ScriptBasic language features are available.

PBI.bas

' PowerBASIC Command Line Interpreter

#DIM ALL

#INCLUDE ONCE "oleauto.inc"
#INCLUDE ONCE "scriba.inc"

FUNCTION newmem CDECL (BYVAL le AS LONG) AS LONG
  FUNCTION=SysAllocStringByteLen (BYVAL 0,BYVAL le)
END FUNCTION

SUB freemem CDECL (BYVAL p AS LONG)
  SysFreeString BYVAL p
END SUB

FUNCTION PBMAIN () AS LONG

DIM pProgram AS LONG
DIM iError AS LONG

pProgram = scriba_new(CODEPTR(newmem),CODEPTR(freemem))
scriba_SetFileName(pProgram,COMMAND$(1))
scriba_LoadSourceProgram(pProgram)
iError = scriba_Run(pProgram,COMMAND$(2))
scriba_destroy(pProgram)

END FUNCTION


E01.sb

cmd = command()

PRINT "Command Line Argument(s): ", cmd, "\n\n"

PRINT "PowerBASIC Embedded Scripting Example\n\n"

FOR x = 1 TO 5
  PRINT x, "\n"
NEXT x


C:\PBCC\Samples\ScriptBasic>pbi e01.sb sample_argument
Command Line Argument(s): sample_argument

PowerBASIC Embedded Scripting Example

1
2
3
4
5

C:\PBCC\Samples\ScriptBasic>

Directory of C:\PBCC\Samples\ScriptBasic

04/03/2013  05:30 PM               164 E01.sb
08/29/2009  02:08 AM           524,288 libscriba.dll
04/03/2013  05:31 PM               596 PBI.bas
04/03/2013  05:31 PM            26,112 PBI.exe
04/03/2013  05:24 PM            61,369 scriba.inc


ScriptBasic can also be translated to C as a 64/32 bit executable.