Author Topic: ScriptBasic 3.0  (Read 11089 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
ScriptBasic 3.0
« on: March 15, 2024, 11:52:51 PM »
ScriptBasic runs in the following modes.
  • Embeddable scripting API as a DLL/so. (libscriba)
  • Console mode interpreter. (sbc)
  • Windows GUI interpreter with Windows style support. (sbw) This version doesn't pop a console or supports redirection.
  • Proxy / standalone application web server. (sbhttpd) The server runs as a service on Windows.
« Last Edit: May 16, 2024, 07:21:28 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #1 on: March 24, 2024, 03:16:32 AM »
After running setup in your ScriptBasic cloned source directory, run setup --install --directory=C:\ScriptBasic64 for your runtime version.

  • cio_colors.sb - Display all 256 colors and their value. This module allows you to control the console screen.
  • curl_wget.sb - Using the cURL extension module to download a file.
  • gmpmath.sb - GMP large integer math module. (+ - * /)
  • sbt_main.sb - Example of ScriptBasic running in threaded mode.
  • sql_odbc.sb - ODBC connected to a MS SQL Server displaying a couple columns in a table.
  • sqlite_demo.sb - Example of a create insert and select with a SQLite table.
  • testmysql.sb - Connecting to the MySQL example DB and get the data from the products table.
  • testmxml.sb - Example of using the Mini XML module.
« Last Edit: May 16, 2024, 07:26:14 PM by John »

Offline AlyssonR

  • Advocate
  • Posts: 131
Re: ScriptBasic 3.0
« Reply #2 on: March 24, 2024, 01:30:16 PM »
Wonderful stuff.

I will take a look when I next take a break from hardware development.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #3 on: March 24, 2024, 02:28:09 PM »
I have added the sbw gcc compiled interpreter to the repo as a zip. This version of ScriptBasic is compiled with no console and has Windows style / theme support for current common controls.

I plan to create a repo for Windows 64 / 32 bit builds using gcc which uses static .h files and creates no documentation from source. All that's needed to compile this version of ScriptBasic is the TDM-GCC-64/32. compiler (open source & free)

If you only need to extend ScriptBasic with C library extension modules the gcc version is a lightweight compile option. This version doesn't compile on Linux and is for Windows 32/64 bit only.

If you plan on modifying ScriptBasic core source, the MSVC version is the way to go.  It builds new .h files and documentation from source. The build system does all the heavy lifting for you.

Offline jack

  • Contributor
  • Posts: 15
Re: ScriptBasic 3.0
« Reply #4 on: March 24, 2024, 07:10:25 PM »
Hi John  :)
I am interested in using libscriba.dll, are there any examples?
with the help of fbfrog I translated scriba.h to scriba.bi, so I am ready to try using libscriba with FreeBasic but I need a skeleton example
an example in C would be good, I should be able to translate it to FB

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #5 on: March 24, 2024, 07:32:42 PM »
Jack,

Here is an example of calling the libscriba.dll using the SBT extension module.

Code: ScriptBasic
  1. ' SBT Demo
  2.  
  3. IMPORT sbt.sbi
  4.  
  5. sb_code = """
  6. FUNCTION prtvars(a, b, c)
  7.  PRINT a,"\\n"
  8.  PRINT FORMAT("%g\\n", b)
  9.  PRINT c,"\\n"
  10.  prtvars = "Function Return"
  11. END FUNCTION
  12.  
  13. a = 0
  14. b = 0
  15. c = ""
  16. """
  17.  
  18. sb = SB_New()
  19. SB_Configure sb, "C:/Windows/SCRIBA.INI"
  20. SB_Loadstr sb, sb_code
  21. SB_NoRun sb
  22. ' Call function before running script
  23. funcrtn = SB_CallSubArgs(sb,"main::prtvars", 123, 1.23, "One, Two, Three")
  24. PRINT funcrtn,"\n"
  25. ' Run script initializing globals
  26. SB_Run sb, ""
  27. ' Assign variables values
  28. SB_SetInt sb, "main::a", 321
  29. SB_SetDbl sb, "main::b", 32.1
  30. SB_SetStr sb, "main::c", "Three,Two,One" & CHR(0)
  31. ' Call function again with variables assigned in the previous step
  32. SB_CallSubArgs sb, "main::prtvars", _
  33.           SB_GetVar(sb, "main::a"), _
  34.           SB_GetVar(sb, "main::b"), _
  35.           SB_GetVar(sb, "main::c")
  36. SB_Destroy sb
  37.  

