Recent Posts

Pages: [1] 2 3 ... 10
1
Scripting Languages / Re: ScriptBasic 3.0
« Last post by John on March 27, 2024, 10:20:28 PM »
Jack,

In this thread it had a download link to FreeBasic embedding of libcriba.dll. I have attached the FBembedsSB_3.zip that has Charles's scriba.bi. This is 32 bit demo.

EO3.bas
Code: ScriptBasic
  1. '
  2. ' SCRIPTBASIC
  3. '
  4.  
  5. ' ----------------
  6. ' GLOBAL VARIABLES
  7. ' ================
  8. '
  9. a=42
  10. b=sqr(2)
  11. s="hello world!"
  12.  
  13.  
  14. q=dprint()
  15. q=eprint(1,2,3,4)
  16.  
  17. 'print "Enter: "
  18. 'line input q
  19.  
  20.  
  21. ' ---------
  22. ' FUNCTIONS
  23. ' =========
  24.  
  25.  
  26. function dprint
  27.   sp="  "
  28.   cr="\n"
  29.   tab=chr$(9)
  30.   print "Dprint Globals: " & s & sp & a & sp & b & cr
  31.   ' line input q
  32.  dprint=1
  33. end function
  34.  
  35.  
  36. function eprint(a,b,c,d)
  37.   sp="  "
  38.   cr="\n"
  39.   tab=chr$(9)
  40.   print "Eprint Args: " & a & sp & b & sp & c & sp & d & cr
  41.   ' line input q
  42.  ans=a+b+c+d
  43.   eprint="Sum = " & ans
  44. end function
  45.  


Code: FreeBasic
  1.   #include once "windows.bi"
  2.   #include once "win/ole2.bi"
  3.   #include once "scriba.bi"
  4.  
  5.   dim as long pProgram,iError,cArgs
  6.   dim as long f1,f2,v
  7.   dim as long n,m
  8.   dim as SbData ReturnData,ArgData(3)
  9.   dim as sbdata ptr pdat
  10.   dim as long qdat
  11.  
  12.   function newmem CDECL (ByVal le As Long) As bstr Export
  13.     function=SysAllocStringByteLen (0,le)
  14.   end function
  15.  
  16.   sub freemem CDECL (ByVal p As bstr) Export
  17.     SysFreeString p
  18.   end sub
  19.  
  20.   SetConsoleTitle "FreeBasic ScriptBasic Embedding Test"
  21.  
  22.  
  23.  
  24.  
  25.   '
  26.   'LOADING AND RUNNING A PROGRAM
  27.   '-----------------------------
  28.   '
  29.   pProgram=scriba_new (cast(long,@newmem), cast(long,@freemem))
  30.   'scriba_LoadConfiguration(pProgram,"c:\scriptbasic\bin\scriba.conf")
  31.   scriba_SetFileName(pProgram,"E03.bas")
  32.  
  33.   iError=scriba_LoadSourceProgram(pProgram)
  34.   if iError then goto ending
  35.  
  36.   iError=scriba_Run(pProgram,"Hello")
  37.   if iError then goto ending
  38.  
  39.   '
  40.   'ACCESSING GLOBAL DATA
  41.   '---------------------
  42.   '
  43.   v=scriba_LookupVariableByName(pProgram,"main::a")  
  44.   scriba_GetVariable(pProgram,v,qdat)
  45.   pdat=cast(sbdata ptr,qdat)
  46.   m=pdat->lng+100
  47.   scriba_SetVariable(pProgram,v,2,m,0,"",0)
  48.   'scriba_GetVariable(pProgram,v,*pdat)
  49.   '
  50.   'CALLING SIMPLE SUBROUTINE
  51.   '-------------------------
  52.   '
  53.   f1=scriba_LookupFunctionByName(pProgram,"main::dprint")
  54.   if f1=0 then print "Unable to locat Dprint" : goto ending
  55.  
  56.   iError=scriba_Call(pProgram,f1)
  57.   if iError then goto ending
  58.   '
  59.   '
  60.   '
  61.   'CALLING FUNCTION, RETURNING DATA AND GETTING ALTERED PARAMS
  62.   '-----------------------------------------------------------
  63.  
  64.   f2=scriba_LookupFunctionByName(pProgram,"main::eprint")
  65.   if f2=0 then print "Unable to locate Eprint" : goto ending
  66.  
  67.  
  68.   'SETUP ARGUMENTS
  69.   '---------------
  70.  
  71.   'these can be used for both input and output
  72.  
  73.   ArgData(0).typ=SBT_DOUBLE
  74.   ArgData(1).typ=SBT_DOUBLE
  75.   ArgData(2).typ=SBT_DOUBLE
  76.   ArgData(3).typ=SBT_DOUBLE
  77.  
  78.   ArgData(0).siz=0
  79.   ArgData(1).siz=0
  80.   ArgData(2).siz=0
  81.   ArgData(3).siz=0
  82.    
  83.   ArgData(0).dbl=11
  84.   ArgData(1).dbl=12
  85.   ArgData(2).dbl=13
  86.   ArgData(3).dbl=14
  87.  
  88.   cArgs=4
  89.   '
  90.   iError=scriba_CallArgEx(pProgram, f2, ReturnData, cArgs, ArgData(0))
  91.   if iError then goto ending
  92.  
  93.   print "Return type:",ReturnData.typ
  94.   print "Value:",
  95.   '
  96.   'READ RETURNED VALUE
  97.   '-------------------
  98.   '
  99.   select case ReturnData.typ
  100.     case SBT_UNDEF  : print "Undefined"
  101.     case SBT_DOUBLE : print ReturnData.dbl
  102.     case SBT_LONG   : print ReturnData.lng
  103.     case SBT_STRING : print *ReturnData.str
  104.     case SBT_ZCHAR  : print *ReturnData.str
  105.   end select
  106.  
  107.   '------
  108.   ending:
  109.   '======
  110.  
  111.   scriba_destroy(pProgram)
  112.  
  113.   if iError then print "ERROR:  " + hex$(iError)  ' + "  " + hex$(pProgram)
  114.  
  115.  
  116.   'messageBox 0,"ok:  "+hex$(iError)+"  "+hex$(pProgram),"FreeBasic",0
  117.   sleep
  118.  

