Author Topic: ScriptBasic 3.0  (Read 11870 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #15 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.  

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #16 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.  

« Last Edit: March 27, 2024, 10:34:16 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #17 on: March 28, 2024, 07:24:34 PM »
Here are the results of my Linux testing of the sb-dev-msvc repo.

Code: Text
  1. *** SBT ***
  2.  
  3. jrs@linux-dev:~/sb/examples$ scriba sbt_demo.sb
  4. 123
  5. 1.23
  6. One, Two, Three
  7. Function Return
  8. 321
  9. 32.1
  10. Three,Two,One
  11. jrs@linux-dev:~/sb/examples$
  12.  
  13.  
  14. jrs@linux-dev:~/sb/examples$ scriba sbt_main.sb
  15. M:1
  16. T:1
  17. M:2
  18. T:2
  19. M:3
  20. T:3
  21. M:4
  22. T:4
  23. M:5
  24. T:5
  25. M:6
  26. T:6
  27. M:7
  28. T:7
  29. M:8
  30. T:8
  31. M:9
  32. T:9
  33. M:10
  34. T:10
  35. Thread Completed
  36. jrs@linux-dev:~/sb/examples$
  37.  
  38.  
  39. *** CURL ***
  40.  
  41. jrs@linux-dev:~/sb/examples$ scriba curl_wget.sb
  42. http://www.textfiles.com/etext/FICTION/warpeace.txt
  43. Data downloaded: 4434670 bytes.
  44. Total download time: 1.510 sec.
  45. Average download speed: 2868.000 kbyte/sec.
  46. jrs@linux-dev:~/sb/examples$
  47.  
  48.  
  49. *** GMP ***
  50.  
  51. jrs@linux-dev:~/sb/examples$ scriba gmpmath.sb
  52. ADD: 2222222211
  53. SUB: 246913569
  54. MUL: 1219326311126352690
  55. DIV: 617283945
  56.  
  57. ScriptBasic MAXINT: 9223372036854775807
  58. jrs@linux-dev:~/sb/examples$
  59.  
  60.  
  61. *** MYSQL ***
  62.  
  63. jrs@linux-dev:~/sb/examples$ scriba testmysql.sb
  64. S10_1678 - 1969 Harley Davidson Ultimate Chopper - $ 95.70
  65. S10_1949 - 1952 Alpine Renault 1300 - $214.30
  66. S10_2016 - 1996 Moto Guzzi 1100i - $118.94
  67. S10_4698 - 2003 Harley-Davidson Eagle Drag Bike - $193.66
  68. S10_4757 - 1972 Alfa Romeo GTA - $136.00
  69. S10_4962 - 1962 LanciaA Delta 16V - $147.74
  70. S12_1099 - 1968 Ford Mustang - $194.57
  71. S12_1108 - 2001 Ferrari Enzo - $207.80
  72. S12_1666 - 1958 Setra Bus - $136.67
  73. S12_2823 - 2002 Suzuki XREO - $150.62
  74. S12_3148 - 1969 Corvair Monza - $151.08
  75. S12_3380 - 1968 Dodge Charger - $117.44
  76. S12_3891 - 1969 Ford Falcon - $173.02
  77. S12_3990 - 1970 Plymouth Hemi Cuda - $ 79.80
  78. S12_4473 - 1957 Chevy Pickup - $118.50
  79. S12_4675 - 1969 Dodge Charger - $115.16
  80. S18_1097 - 1940 Ford Pickup Truck - $116.67
  81. S18_1129 - 1993 Mazda RX-7 - $141.54
  82. S18_1342 - 1937 Lincoln Berline - $102.74
  83. S18_1367 - 1936 Mercedes-Benz 500K Special Roadster - $ 53.91
  84. S18_1589 - 1965 Aston Martin DB5 - $124.44
  85. S18_1662 - 1980s Black Hawk Helicopter - $157.69
  86. S18_1749 - 1917 Grand Touring Sedan - $170.00
  87. S18_1889 - 1948 Porsche 356-A Roadster - $ 77.00
  88. S18_1984 - 1995 Honda Civic - $142.25
  89. S18_2238 - 1998 Chrysler Plymouth Prowler - $163.73
  90. S18_2248 - 1911 Ford Town Car - $ 60.54
  91. S18_2319 - 1964 Mercedes Tour Bus - $122.73
  92. S18_2325 - 1932 Model A Ford J-Coupe - $127.13
  93. S18_2432 - 1926 Ford Fire Engine - $ 60.77
  94. S18_2581 - P-51-D Mustang - $ 84.48
  95. S18_2625 - 1936 Harley Davidson El Knucklehead - $ 60.57
  96. S18_2795 - 1928 Mercedes-Benz SSK - $168.75
  97. S18_2870 - 1999 Indy 500 Monte Carlo SS - $132.00
  98. S18_2949 - 1913 Ford Model T Speedster - $101.31
  99. S18_2957 - 1934 Ford V8 Coupe - $ 62.46
  100. S18_3029 - 1999 Yamaha Speed Boat - $ 86.02
  101. S18_3136 - 18th Century Vintage Horse Carriage - $104.72
  102. S18_3140 - 1903 Ford Model A - $136.59
  103. S18_3232 - 1992 Ferrari 360 Spider red - $169.34
  104. S18_3233 - 1985 Toyota Supra - $107.57
  105. S18_3259 - Collectable Wooden Train - $100.84
  106. S18_3278 - 1969 Dodge Super Bee - $ 80.41
  107. S18_3320 - 1917 Maxwell Touring Car - $ 99.21
  108. S18_3482 - 1976 Ford Gran Torino - $146.99
  109. S18_3685 - 1948 Porsche Type 356 Roadster - $141.28
  110. S18_3782 - 1957 Vespa GS150 - $ 62.17
  111. S18_3856 - 1941 Chevrolet Special Deluxe Cabriolet - $105.87
  112. S18_4027 - 1970 Triumph Spitfire - $143.62
  113. S18_4409 - 1932 Alfa Romeo 8C2300 Spider Sport - $ 92.03
  114. S18_4522 - 1904 Buick Runabout - $ 87.77
  115. S18_4600 - 1940s Ford truck - $121.08
  116. S18_4668 - 1939 Cadillac Limousine - $ 50.31
  117. S18_4721 - 1957 Corvette Convertible - $148.80
  118. S18_4933 - 1957 Ford Thunderbird - $ 71.27
  119. S24_1046 - 1970 Chevy Chevelle SS 454 - $ 73.49
  120. S24_1444 - 1970 Dodge Coronet - $ 57.80
  121. S24_1578 - 1997 BMW R 1100 S - $112.70
  122. S24_1628 - 1966 Shelby Cobra 427 S/C - $ 50.31
  123. S24_1785 - 1928 British Royal Navy Airplane - $109.42
  124. S24_1937 - 1939 Chevrolet Deluxe Coupe - $ 33.19
  125. S24_2000 - 1960 BSA Gold Star DBD34 - $ 76.17
  126. S24_2011 - 18th century schooner - $122.89
  127. S24_2022 - 1938 Cadillac V-16 Presidential Limousine - $ 44.80
  128. S24_2300 - 1962 Volkswagen Microbus - $127.79
  129. S24_2360 - 1982 Ducati 900 Monster - $ 69.26
  130. S24_2766 - 1949 Jaguar XK 120 - $ 90.87
  131. S24_2840 - 1958 Chevy Corvette Limited Edition - $ 35.36
  132. S24_2841 - 1900s Vintage Bi-Plane - $ 68.51
  133. S24_2887 - 1952 Citroen-15CV - $117.44
  134. S24_2972 - 1982 Lamborghini Diablo - $ 37.76
  135. S24_3151 - 1912 Ford Model T Delivery Wagon - $ 88.51
  136. S24_3191 - 1969 Chevrolet Camaro Z28 - $ 85.61
  137. S24_3371 - 1971 Alpine Renault 1600s - $ 61.23
  138. S24_3420 - 1937 Horch 930V Limousine - $ 65.75
  139. S24_3432 - 2002 Chevy Corvette - $107.08
  140. S24_3816 - 1940 Ford Delivery Sedan - $ 83.86
  141. S24_3856 - 1956 Porsche 356A Coupe - $140.43
  142. S24_3949 - Corsair F4U ( Bird Cage) - $ 68.24
  143. S24_3969 - 1936 Mercedes Benz 500k Roadster - $ 41.03
  144. S24_4048 - 1992 Porsche Cayenne Turbo Silver - $118.28
  145. S24_4258 - 1936 Chrysler Airflow - $ 97.39
  146. S24_4278 - 1900s Vintage Tri-Plane - $ 72.45
  147. S24_4620 - 1961 Chevrolet Impala - $ 80.84
  148. S32_1268 - 1980?s GM Manhattan Express - $ 96.31
  149. S32_1374 - 1997 BMW F650 ST - $ 99.89
  150. S32_2206 - 1982 Ducati 996 R - $ 40.23
  151. S32_2509 - 1954 Greyhound Scenicruiser - $ 54.11
  152. S32_3207 - 1950's Chicago Surface Lines Streetcar - $ 62.14
  153. S32_3522 - 1996 Peterbilt 379 Stake Bed with Outrigger - $ 64.64
  154. S32_4289 - 1928 Ford Phaeton Deluxe - $ 68.79
  155. S32_4485 - 1974 Ducati 350 Mk3 Desmo - $102.05
  156. S50_1341 - 1930 Buick Marquette Phaeton - $ 43.64
  157. S50_1392 - Diamond T620 Semi-Skirted Tanker - $115.75
  158. S50_1514 - 1962 City of Detroit Streetcar - $ 58.58
  159. S50_4713 - 2002 Yamaha YZR M1 - $ 81.36
  160. S700_1138 - The Schooner Bluenose - $ 66.67
  161. S700_1691 - American Airlines: B767-300 - $ 91.34
  162. S700_1938 - The Mayflower - $ 86.61
  163. S700_2047 - HMS Bounty - $ 90.52
  164. S700_2466 - America West Airlines B757-200 - $ 99.72
  165. S700_2610 - The USS Constitution Ship - $ 72.28
  166. S700_2824 - 1982 Camaro Z28 - $101.15
  167. S700_2834 - ATA: B757-300 - $118.65
  168. S700_3167 - F/A 18 Hornet 1/72 - $ 80.00
  169. S700_3505 - The Titanic - $100.17
  170. S700_3962 - The Queen Mary - $ 99.31
  171. S700_4002 - American Airlines: MD-11S - $ 74.03
  172. S72_1253 - Boeing X-32A JSF - $ 49.66
  173. S72_3212 - Pont Yacht - $ 54.60
  174.  
  175. The database handle is: 1
  176. Affected rows by SELECT: 110
  177. Character set name is: utf8mb4
  178. Last error is:
  179. Client info is: 8.0.36
  180. Host info is: 127.0.0.1 via TCP/IP
  181. Proto info is: 10
  182. Server info is: 8.0.36-0ubuntu0.22.04.1
  183. PING result: -1
  184. Thread ID: 0
  185. Status is: Uptime: 2530  Threads: 2  Questions: 4  Slow queries: 0  Opens: 140  Flush tables: 3  Open tables: 59  Queries per second avg: 0.001
  186. jrs@linux-dev:~/sb/examples$
  187.  
  188.  
  189. *** MXML ***
  190.  
  191. jrs@linux-dev:~/sb/examples$ scriba testmxml.sb
  192. Test2: And this is another test!
  193.  
  194. Image: madonna.jpg
  195. Alt Image: Foligno Madonna, by Raphael
  196.  
  197. ID = 1
  198. Name = Hello, world!
  199. ID = 2
  200. Name = Hello, China!
  201. jrs@linux-dev:~/sb/examples$
  202.  
  203.  
  204. *** JSON ***
  205.  
  206. jrs@linux-dev:~/sb/examples$ scriba testjson.sb
  207. {
  208.     "Preferences": {
  209.         "AccountingInfoPrefs": {
  210.             "UseAccountNumbers": false,
  211.             "TrackDepartments": false,
  212.             "ClassTrackingPerTxn": false,
  213.             "ClassTrackingPerTxnLine": false,
  214.             "FirstMonthOfFiscalYear": "January",
  215.             "TaxYearMonth": "January",
  216.             "TaxForm": "1",
  217.             "CustomerTerminology": "Customers"
  218.         },
  219.         "ProductAndServicesPrefs": {
  220.             "ForSales": true,
  221.             "ForPurchase": true,
  222.             "QuantityWithPriceAndRate": true,
  223.             "QuantityOnHand": true,
  224.             "RevenueRecognition": false,
  225.             "RevenueRecognitionFrequency": "MONTHLY"
  226.         },
  227.         "SalesFormsPrefs": {
  228.             "UsingProgressInvoicing": false,
  229.             "CustomField": [
  230.                 {
  231.                     "CustomField": [
  232.                         {
  233.                             "Name": "SalesFormsPrefs.UseSalesCustom3",
  234.                             "Type": "BooleanType",
  235.                             "BooleanValue": false
  236.                         },
  237.                         {
  238.                             "Name": "SalesFormsPrefs.UseSalesCustom1",
  239.                             "Type": "BooleanType",
  240.                             "BooleanValue": true
  241.                         },
  242.                         {
  243.                             "Name": "SalesFormsPrefs.UseSalesCustom2",
  244.                             "Type": "BooleanType",
  245.                             "BooleanValue": false
  246.                         }
  247.                     ]
  248.                 },
  249.                 {
  250.                     "CustomField": [
  251.                         {
  252.                             "Name": "SalesFormsPrefs.SalesCustomName1",
  253.                             "Type": "StringType",
  254.                             "StringValue": "Crew #"
  255.                         }
  256.                     ]
  257.                 },
  258.                 {
  259.                     "CustomField": [
  260.                         {
  261.                             "Module": "Json",
  262.                             "Author": {
  263.                                 "FirstName": "Armando",
  264.                                 "LastName": "Rivera",
  265.                                 "Alias": "AIR"
  266.                             }
  267.                         }
  268.                     ]
  269.                 }
  270.             ],
  271.             "CustomTxnNumbers": false,
  272.             "EmailCopyToCompany": false,
  273.             "AllowDeposit": false,
  274.             "AllowDiscount": true,
  275.             "DefaultDiscountAccount": "86",
  276.             "AllowEstimates": true,
  277.             "ETransactionEnabledStatus": "NotApplicable",
  278.             "ETransactionAttachPDF": false,
  279.             "ETransactionPaymentEnabled": false,
  280.             "IPNSupportEnabled": false,
  281.             "AllowServiceDate": false,
  282.             "AllowShipping": false,
  283.             "DefaultTerms": {
  284.                 "value": "3"
  285.             },
  286.             "AutoApplyCredit": true,
  287.             "AutoApplyPayments": true,
  288.             "UsingPriceLevels": false,
  289.             "DefaultCustomerMessage": "Thank you for your business and have a great day!"
  290.         },
  291.         "EmailMessagesPrefs": {
  292.             "InvoiceMessage": {
  293.                 "Subject": "Invoice from Craig's Design and Landscaping Services",
  294.                 "Message": "Your invoice is attached.  Please remit payment at your earliest convenience.\nThank you for your business - we appreciate it very much.\n\nSincerely,\nCraig's Design and Landscaping Services"
  295.             },
  296.             "EstimateMessage": {
  297.                 "Subject": "Estimate from Craig's Design and Landscaping Services",
  298.                 "Message": "Please review the estimate below.  Feel free to contact us if you have any questions.\nWe look forward to working with you.\n\nSincerely,\nCraig's Design and Landscaping Services"
  299.             },
  300.             "SalesReceiptMessage": {
  301.                 "Subject": "Sales Receipt from Craig's Design and Landscaping Services",
  302.                 "Message": "Your sales receipt is attached.\nThank you for your business - we appreciate it very much.\n\nSincerely,\nCraig's Design and Landscaping Services"
  303.             },
  304.             "StatementMessage": {
  305.                 "Subject": "Statement from Craig's Design and Landscaping Services",
  306.                 "Message": "Your statement is attached.  Please remit payment at your earliest convenience.\nThank you for your business - we appreciate it very much.\n\nSincerely,\nCraig's Design and Landscaping Services"
  307.             }
  308.         },
  309.         "VendorAndPurchasesPrefs": {
  310.             "TrackingByCustomer": true,
  311.             "BillableExpenseTracking": true,
  312.             "POCustomField": [
  313.                 {
  314.                     "CustomField": [
  315.                         {
  316.                             "Name": "PurchasePrefs.UsePurchaseCustom1",
  317.                             "Type": "BooleanType",
  318.                             "BooleanValue": true
  319.                         },
  320.                         {
  321.                             "Name": "PurchasePrefs.UsePurchaseCustom2",
  322.                             "Type": "BooleanType",
  323.                             "BooleanValue": true
  324.                         },
  325.                         {
  326.                             "Name": "PurchasePrefs.UsePurchaseCustom3",
  327.                             "Type": "BooleanType",
  328.                             "BooleanValue": false
  329.                         }
  330.                     ]
  331.                 },
  332.                 {
  333.                     "CustomField": [
  334.                         {
  335.                             "Name": "PurchasePrefs.PurchaseCustomName1",
  336.                             "Type": "StringType",
  337.                             "StringValue": "Crew #"
  338.                         },
  339.                         {
  340.                             "Name": "PurchasePrefs.PurchaseCustomName2",
  341.                             "Type": "StringType",
  342.                             "StringValue": "Sales Rep"
  343.                         }
  344.                     ]
  345.                 }
  346.             ]
  347.         },
  348.         "TimeTrackingPrefs": {
  349.             "UseServices": true,
  350.             "BillCustomers": true,
  351.             "ShowBillRateToAll": false,
  352.             "WorkWeekStartDate": "Monday",
  353.             "MarkTimeEntriesBillable": true
  354.         },
  355.         "TaxPrefs": {
  356.             "UsingSalesTax": true,
  357.             "TaxGroupCodeRef": {
  358.                 "value": "2"
  359.             }
  360.         },
  361.         "CurrencyPrefs": {
  362.             "MultiCurrencyEnabled": false,
  363.             "HomeCurrency": {
  364.                 "value": "USD"
  365.             }
  366.         },
  367.         "ReportPrefs": {
  368.             "ReportBasis": "Accrual",
  369.             "CalcAgingReportFromTxnDate": false
  370.         },
  371.         "OtherPrefs": {
  372.             "NameValue": [
  373.                 {
  374.                     "Name": "SalesFormsPrefs.DefaultCustomerMessage",
  375.                     "Value": "Thank you for your business and have a great day!"
  376.                 },
  377.                 {
  378.                     "Name": "SalesFormsPrefs.DefaultItem",
  379.                     "Value": "1"
  380.                 },
  381.                 {
  382.                     "Name": "DTXCopyMemo",
  383.                     "Value": "false"
  384.                 },
  385.                 {
  386.                     "Name": "UncategorizedAssetAccountId",
  387.                     "Value": "32"
  388.                 },
  389.                 {
  390.                     "Name": "UncategorizedIncomeAccountId",
  391.                     "Value": "30"
  392.                 },
  393.                 {
  394.                     "Name": "UncategorizedExpenseAccountId",
  395.                     "Value": "31"
  396.                 },
  397.                 {
  398.                     "Name": "SFCEnabled",
  399.                     "Value": "true"
  400.                 },
  401.                 {
  402.                     "Name": "DataPartner",
  403.                     "Value": "false"
  404.                 },
  405.                 {
  406.                     "Name": "Vendor1099Enabled",
  407.                     "Value": "true"
  408.                 },
  409.                 {
  410.                     "Name": "TimeTrackingFeatureEnabled",
  411.                     "Value": "true"
  412.                 },
  413.                 {
  414.                     "Name": "FDPEnabled",
  415.                     "Value": "true"
  416.                 },
  417.                 {
  418.                     "Name": "isDTXOnStage",
  419.                     "Value": "false"
  420.                 },
  421.                 {
  422.                     "Name": "ProjectsEnabled",
  423.                     "Value": "true"
  424.                 },
  425.                 {
  426.                     "Name": "VendorAndPurchasesPrefs.UseCustomTxnNumbers",
  427.                     "Value": "false"
  428.                 },
  429.                 {
  430.                     "Name": "DateFormat",
  431.                     "Value": "Month Date Year separated by a slash"
  432.                 },
  433.                 {
  434.                     "Name": "DateFormatMnemonic",
  435.                     "Value": "MMDDYYYY_SEP_SLASH"
  436.                 },
  437.                 {
  438.                     "Name": "NumberFormat",
  439.                     "Value": "US Number Format"
  440.                 },
  441.                 {
  442.                     "Name": "NumberFormatMnemonic",
  443.                     "Value": "US_NB"
  444.                 },
  445.                 {
  446.                     "Name": "WarnDuplicateCheckNumber",
  447.                     "Value": "true"
  448.                 },
  449.                 {
  450.                     "Name": "WarnDuplicateBillNumber",
  451.                     "Value": "false"
  452.                 },
  453.                 {
  454.                     "Name": "WarnDuplicateJournalNumber",
  455.                     "Value": "false"
  456.                 },
  457.                 {
  458.                     "Name": "SignoutInactiveMinutes",
  459.                     "Value": "60"
  460.                 },
  461.                 {
  462.                     "Name": "AccountingInfoPrefs.ShowAccountNumbers",
  463.                     "Value": "false"
  464.                 },
  465.                 {
  466.                     "Name": "VendorAndPurchasesPrefs.PurchaseOrderEnabled",
  467.                     "Value": "true"
  468.                 },
  469.                 {
  470.                     "Name": "VendorAndPurchasesPrefs.MarkupOnBillableExpenseEnabled",
  471.                     "Value": "false"
  472.                 },
  473.                 {
  474.                     "Name": "SalesFormsPrefs.AllowGratuity",
  475.                     "Value": "false"
  476.                 }
  477.             ]
  478.         },
  479.         "domain": "QBO",
  480.         "sparse": false,
  481.         "Id": "1",
  482.         "SyncToken": "3",
  483.         "MetaData": {
  484.             "CreateTime": "2022-07-09T01:51:08-07:00",
  485.             "LastUpdatedTime": "2022-07-11T23:12:35-07:00"
  486.         }
  487.     },
  488.     "time": "2022-08-23T17:12:54.842-07:00"
  489. }
  490. jrs@linux-dev:~/sb/examples$
  491.  
  492.  
  493. *** SQLITE ***
  494.  
  495. jrs@linux-dev:~/sb/examples$ scriba sqlite_demo.sb
  496. 123     -       hello
  497. 234     -       cruel
  498. 345     -       world
  499. jrs@linux-dev:~/sb/examples$
  500.  
  501.  
  502. *** SLRE ***
  503.  
  504. jrs@linux-dev:~/sb/examples$ scriba testslre.sb
  505. 1. Samsung
  506. 2. unveiled
  507. 3. flexible
  508. 4. prototype
  509. 5. developers
  510. 6. apps
  511. jrs@linux-dev:~/sb/examples$
  512.  
« Last Edit: March 28, 2024, 08:41:25 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #18 on: March 29, 2024, 10:36:31 AM »
I was trying to get ODBC to work on Ubuntu yesterday and what a mess. I first tried using the iODBC library but the extension module compile said it was missing sql.h. I then inststalled the unixodbc library which allowed the module compile. I then tried to install the MySQL ODBC  Connector. Oracle only offered them as .deb files. When I tried to install the library from the .deb it said said it had ument conflicts. I tried to install it from a .tarz (other Linux) and manually install the files. When I ran my testodbc.sb program I was getting query errors from the module.

I then tried to install the iODBC library again. It seems they put their .h files in a sub-directory of include. I ended having to copy all the .h files to the include directory. Even secondary .h files didn't have the <iodbc/XXXX.h> prefix. I then installed the SQLite ODBC driver. It failed fetching the data.

ODBC on Linux is a joke! My impression is ODBC is being slowly deprecated on Linux.

Luckily ScriptBasic has a lightening fast C interface to MySQL I rarely use ODBC on Linux.
« Last Edit: March 29, 2024, 02:22:28 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #19 on: March 29, 2024, 12:11:14 PM »
Using libcriba from ScriptBasic or other languages works a little differently than scriba from the console. When you run a script with libscriba, it doesn't destroy the variables created and you can call functions externally using variables defined in the run. You can reset the variables and rerun the script.

I use this feature like an eval function on steroids.
« Last Edit: March 29, 2024, 12:14:21 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #20 on: March 29, 2024, 03:11:02 PM »
This is an example of using the webext extension module to convert a compacted JSON statement to a ScriptBasic associative array. The sbadump() function iis used for debugging to display the the array.

Code: ScriptBasic
  1. IMPORT webext.bas
  2.  
  3. json = """{"id":"0001","type":"donut","name":"Cake","ppu":0.55,"batters":{"batter":[{"id":"1001","type":"Regular"},{"id":"1002","type":"Chocolate"},{"id":"1003","type":"Blueberry"},{"id":"1004","type":"Devil's Food"}]},"topping":[{"id":"5001","type":"None"},{"id":"5002","type":"Glazed"},{"id":"5005","type":"Sugar"},{"id":"5007","type":"Powdered Sugar"},{"id":"5006","type":"Chocolate with Sprinkles"},{"id":"5003","type":"Chocolate"},{"id":"5004","type":"Maple"}]}"""
  4.  
  5. web::json2sba(json)
  6.  
  7. web::sbadump(json)
  8. PRINT "\n\n"
  9. PRINT "Number of batter items:  ", (UBOUND(json{"batters"}{"batter"}) + 1) / 2, "\n"
  10. PRINT "Number of topping items: ", (UBOUND(json{"topping"}) + 1) / 2, "\n\n"
  11.  
  12.  

Formatted JSON
Code: Javascript
  1. {
  2.         "id": "0001",
  3.         "type": "donut",
  4.         "name": "Cake",
  5.         "ppu": 0.55,
  6.         "batters":
  7.                 {
  8.                         "batter":
  9.                                 [
  10.                                         { "id": "1001", "type": "Regular" },
  11.                                         { "id": "1002", "type": "Chocolate" },
  12.                                         { "id": "1003", "type": "Blueberry" },
  13.                                         { "id": "1004", "type": "Devil's Food" }
  14.                                 ]
  15.                 },
  16.         "topping":
  17.                 [
  18.                         { "id": "5001", "type": "None" },
  19.                         { "id": "5002", "type": "Glazed" },
  20.                         { "id": "5005", "type": "Sugar" },
  21.                         { "id": "5007", "type": "Powdered Sugar" },
  22.                         { "id": "5006", "type": "Chocolate with Sprinkles" },
  23.                         { "id": "5003", "type": "Chocolate" },
  24.                         { "id": "5004", "type": "Maple" }
  25.                 ]
  26. }
  27.  

sbadump()
Code: Text
  1. id = 0001
  2. type = donut
  3. name = Cake
  4. ppu = 0.55
  5. batters
  6.    batter
  7.       [1]
  8.          id = 1001
  9.          type = Regular
  10.       [2]
  11.          id = 1002
  12.          type = Chocolate
  13.       [3]
  14.          id = 1003
  15.          type = Blueberry
  16.       [4]
  17.          id = 1004
  18.          type = Devil's Food
  19. topping
  20.    [1]
  21.       id = 5001
  22.       type = None
  23.    [2]
  24.       id = 5002
  25.       type = Glazed
  26.    [3]
  27.       id = 5005
  28.       type = Sugar
  29.    [4]
  30.       id = 5007
  31.       type = Powdered Sugar
  32.    [5]
  33.       id = 5006
  34.       type = Chocolate with Sprinkles
  35.    [6]
  36.       id = 5003
  37.       type = Chocolate
  38.    [7]
  39.       id = 5004
  40.       type = Maple
  41.  
  42.  
  43. Number of batter items:  4
  44. Number of topping items: 7
  45.  
« Last Edit: March 29, 2024, 03:38:06 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #21 on: March 29, 2024, 07:14:19 PM »
It would be great if Charles Pegg would lend a hand and get a 64 bit version of DLLC working. Here is a 32 bit example of DLLC creating an virtual DLL with an ASM function using FII scripting for the call definition.

Code: ScriptBasic
  1.  
  2. include dllc.sbi
  3.  
  4.   oxy=dllfile("oxygen.dll")
  5.  
  6.   o2_basic = dllproc( oxy, "o2_basic i =(c*source) " )
  7.   o2_exec  = dllproc( oxy, "o2_exec  i =(i call)   " )
  8.   o2_error = dllproc( oxy, "o2_error c*=()         " )
  9.   o2_errno = dllproc( oxy, "o2_errno i =()         " )
  10.   o2_len   = dllproc( oxy, "o2_len   i =()         " )
  11.   o2_mode  = dllproc( oxy, "o2_mode     (i mode)   " )
  12.  
  13.   dllcall o2_mode,1
  14.  
  15.   function oxygen(src)
  16.   dllcall o2_basic,src
  17.   if (dllcall(o2_errno)<>0) then
  18.     dllprnt dllcall(o2_error)
  19.     a=0
  20.     line input q
  21.   else
  22.     a=dllcall(o2_exec,0)
  23.   end if
  24.   oxygen=a
  25.   end function
  26.  
  27.  
  28. ' ==============================
  29.  src="""
  30.  extern
  31.  
  32.  function reverse(char*s)
  33.  ========================
  34.  addr ecx,s
  35.  mov edx,0
  36. .rlen
  37.  mov al,[ecx]
  38.  cmp al,0
  39.  jz xlen
  40.  inc edx
  41.  inc ecx
  42.  jmp rlen
  43. .xlen
  44.  ;
  45.  addr ecx,s
  46.  add  edx,ecx
  47.  dec ecx
  48.  ;
  49. .rswap
  50.  inc ecx
  51.  dec edx
  52.  cmp edx,ecx
  53.  jle xswap
  54.  mov al,[ecx]
  55.  mov ah,[edx]
  56.  mov [ecx],ah
  57.  mov [edx],al
  58.  jmp rswap
  59. .xswap
  60.  end function
  61.  
  62.  function getword(char*ss,sys*b) as char*
  63.  '=======================================
  64.  sys a
  65.  if not @ss then return ""
  66.  if b=0 then b=1
  67.  byte s at @ss
  68.  byte c,d
  69.  sys bb,bc
  70.  static char z[128]
  71.  a=0
  72.  bb=b
  73.  '
  74.  'SKIP LEADING SPACES
  75.  do
  76.    c=s[b]
  77.    select c
  78.    case 33 to 255,0 : exit do 'SKIP SPACE
  79.    end select
  80.    b++
  81.  end do
  82.  bc=b
  83.  '
  84.  'QUOTES
  85.  select c
  86.  case 34,39
  87.   do
  88.      b+=1
  89.      d=s[b]
  90.      if d=0 or d=c then b+=1 : jmp fwd done
  91.   end do
  92.  end select
  93.  'WORDS AND SYMBOLS
  94.  do
  95.    c=s[b]
  96.    select c
  97.    case 0 to 32     : exit do
  98.    case 35          : jmp fwd more
  99.    case 33  to 47   : 'symbols
  100.    case 48  to 57   : jmp fwd more 'numbers
  101.    case 58  to 64   : 'symbols
  102.    case 65  to 90   : jmp fwd more 'capitals
  103.    case 95          : jmp fwd more 'underscore
  104.    case 91  to 96   : 'symbols
  105.    case 97  to 122  : jmp fwd more 'lower case
  106.    case 123 to 127  : 'symbols
  107.    case 128 to 255  : jmp fwd more 'higher ascii
  108.    end select
  109.    '
  110.    if b=bc then b++
  111.    exit do
  112.    '
  113.    more:
  114.    b++
  115.  end do
  116.  '
  117.  done:
  118.  '
  119.  if b>bb then
  120.    z=mid ss,bc,b-bc
  121.  else
  122.    z=""
  123.  end if
  124.  return z
  125.  
  126.  end function
  127.  
  128.  
  129. =================
  130. Class AlignedText
  131. =================
  132.  
  133. indexbase 1
  134.  
  135. string  buf, bufo, pr, cr, tab, jus, dlm
  136. sys     Cols, Rows, ColWidth[0x100], TotWidth, ColPad, ld
  137.  
  138. method SetText(char*s)
  139. ======================
  140. if not len cr then cr=chr(13,10)
  141. tab=chr(9)
  142. if not len jus then jus=string 200,"L"
  143. buf=s
  144. measure
  145. end method
  146.  
  147.  
  148. method measure()
  149. ================
  150. sys a, b, wa, wb, cm, c, cw, i
  151. a=1 : b=1
  152. Cols=0 : Rows=0 : ColPad=3
  153. ld=len dlm
  154. if not ld then dlm="," : ld=1 'default to comma
  155. do
  156.  wb=b
  157.  a=instr b,buf,cr
  158.  if a=0 then exit do
  159.  cm=0
  160.  c++
  161.  do
  162.    wa=instr wb,buf,dlm
  163.    if wa=0 or wa>a then exit do
  164.    cm++
  165.    if cm>cols then cols=cm
  166.    cw=wa-wb
  167.    if cw > ColWidth[cm] then ColWidth[cm]=cw
  168.    wb=wa+ld
  169.  end do
  170.  b=a+len cr
  171. end do
  172. rows=c
  173. '
  174. c=0
  175. for i=1 to cols
  176.  ColWidth[ i ]+=ColPad
  177.  c+=ColWidth[ i ]
  178. next
  179. TotWidth=c+len cr
  180. 'print ShowMetrics
  181. end method
  182.  
  183.  
  184. method ShowMetrics() as char*
  185. =============================
  186. sys i
  187. pr="METRICS:" cr cr
  188. pr+=rows tab cols tab totwidth cr cr
  189. pr+="column" tab "spacing" cr
  190. for i=1 to cols
  191.  pr+=i tab ColWidth[ i ] cr
  192. next
  193. return pr
  194. end method
  195.  
  196.  
  197. method justify(char*j)
  198. ======================
  199. jus=j
  200. end method
  201.  
  202. method delimiter(char*j)
  203. ========================
  204. dlm=j
  205. end method
  206.  
  207. method endofline(char*j)
  208. ========================
  209. cr=j
  210. end method
  211.  
  212.  
  213. method layout() as char*
  214. ========================
  215. sys a, b, wa, wb, wl, cm, lpos, cpos, p
  216. bufo=space Rows*TotWidth
  217. a=1 : b=1
  218. do
  219.  wb=b
  220.  a=instr(b,buf,cr)
  221.  if a=0 then exit do
  222.  cm=0
  223.  cpos=1
  224.  do
  225.    wa=instr(wb,buf,dlm)
  226.    if wa=0 or wa>a then exit do
  227.    '
  228.    cm++
  229.    '
  230.    'JUSTIFICATION
  231.    '
  232.    wl=wa-wb
  233.    p=lpos+cpos 'default "L" LEFT ALIGN
  234.    '
  235.    select case asc(jus,cm)
  236.      case "R" : p=lpos+cpos+ColWidth[cm]-wl-Colpad
  237.      case "C" : p=lpos+cpos+( ColWidth[cm]-wl-Colpad )*.5
  238.    end select
  239.    '
  240.    mid bufo,p, mid buf,wb,wl
  241.    cpos+=colwidth[cm]
  242.    wb=wa+ld
  243.  end do
  244.  b=a+len cr
  245.  lpos+=TotWidth
  246.  if lpos<len(bufo) then mid bufo,lpos-1,cr
  247. end do
  248. return bufo
  249. end method
  250. '
  251. end class
  252.  
  253. '#recordof AlignedText
  254.  
  255.  AlignedText atxt
  256.  
  257.  function AlignText(char *in,*ju,*dl,*cr) as char*
  258.  =================================================
  259.  atxt.justify         ju
  260.  atxt.delimiter       dl
  261.  atxt.endofline       cr
  262.  atxt.SetText         in
  263.  return               atxt.layout
  264.  end function
  265.  
  266.  
  267.  sub finish()
  268.  ============
  269.  terminate
  270.  end sub
  271.  
  272.  
  273.  
  274.  function link(sys n) as sys
  275.  ===========================
  276.  select n
  277.  case 0 : return @finish
  278.  case 1 : return @reverse
  279.  case 2 : return @getword
  280.  case 3 : return @aligntext
  281.  end select
  282.  end function
  283.  
  284.  end extern
  285.  
  286.  
  287.  addr link
  288.  """
  289. ' ==============================
  290.  
  291.   '
  292.  a=oxygen(src)
  293.   '
  294.  if (a<>0) then
  295.   '
  296. ' ==============================
  297.  '
  298.  Finish    = dllproc(a,"Finish     ()        ", dllcald(a,0) )
  299.   Reverse   = dllproc(a,"Reverse    (c*value) ", dllcald(a,1) )
  300.   GetWord   = dllproc(a,"GetWord c*=(c*value,i*index) ", dllcald(a,2) )
  301.   AlignText = dllproc(a,"AlignText c*=(c*in,c*jus,c*dlm,c*cr) ", dllcald(a,3) )
  302.   '
  303. ' ==============================
  304.  '
  305.  s="abcdef1234567"
  306.   print "Reversed " & s & " = "
  307.   dllcall(Reverse,s)
  308.   print s & "\n"
  309.   '
  310.  '
  311.  s="one two three"
  312.   i=1
  313.   dllcall(GetWord,s,i)
  314.   print dllcall(GetWord,s,i) & "\n"
  315.   dllcall(GetWord,s,i)
  316.  
  317.  
  318. s="""
  319. Given;;a;;text;;file;;of;;many;;lines,;;where;;fields;;within;;a;;line;;
  320. are;;delineated;;by;;a;;single;;'dollar';;character,;;write;;a;;program
  321. that;;aligns;;each;;column;;of;;fields;;by;;ensuring;;that;;words;;in;;each;;
  322. column;;are;;separated;;by;;at;;least;;one;;space.
  323. Further,;;allow;;for;;each;;word;;in;;a;;column;;to;;be;;either;;left;;
  324. justified,;;right;;justified,;;or;;center;;justified;;within;;its;;column.
  325. """
  326.  
  327.   lf="\n" & chr(0)
  328.   dl=";;"
  329.   fm="LLLLCCCRRRRR"
  330.   ' t=dllcall(AlignText,s,fm,dl,lf )
  331.  t=dllcall(AlignText,s,"LLLLCCCRRRRR",";;","\n" & chr(0) )
  332.   print t & "\n"
  333.  
  334.   dllcall(Finish)
  335.   '
  336.  end if
  337.   dllfile
  338.  

Output


C:\ScriptBasic\examples>sbc dllco2asm.sb
Reversed abcdef1234567 = 7654321fedcba
two

 Given        a            text         file       of       many        lines,        where   fields   within        a   line
 are          delineated   by           a        single   'dollar'    character,      write        a
 that         aligns       each         column     of       fields        by       ensuring     that    words       in   each
 column       are          separated    by         at       least         one
 Further,     allow        for          each      word        in          a          column       to       be   either   left
 justified,   right        justified,   or       center   justified     within          its

C:\ScriptBasic\examples>
« Last Edit: March 29, 2024, 07:16:16 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #22 on: March 29, 2024, 07:47:09 PM »
I'm working on building a ScriptBasic 3.0 32 bit version which will include the following features. I have used non-UI based COM objects with the ScriptBasic web server.

This will be offered in executable form only as a Windows installer. The code is frozen and I have no plans on enhancing the 32 bit version further.
  • COM / OLE / VB6 support
  • VB6 UI based IDE/Debugger
  • DLLC for FFI scripting and O2 virtual DLLs
  • libscriba that works
  • Both console (sbc) and Windows (sbw) interpreters
« Last Edit: March 31, 2024, 05:52:18 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #23 on: March 29, 2024, 08:34:21 PM »
This is an example of using DLLC with the FreeImage library with the functions interface definitions scripted.

Code: ScriptBasic
  1. ' FreeImage Example  
  2.  
  3. DECLARE SUB DLLC_File ALIAS "dllfile" LIB "DLLC"  
  4. DECLARE SUB DLLC_Proc ALIAS "dllproc" LIB "DLLC"  
  5. DECLARE SUB DLLC_Call ALIAS "dllcall" LIB "DLLC"  
  6.  
  7. fih=dllc_file("/scriptbasic/bin/Freeimage.dll")
  8.  
  9. Version = DLLC_Proc(fih,"_FreeImage_GetVersion@0 z = ( )")  
  10. Copyright = DLLC_Proc(fih,"_FreeImage_GetCopyrightMessage@0 z = ( )")  
  11. LoadImage  = DLLC_Proc(fih,"_FreeImage_Load@12 i = (i fif, z filename, i flag)")  
  12. Width = DLLC_Proc(fih,"_FreeImage_GetWidth@4 i = (i dib)")  
  13. Height = DLLC_Proc(fih,"_FreeImage_GetHeight@4 i = (i dib)")  
  14. Rescale = DLLC_Proc(fih,"_FreeImage_Rescale@16 i = (i dib, i dst_width, i dst_height, i filter)")  
  15. Rotate = DLLC_Proc(fih,"_FreeImage_Rotate@16 i = (i dib, d angle, p bkcolor)")  
  16. Save = DLLC_Proc(fih,"_FreeImage_Save@16 b = (i fif, i dib, z fname, i flage)")  
  17.  
  18. CONST FIF_BMP  =  0  
  19. CONST FIF_JPEG =  2  
  20. CONST FIF_PNG  = 13  
  21. CONST FIF_GIF  = 25  
  22. CONST FILTER_BICUBIC = 1  
  23.  
  24. fimg_in    = "world.jpg\0"
  25. fimg_small = "world_small.png\0"
  26. fimg_flip  = "world_flip.png\0"
  27.  
  28. PRINT DLLC_Call(Version),"\n"  
  29. PRINT DLLC_Call(Copyright),"\n"  
  30. fbmp = DLLC_Call(LoadImage, FIF_JPEG, fimg_in, 0)  
  31. PRINT "Width: ",DLLC_Call(Width, fbmp),"\n"  
  32. PRINT "Height: ",DLLC_Call(Height, fbmp),"\n"  
  33. fbmps = DLLC_Call(Rescale, fbmp, 100, 100, FILTER_BICUBIC)  
  34. DLLC_Call(Save, FIF_PNG, fbmps, fimg_small, 0)  
  35. fbmpr = DLLC_Call(Rotate, fbmp, 180, 0)  
  36. DLLC_Call(Save, FIF_PNG, fbmpr, fimg_flip, 0)
  37.  
  38. line input u  
  39.  

Output

C:\ScriptBasic\examples>sbc DllcFreeImage2.sb
3.18.0
This program uses FreeImage, a free, open source image library supporting all common bitmap formats. See http://freeimage.sourceforge.net for details
Width: 225
Height: 225

C:\ScriptBasic\examples>


The world.jpg was the original image. The other two were created with this example.
« Last Edit: March 29, 2024, 08:39:58 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #24 on: March 29, 2024, 09:58:40 PM »
Here is a screen shot of the ScriptBasic IDE / Debugger working with the COM SAPI component. This feature is only in the 32 bit version of ScriptBasic.



Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #25 on: March 29, 2024, 10:50:11 PM »
I'm going to include the SDL-GFX graphic extension module in the ScriptBasic Windows 32 bit installer.

Fern
Code: ScriptBasic
  1. ' ScriptBasic GFX - Fern
  2.  
  3. IMPORT gfx.sbi
  4.  
  5. s = gfx::Window(640,500,"ScriptBasic GFX Fern")
  6. RANDOMIZE(gfx::Time())
  7. SPLITA STRING(3,"0") BY "" TO xy
  8.  
  9. SUB Fern
  10. r = RND() % 100
  11. IF r <= 10 THEN
  12.    SPLIT "0,0,0,0.16,0,0" BY "," TO a,b,c,d,e,f
  13. ELSE IF r > 1 AND r <=86 THEN
  14.    SPLIT "0.85,0.04,-.04,0.85,0,1.60" BY "," TO a,b,c,d,e,f
  15. ELSE IF r > 86 AND r <=93 THEN
  16.    SPLIT "0.2,-.26,0.23,0.22,0,0.16" BY "," TO a,b,c,d,e,f
  17. ELSE
  18.    SPLIT "-.15,0.28,0.26,0.24,0,0.44" BY "," TO a,b,c,d,e,f
  19. END IF
  20. newx = ((a * xy[1]) + (b * xy[2]) + e)
  21. newy = ((c * xy[1]) + (d * xy[2]) + f)
  22. xy[1] = newx
  23. xy[2] = newy
  24. gfx::pixelRGBA s, INT(xy[1]*40+300), INT(-xy[2]*40+450), 0, 210, 55, 255
  25. END SUB
  26.  
  27. ts = gfx::Time()
  28. FOR w=1 TO 250000
  29.     Fern
  30. NEXT
  31. te = gfx::Time()
  32. gfx::stringColor s, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xffffffff
  33. gfx::Update
  34. WHILE gfx::KeyName(1) <> "+escape"
  35. WEND
  36. gfx::Close
  37.  



Mandelbrot
Code: ScriptBasic
  1. ' ScriptBasic GFX - Mandelbrot
  2.  
  3. IMPORT gfx.sbi
  4.  
  5. s = gfx::Window(640,480,"ScriptBasic SDL_gfx Mandelbrot")
  6. ts = gfx::Time()
  7. FOR y = 0 TO 479
  8.   FOR x = 0 TO 639
  9.     cx = (x - 320) / 120
  10.     cy = (y - 240) / 120
  11.     rit = gfx::Mandelbrot(cx, cy, 510)
  12.     gfx::PixelRGBA s, x, y, rit * 32, rit * 16, rit * 8, 255
  13.   NEXT
  14. NEXT
  15. te = gfx::Time()
  16. gfx::stringColor s, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0x000000ff
  17. gfx::Update
  18. WHILE gfx::KeyName(1) <> "+escape"
  19. WEND
  20. gfx::Close
  21.  



Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #26 on: March 30, 2024, 10:30:38 AM »
This is an example of some of the SDL-gfx graphics primitives. The SDL-gfx extension module was the best example of using CBASIC. SDL- gfx Source

Code: ScriptBasic
  1. ' SDL_gfx Demo
  2.  
  3. IMPORT gfx.sbi
  4.  
  5. win = gfx::Window(700, 600, "ScriptBasic SDL_gfx Demo")
  6. gfx::pixelRGBA(win, 10, 15, 255, 255, 255, 255)
  7. gfx::lineRGBA(win, 20, 10, 70, 90, 255, 0, 0, 255)
  8. gfx::trigonRGBA(win, 500, 50, 550, 200, 600, 150, 0, 255, 255, 255)
  9. gfx::filledTrigonRGBA(win, 200, 200, 300, 50, 400, 200, 0, 0, 255, 255)
  10. gfx::rectangleRGBA(win, 10, 300, 100, 380, 0, 255, 0, 255)
  11. gfx::boxRGBA(win, 210, 76, 325, 300, 255, 0, 0, 150)
  12. gfx::ellipseRGBA(win, 600, 400, 50, 90, 255, 255, 0, 200)
  13. gfx::filledEllipseRGBA(win, 600, 400, 25, 150, 0, 255, 0, 255)
  14. SPLIT "350,275,300,325,350,400,325,325,390,390,375" BY "," TO _
  15.       x[0],x[1],x[2],x[3],x[4],x[5],y[0],y[1],y[2],y[3],y[4]
  16. gfx::polygonRGBA(win, x, y, 6, 255, 255, 255, 155)
  17. SPLIT "400,450,450,425,300,400,410,450,425,500" BY "," TO _
  18.       s[0],s[1],s[2],s[3],s[4],t[0],t[1],t[2],t[3],t[4]
  19. gfx::filledPolygonRGBA(win, s, t, 5, 255, 0, 255, 155)
  20. gfx::stringColor win, 250, 550, "Press ESC key to QUIT" & CHR(0), 0xffffffff
  21. gfx::Update
  22. WHILE gfx::KeyName(1) <> "+escape"
  23. WEND
  24. gfx::Close
  25.  


« Last Edit: March 30, 2024, 11:46:17 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #27 on: March 30, 2024, 12:38:15 PM »
The ScriptBasic COM extension integrates well with VB6 allowing callbacks to ScriptBasic on VB6 events. I use VB6  to create form and class OCXs (DLLs) with ScriptBasic as the main program. The screen shot attached is a time keeping project I did for a client. This is the OCX form / class library for the project.
« Last Edit: May 13, 2024, 03:24:22 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #28 on: March 31, 2024, 07:17:40 PM »
The Windows 32 bit ScriptBasic 3.0 release will only be offered in binary format as an installer. It will offer the following features.
  • A CallByName COM extension module with VB6 support.
  • cURL extension module for http(s) access.
  • ODBC direct C API extension module. (no OLEDB)
  • SDL-gfx extension module for games and general graphics.
  • MySQL C API extension module. (fastest DB I've used)
  • SQLite extension module. (:memory: and file DBs)
  • DLLC extension module for FFI scripting  and O2 virtual functions including ASM.
  • SBT extension module for running scripts as threads and embedding libscriba in ScriptBasic.
  • JSON extension module.
  • MXML extension module.
  • ScriptBasic Application Web Server (standalone / proxy)
  • WEBEXT extension module for JSON ScriptBasic associative arrays.
  • ZLIB in memory compression extension module.

This distribution will be available from the ScriptBasic repository with examples and documentation wiki. I'll post the source to the extension modules which can be compiled with TDM-GCC-32. Hopefully others will extend the modules by including missing functions and features.

The ScriptBasic 64 bit version is focused on web apps and glue scripts that may be run in the Windows scheduler. This version should be used if you plan on modifying ScriptBasic source.
« Last Edit: April 03, 2024, 12:25:43 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3598
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #29 on: March 31, 2024, 08:41:34 PM »
ScriptBasic is traditional BASIC for the most part with these differences.
  • Variables are of a variant type and require no DIM including arrays. 1 + "2" = 3  1 & 2 = 12
  • Arrays can be indexed based, associative or a combination of both with no practical dimension limits.  PRINT sba[id]{"name"},"\n"  This creates a 500000 element array of undef values.
Code: ScriptBasic
  1. a[500000] = undef
  2. a[1000000] = undef
  3. PRINT LBOUND(a),"\n"
  4. PRINT UBOUND(a),"\n"
  5.  
  6. C:\ScriptBasic\examples>sbc testdim.sb
  7. 500000
  8. 1000000
  9.  
  10. C:\ScriptBasic\examples>
  11.  
  • String function searches can be case sensitive (default) or not.
  • ScriptBasic supports GOTO / GOSUB RETURN.
  • SPLIT(A) can split delimited strings into arrays or assign a list of variables.
  • LIKE will extract data from a string based on a template string.
  • IF/THEN/IF THEN/ELSE replace the need for a SELECT structure.
  • Strings can be multi-line with embedded quotes using """. Remarks work the same way.
  • ScriptBasic supports namespaces (MODULE / END MODULE) and are referenced with namespace::FUNCTION/SUB.
  • ScriptBasic supports an easy to use C extension API.
  • ScriptBasic uses a thread safe memory model.

Everything else is traditional BASIC syntax.

ScriptBasic supports using line numbers (actually labels) and defining your string variables with a $. String functions support appending a $ to its name. LET A=1 works even thought the docs say LET is unsupported.

Unsupported
Code: Text
  1. a=1:b=2:c=3
  2.  

Supported
Code: ScriptBasic
  1. SPLIT "1,2,3" BY "," TO a,b,c
  2.  


« Last Edit: May 18, 2024, 10:40:14 AM by John »