Output

123
1.23
One, Two, Three
Function Return
321
32.1
Three,Two,One

Looking at the SBT extension module C source may be helpful as well.


« Last Edit: May 16, 2024, 07:26:58 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #6 on: March 25, 2024, 03:00:46 AM »
setup can fully customize how your runtime file structure is laid out and configuration file defined. Take a peek at the setup.pl file for how setup options work.

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #7 on: March 25, 2024, 03:28:05 AM »
Charles Pegg created a ScriptBasic extension module called DLLC with OxygenBasic which was a scriptable FFI, virtual DLLs and ability to compile virtual assembly code. I'm going to try and get it working with 64 bit. Any O2 pros / Charles willing to help get this module working, let me know.

P.S.

I'm no longer interested in IUP support any longer in DLLC.

Offline jack

  • Contributor
  • Posts: 15
Re: ScriptBasic 3.0
« Reply #8 on: March 25, 2024, 04:02:07 AM »
thank you John

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0 - Runtime Download
« Reply #9 on: March 26, 2024, 12:50:31 AM »
If you would like to try ScriptBasic64 rather than building it from source, I've attached a ScriptBasic Windows 64 Bit zip to install.

  • Unzip the zip in your root C:\ drive.
  • Open up an admin console if you are going try the ScriptBasic Application Server in standalone mode otherwise a normal console will do.
  • Change directory to your C:\ScriptBasic64\bin directory an run the sbpath.bat file. (adds bin and lib to the console search path for the console session)
  • Change directory to the examples directory and run the test scripts.  scriba <name>.sb
To run the sbhttpd.exe (Application Server) in standalone mode do the following.
  • In an admin console cd to you bin directory.
  • Run sbhttpd -install (sbhttpd -remove)
  • Open the Windows Service Manger and start the "ScriptBasic Application Server 3.0" service. You can also use the sc.exe console version.
  • In your web browser type in localhost:9090/home/echo script.