Output

Code: Text
  1. C:\FBWin\FBembedsSB_3>fbembeds3
  2. Dprint Globals: hello world!  42  1.414214
  3. Eprint Args: 1  2  3  4
  4. Dprint Globals: hello world!  142  1.414214
  5. Eprint Args: 11.000000  12.000000  13.000000  14.000000
  6. Return type:   3
  7. Value:        Sum = 50
  8.  
  9. C:\FBWin\FBembedsSB_3>
  10.  

2
Scripting Languages / Re: ScriptBasic 3.0
« Last post by John on March 27, 2024, 09:20:51 PM »
The ScriptBasic Application Server works under Linux with the sb-dev-msvc build.

Code: ScriptBasic
  1. global const nl = "\n"
  2. Const NumberOfCookies = 3
  3.  
  4. include cgi.bas
  5.  
  6. option cgi$Method cgi::Get or cgi::Upload
  7.  
  8. ' cgi::RequestBasicAuthentication "Test Realm"
  9. cgi::Header 200,"text/html"
  10.  
  11. '
  12. ' We are setting several cookies. The expiry time is ten seconds so you can test that
  13. ' the cookies are sent by the browser if you press some of the buttons fast enough,
  14. ' but it does not if you are slow
  15. '
  16. for i=1 to NumberOfCookies
  17.   ' cookie(i) is i, no domain is defined, path is /, expires after 5 seconds, not secure
  18.  cgi::SetCookie "cookie" & i,i,undef,"/",gmtime()+10,false
  19. next i
  20.  
  21. cgi::FinishHeader
  22.  
  23. '-------------------------------------------------------
  24. print """<HTML>
  25. <HEAD>
  26. <title>CGI parameter testing</title>
  27. </HEAD>
  28. <BODY><font face="VERDANA" size="2">
  29. <H1>View CGI Parameters</H1>
  30. This page shows the cgi parameters the way it was uploaded.
  31. <!-- here is the result of the previous HTTP request -->
  32. <FONT SIZE="3">
  33. <PRE>
  34. CGI system variables
  35. --------------------
  36.  
  37. """
  38. '-------------------------------------------------------
  39.  
  40. print "ServerSoftware  = ",cgi::ServerSoftware(), nl
  41. print "ServerName      = ",cgi::ServerName(), nl
  42. print "GatewayInterface= ",cgi::GatewayInterface(),nl
  43. print "ServerProtocol  = ",cgi::ServerProtocol(), nl
  44. print "ServerPort      = ",cgi::ServerPort(), nl
  45. print "RequestMethod   = ",cgi::RequestMethod(), nl
  46. print "PathInfo        = ",cgi::PathInfo(), nl
  47. print "PathTranslated  = ",cgi::PathTranslated(), nl
  48. print "ScriptName      = ",cgi::ScriptName(), nl
  49. print "QueryString     = ",cgi::QueryString(), nl
  50. print "RemoteHost      = ",cgi::RemoteHost(), nl
  51. print "RemoteAddress   = ",cgi::RemoteAddress(), nl
  52. print "AuthType        = ",cgi::AuthType(), nl
  53. print "RemoteUser      = ",cgi::RemoteUser(), nl
  54. print "RemoteIdent     = ",cgi::RemoteIdent(), nl
  55. print "ContentType     = ",cgi::ContentType(), nl
  56. print "ContentLength   = ",cgi::ContentLength(), nl
  57. print "UserAgent       = ",cgi::UserAgent(), nl
  58. print "Cookie          = ",cgi::RawCookie(), nl
  59.  
  60. print "Referer         = ",cgi::Referer(),nl
  61. print "Password        = ",Environ("HTTP_PASSWORD"),nl
  62. print "Full auth string= ",Environ("HTTP_AUTHORIZATION"),nl
  63. print "\nCookies:\n"
  64. for i=1 to NumberOfCookies
  65.   print "cookie" & i," ",cgi::Cookie("cookie" & i),"\n"
  66. next i
  67.  
  68. print "Text field using Param(\"TEXT-FIELD\") is ",cgi::Param("TEXT-FIELD"),nl,nl
  69.  
  70.  
  71. if cgi::RequestMethod() = "GET" then
  72.   print "GET text field using GetParam(\"TEXT-FIELD\") is ",cgi::GetParam("TEXT-FIELD"),nl
  73. end if
  74.  
  75. if cgi::RequestMethod() = "POST" then
  76.   print "POST text field using PostParam(\"TEXT-FIELD\") is ",cgi::PostParam("TEXT-FIELD"),nl
  77.   if cgi::ContentType() like "multipart*" then
  78.     print "Original file name is ",cgi::FileName("FILE-UPLOAD-NAME"),nl
  79.     if cgi::FileLength("FILE-UPLOAD-NAME") > 0 then
  80.       print "File of length ",cgi::FileLength("FILE-UPLOAD-NAME")," bytes is saved\n"
  81.       on error goto NoSave
  82.       cgi::SaveFile "FILE-UPLOAD-NAME","/home/jrs/sb/home/upload.txt"
  83.     else
  84.       print "There is no uploaded file."
  85.     end if
  86.   end if
  87. end if
  88.  
  89. print """</PRE><TABLE><TR><TD BORDER=0 BGCOLOR="EEEEEE"><PRE>
  90. A simple form to POST parameters:<BR>
  91. <FORM METHOD="POST" ACTION="/home/echo">
  92. <INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
  93. <INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE=" POST ">
  94. </FORM>
  95. </PRE></TD><TD BORDER=1 width="20">&nbsp;</TD><TD BORDER=0 BGCOLOR="EEEEEE"><PRE>
  96. A simple form to GET parameters:<BR>
  97. <FORM METHOD="GET" ACTION="/home/echo">
  98. <INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
  99. <INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE=" GET ">
  100. </FORM>
  101. </PRE></TD></TR></TABLE><PRE>
  102. <hr>
  103. A simple form to UPLOAD a file:<BR>
  104. <FORM METHOD="POST" ACTION="/qbo/echo" ENCTYPE="multipart/form-data">
  105. <INPUT TYPE="TEXT" VALUE="DEFAULT TEXT" NAME="TEXT-FIELD">
  106. <INPUT TYPE="FILE" VALUE="FILE-UPLOAD-VALUE" NAME="FILE-UPLOAD-NAME">
  107. <INPUT TYPE="SUBMIT" NAME="SUBMIT-BUTTON" VALUE="UPLOAD FILE">
  108. </FORM>
  109. <hr>
  110. </BODY>
  111. </HTML>
  112. """
  113. stop
  114. NoSave:
  115.  
  116. print "An error has happened saving the file. Code =",error(),nl
  117.  
  118. resume next
  119.  
3
Scripting Languages / Re: ScriptBasic 3.0
« Last post by John 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.  
4
Scripting Languages / Re: ScriptBasic 3.0
« Last post by John 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
5
Scripting Languages / Re: ScriptBasic 3.0
« Last post by John 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.
6
Scripting Languages / Re: ScriptBasic 3.0
« Last post by John 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


7
Scripting Languages / Re: ScriptBasic 3.0
« Last post by John 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
8
Scripting Languages / Re: ScriptBasic 3.0 - Runtime Download
« Last post by John 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
9
NOT BASIC / Tetris game for Windows in Fortran
« Last post by jalih on March 25, 2024, 08:21:33 AM »
I wrote a simple Tetris game sample for Windows using Simply Fortran and it's AppGraphics library.

Sources + runnable binary
10
Scripting Languages / Re: ScriptBasic 3.0
« Last post by jack on March 25, 2024, 04:02:07 AM »
thank you John
Pages: [1] 2 3 ... 10