Code: DOS
  1. C:\ScriptBasic64\bin>sbhttpd -install
  2. ScriptBasic Application Server 3.0 installed.
  3.  
  4. C:\ScriptBasic64\bin>sc start "ScriptBasic Application Server 3.0"
  5.  
  6. SERVICE_NAME: ScriptBasic Application Server 3.0
  7.         TYPE               : 10  WIN32_OWN_PROCESS
  8.         STATE              : 4  RUNNING
  9.                                 (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
  10.         WIN32_EXIT_CODE    : 0  (0x0)
  11.         SERVICE_EXIT_CODE  : 0  (0x0)
  12.         CHECKPOINT         : 0x0
  13.         WAIT_HINT          : 0x0
  14.         PID                : 4712
  15.         FLAGS              :
  16.  
  17. C:\ScriptBasic64\bin>
  18.  

I use the Bootstrap framework with the ScriptBasic Application Server. Here is a template I've use. Spur Template
« Last Edit: May 16, 2024, 07:27:44 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #10 on: March 26, 2024, 07:48:22 PM »
ScriptBasic 64 supports these key extensions for the language. These extension modules can be used with the web application server as well.

ScriptBasic supports a single step / breakpoints / view variables Debugger preprocessor.
  • ScriptBasic multi-threading with inter thread variable sharing.
  • cURL with https support
  • ODBC - uses ODBC DSN manager
  • MySQL direct API C interface
  • SQLite with memory / file DB support
  • JSON data API
  • XML data API
  • WEBEXT - converts JSON to ScriptBasic associative arrays and back.
  • Various other extensions are available separately
« Last Edit: March 26, 2024, 07:54:57 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #11 on: March 27, 2024, 01:36:05 AM »
I thought I would give embedding libscriba.dll with the current version of OxygenBasic a try. The original 32 bit code worked. When I tried to change to rt64.inc and switch to the 64 bit version of libscriba, it failed to run.

Code: Visual Basic
  1. ' O2 SB Embed
  2.  
  3. % filename "o2sb.exe"
  4. includepath "$/inc/"
  5. include "RTL32.inc"
  6. ' include "RTL64.inc"
  7. % libScriba = "libScriba.dll"
  8. indexbase 0
  9.  
  10. type SbData
  11.   typ as dword
  12.   siz as dword
  13.   union {
  14.     dbl as double
  15.     lng as sys
  16.     str as char*
  17.     gen as sys
  18.   }
  19. end type
  20.  
  21. #define SBT_UNDEF  0
  22. #define SBT_DOUBLE 1
  23. #define SBT_LONG   2
  24. #define SBT_STRING 3
  25. #define SBT_ZCHAR  4
  26.  
  27. sys pProgram, iError, cArgs
  28. sys f1, f2, v
  29. sys n, m
  30. sys qdat
  31. SbData ReturnData, ArgData[3]
  32. sbData pdat
  33.  
  34. sys sb=LoadLibrary libScriba
  35. extern cdecl
  36.   bind sb
  37.   {
  38.   scriba_new
  39.   scriba_SetStdin()
  40.   scriba_SetStdout()
  41.   scriba_SetEmbedPointer()
  42.   scriba_LoadConfiguration
  43.   scriba_destroy
  44.   scriba_DestroySbData
  45.   scriba_SetFileName
  46.   scriba_LoadSourceProgram
  47.   scriba_LoadProgramString
  48.   scriba_Run
  49.   scriba_GetVariable
  50.   scriba_SetVariable
  51.   scriba_LookupVariableByName
  52.   scriba_LookupFunctionByName
  53.   scriba_Call
  54.   scriba_CallArg
  55.   scriba_NewSbArgs
  56.   scriba_CallArgEx
  57.   scriba_DestroySbArgs
  58.   scriba_DestroySbData
  59.   scriba_NewSbString
  60.   }
  61. end extern
  62.  
  63. function newmem cdecl (sys le) as sys, export
  64.   return getmemory le
  65. end function
  66.  
  67. function freemem cdecl (sys p) export
  68.   freememory p
  69. end function
  70.  
  71. pProgram = scriba_new(@newmem, @freemem)
  72. scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI_64")
  73. scriba_SetFileName(pProgram, "test.sb")
  74. scriba_LoadSourceProgram(pProgram)
  75. scriba_Run(pProgram,"")
  76.  
  77. ' Get Global Var  
  78. sbdata *p  
  79. v = scriba_LookupVariableByName(pProgram, "main::a")
  80. scriba_GetVariable(pProgram, v, @@p)
  81. print "A: " + str(p.lng)
  82.  
  83. ' Create SB Variant Array
  84. sbData *arg
  85. @arg = scriba_NewSbArgs(pProgram,"i r s", 1, .2, "three")
  86. print str(arg[0].lng) + " | " + str(arg[1].dbl) + " | " + arg[2].str
  87.  
  88. scriba_DestroySbArgs(pProgram, arg, 3)
  89. scriba_DestroySbData(pProgram, arg)  
  90. scriba_destroy(pProgram)
  91.  

test.sb
Code: ScriptBasic
  1. a=99


« Last Edit: March 27, 2024, 04:53:48 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #12 on: March 27, 2024, 12:58:48 PM »
There seems to be some issues with the 64 bit version of libscriba.dll. It fails with passing string arguments like configuration and code as a string. I tried the GCC 64 bit version libscriba with the same results. Hopefully AIR will find some time to have a look.

The libscriba shared object works fine on 64 bit Linux.
« Last Edit: March 27, 2024, 02:47:23 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #13 on: March 27, 2024, 07:03:45 PM »
Jack,

Here is a 'Back to the Future' thread you might find interesting. Charles Pegg created a scriba.bi when he was building the DLLC extension module. This was before he created his self compiling version of O2.

Maybe you could revitalize this old FreeBaic thread with your efforts.

https://www.freebasic.net/forum/viewtopic.php?t=15976
« Last Edit: March 27, 2024, 07:11:09 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #14 on: March 27, 2024, 08:52:16 PM »
I have been testing the sb-dev-msvc repo under Ubuntu Linux. The install went well.

Code: Text
  1. jrs@linux-dev:~/sb-dev-msvc$ ./setup --check
  2. This is unix cwd=/home/jrs/sb-dev-msvc/
  3. scriba executable OK  
  4. sbhttpd executable OK  
  5. libscriba library OK  
  6. MODULE odbc:     dll OK   lib OK   bas OK  
  7. MODULE webext:   dll OK   lib OK   bas OK  
  8. MODULE gmp2:     dll OK   lib OK   bas OK  
  9. MODULE curl:     dll OK   lib OK   bas OK  
  10. MODULE t:        dll OK   lib OK   bas OK  
  11. MODULE ip:       dll OK   lib OK   bas OK  
  12. MODULE hash:     dll OK   lib OK   bas OK  
  13. MODULE sqlite:   dll OK   lib OK   bas OK  
  14. MODULE trial:    dll OK   lib OK   bas OK  
  15. MODULE zlib:     dll OK   lib OK   bas OK  
  16. MODULE sbt:      dll OK   lib OK   bas OK  
  17. MODULE sdbg:     dll OK   lib OK   bas OK  
  18. MODULE curses:   dll OK   lib OK   bas OK  
  19. MODULE dbg:      dll OK   lib OK   bas OK  
  20. MODULE slre:     dll OK   lib OK   bas OK  
  21. MODULE mt:       dll OK   lib OK   bas OK  
  22. MODULE json:     dll OK   lib OK   bas OK  
  23. MODULE ux:       dll OK   lib OK   bas OK  
  24. MODULE mxml:     dll OK   lib OK   bas OK  
  25. MODULE mysql:    dll OK   lib OK   bas OK  
  26. MODULE cgi:      dll OK   lib OK   bas OK  
  27. jrs@linux-dev:~/sb-dev-msvc$
  28.  

The libscriba and SBT extension module seem to be working.

Code: ScriptBasic
  1. ' SBT 64 bit Linux Demo
  2.  
  3. IMPORT sbt.bas
  4.  
  5. sb_code = """
  6. FUNCTION prtvars(a, b, c)
  7.  PRINT a,"\\n"
  8.  PRINT FORMAT("%g\\n", b)
  9.  PRINT c,"\\n"
  10.  prtvars = "Function Return"
  11. END FUNCTION
  12.  
  13. a = 0
  14. b = 0
  15. c = ""
  16. """
  17.  
  18. sb = sbt::SB_New()
  19. sbt::SB_Configure sb, "/etc/scriba/basic.conf"
  20. sbt::SB_Loadstr sb, sb_code
  21. sbt::SB_NoRun sb
  22. ' Call function before running script
  23. funcrtn = sbt::SB_CallSubArgs(sb,"main::prtvars", 123, 1.23, "One, Two, Three")
  24. PRINT funcrtn,"\n"
  25. ' Run script initializing globals
  26. sbt::SB_Run sb, ""
  27. ' Assign variables values
  28. sbt::SB_SetInt sb, "main::a", 321
  29. sbt::SB_SetDbl sb, "main::b", 32.1
  30. sbt::SB_SetStr sb, "main::c", "Three,Two,One" & CHR(0)
  31. ' Call function again with variables assigned in the previous step
  32. sbt::SB_CallSubArgs sb, "main::prtvars", _
  33.           sbt::SB_GetVar(sb, "main::a"), _
  34.           sbt::SB_GetVar(sb, "main::b"), _
  35.           sbt::SB_GetVar(sb, "main::c")
  36. sbt::SB_Destroy sb
  37.  

Output

Code: Text
  1. jrs@linux-dev:~/sb/examples$ scriba sbt_demo.sb
  2. 123
  3. 1.23
  4. One, Two, Three
  5. Function Return
  6. 321
  7. 32.1
  8. Three,Two,One
  9. jrs@linux-dev:~/sb/examples
  10.