Recent Posts

Pages: 1 ... 7 8 [9] 10
81
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 09, 2024, 12:46:41 AM »
Based on what I've read it looks like long is 32 bit on Windows 64 bit compiled C code. One would have to use long long for 64 bit values. It looks to me like a major refactoring job of the code. I'm hoping someone comes up which a better story.


[32-bit Linux]

me@u32:~$ ./sizes32
sizeof(char):      1
sizeof(short):     2
sizeof(int):       4
sizeof(long):      4
sizeof(long long): 8

[64-bit Linux]

me@u64:~$ ./sizes64
sizeof(char):      1
sizeof(short):     2
sizeof(int):       4
sizeof(long):      8
sizeof(long long): 8

[32-bit Windows]

C:\Users\me\Downloads>sizes32.exe
sizeof(char):      1
sizeof(short):     2
sizeof(int):       4
sizeof(long):      4
sizeof(long long): 8

[64-bit Windows]

C:\Users\me\Downloads>sizes64.exe
sizeof(char):      1
sizeof(short):     2
sizeof(int):       4
sizeof(long):      4
sizeof(long long): 8


Based on Linux LONG  being 8 bytes wide and ScriptBasic working fine, defining LONG  as long long would probably work but break interfacing with other 64 bit libraries passing 4 byte longs.

Quote

Windows x64 is a hybrid operating system, meaning many components (e.g. Internet Explorer, Windows Media Player, etc.) are present in both 32bit and 64bit variants and most 32bit programs work just as well with Windows x64.

is it worth to change? only if you have more than 4 GB RAM in your system.
82
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 08, 2024, 03:50:38 PM »
I tried to fix the issue with the 64 bit version of ScriptBasic for Windows not using LLONG_MAX and LLONG_MIN to return a 64 bit value. This is the code AIR suggested to resolve the issue. Unfortunately I think more needs to be dome to get 32 bit LONG to be LONG LONG on 64 bit.

Code: C
  1. // AIR code - JRS implemented
  2. #if (_MSC_VER > 0)     // check if MSVC
  3.     #ifdef _WIN64      // check if 64bit
  4.        #define LONG_MIN LLONG_MIN
  5.        #define LONG_MAX LLONG_MAX
  6.     #endif
  7. #endif
  8.  

Code: ScriptBasic
  1. PRINT "MIN_INT: ",MININT,"\n"
  2. PRINT "MAX_INT: ",MAXINT,"\n"
  3.  


C:\ScriptBasic64\examples>..\bin\scriba.exe minmax.sb
MIN_INT: 0
MAX_INT: -1

C:\ScriptBasic64\examples>


Linux 64 Bit
jrs@linux-dev:~/sb/examples$ scriba minmax.sb
MIN_INT: -9223372036854775808
MAX_INT: 9223372036854775807
jrs@linux-dev:~/sb/examples$

Windows 32 Bit
C:\ScriptBasic64\examples>sbc minmax.sb
MIN_INT: -2147483648
MAX_INT: 2147483647

C:\ScriptBasic64\examples>

Windows 64 Bit
C:\ScriptBasic64\bin>scriba.exe ..\examples\minmax.sb
MAX_INT: 2147483647

C:\ScriptBasic64\bin>

SCRIBA says there is no MININT command. ???


I'm wondering if this 32 / 64 bit mismatch is the reason libscriba isn't working on 64 bit Window. (works on 64 bit Linux) I have no interest in the sb-dev-msvc build system create anything other than 64 bit executables.

This sounds discouraging.
https://stackoverflow.com/questions/49311731/force-lp64-data-model-with-gcc-or-clang-in-windows


LONG_MAX (largest signed long)
  32-bit  2,147,483,647
  64-bit  9,223,372,036,854,775,807
ULONG_MAX (largest unsigned long)
  32-bit  4,294,967,295
  64-bit 18,446,744,073,709,551,615


MSVC is treating LONG_MAX as a 32 bit number not 64 bit on a Windows 64 bit compile.

If you have any suggestions that might resolve this issue, it would be appreciated.
83
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 07, 2024, 05:33:17 PM »
This is an example of DLLC making callbacks from ScriptBasic scripts running as threads.

main_proc.sb
Code: ScriptBasic
  1. IMPORT dllc.sbi
  2.  
  3. dllcnsl 1
  4. bdat = STRING(8192, chr(0))
  5. idat = dllsptr(bdat)
  6. ' program,function-name, thread-flag, shared-data
  7. thrM1 = dlltran("Thread-A.sb", "main::main", 1, idat)
  8. thrM2 = dlltran("Thread-B.sb", "main::main", 1, idat)
  9. dllprnt("Thread Handles: " & thrM1 & "   " & thrM2 & "\n\n")
  10. dllwait(10000, thrM1, thrM2)
  11. dllclos(thrM1, thrM2)
  12. dllprnt("Thread scripts closed: "  & thrM1 & "  " & thrM2  & "\n")
  13. dllfile()
  14. dllprnt("DLLs released\n")
  15.  

Thread-A.sb
Code: ScriptBasic
  1. IMPORT "C:/Scriptbasic/include/dllc.sbi"
  2.  
  3. dllcnsl(1)
  4.  
  5. ' LINK TO TEST DLL
  6. dllwait(100)
  7. testf = dllfile("DllcTestDll.dll")
  8.  
  9. ' THREAD TEST
  10. FUNCTION SimpleMultiThreadTest(a)
  11.   tic = dllproc(testf,"tic i=(c*msg)")
  12.   thr1 = dllcalt(tic, 1)
  13.   dllprnt("Thread-A Waiting here for tick and tock to finish\n")
  14.   dllwait(10000, thr1)
  15.   dllclos(thr1)
  16.   dllprnt("Script Thread-A tick & tock threads closed: " & thr1 & ", " & thr2 & "\n")
  17. END FUNCTION
  18.  
  19. ' SET UP AND TESTCALLBACKS
  20. SetCallBack=dllProc(testf,"SetCallBack i=(i pfunction)")
  21. MakeCallBacks=dllProc(testf,"MakeCallBacks i=()")
  22.  
  23. FUNCTION callBackA(dat)
  24.   dllprnt("CallBack Thread-A " & dat & "\n")
  25. END FUNCTION
  26.  
  27. FUNCTION CallBackTests(pProg, a, idat)
  28.   pFunc=dllclbk(2,pProg,"main::callbacka",1,-1,idat)
  29.   dllcall(SetCallBack,pFunc)
  30.   ' Run Callbacks Directly Or In Thread
  31.  IF (a = 0) THEN
  32.     dllcall(MakeCallBacks)
  33.   ELSE
  34.     thr3 = dllcalt(MakeCallBacks)
  35.     dllprnt("Thread-A Waiting here:" & thr3 & "\n")
  36.     dllwait(10000, thr3)
  37.     dllclos(thr3)
  38.     dllprnt("Thread-A CallBacks Thread Closed\n")
  39.   END IF
  40. END FUNCTION
  41.  
  42. ' MAIN FUNCTION
  43. FUNCTION main(pProg, idat)
  44. dllprnt("Thread-A Main now running\n")
  45. dllprnt("idat: " & idat & "\n")
  46. CallBackTests(pProg, 0, idat)
  47. dllprnt("Thread-A Main now finished\n")
  48. main = 0
  49. END FUNCTION
  50.  
  51. FUNCTION finish(pProg, idat)
  52. END FUNCTION
  53.  

Thread-B.sb
Code: ScriptBasic
  1. IMPORT "C:/Scriptbasic/include/dllc.sbi"
  2.  
  3. ' LINK TO TEST DLL
  4. dllwait 120
  5. testf = dllfile("DllcTestDll.dll")
  6. PRINT testf, "\n"
  7.  
  8. ' THREAD TEST
  9. FUNCTION SimpleMultiThreadTest(a)
  10.   tic = dllproc(testf, "tic i=(c*msg)")
  11.   thr1 = dllcalt(tic, 1)
  12.   thr2 = dllcalt(tic, 2)
  13.   dllprnt "Script Thread-B Waiting here for tick and tock to finish\n"
  14.   dllwait(10000, thr1, thr2)
  15.   dllclos(thr1, thr2)
  16.   dllprnt("Thread-B tick & tock threads closed: " & thr1 & ", " & thr2 & "\n")
  17. END FUNCTION
  18.  
  19. ' SET UP AND TESTCALLBACKS
  20. SetCallBack = dllProc(testf, "SetCallBack i=(i pfunction)")
  21. MakeCallBacks = dllProc(testf, "MakeCallBacks i=()")
  22.  
  23. FUNCTION callBackA(dat)
  24.   dllprnt "CallBack Thread-A " & dat & "\n"
  25. END FUNCTION
  26.  
  27. FUNCTION CallBackTests(pProg,a,idat)
  28.   pFunc = dllclbk(2,pProg,"main::callbacka",1,-1,idat)
  29.   dllcall(SetCallBack,pFunc)
  30.  
  31.   ' RUN CALLBACKS DIRECTLY OR IN THREAD
  32.  IF (a = 0) then
  33.     dllcall(MakeCallBacks)
  34.   ELSE
  35.     thr3 = dllcalt(MakeCallBacks)
  36.     dllprnt("Thread-B Waiting here:" & thr3 & "\n")
  37.     dllwait(10000, thr3)
  38.     dllclos(thr3)
  39.     dllprnt("Thread-B CallBacks Thread" & thr3 & " Closed\n")
  40.   END IF
  41.   dllwait(500)
  42. END FUNCTION
  43.  
  44. ' MAIN FUNCTION
  45. FUNCTION main(pProg, idat)
  46.   dllprnt("Thread-B Main now running\n")
  47.   SimpleMultiThreadTest(0)
  48.   dllwait 200
  49.   CallBackTests pProg,0,idat
  50.   dllprnt("Thread-B Main now finished\n")
  51.   main=0
  52. END FUNCTION
  53.  

OUTPUT

C:\sb_examples\dllc>sbc main_proc.sb
Thread-A Main now running
idat: 13612276
CallBack Thread-A 1
4
Thread-B Main now running
tick
Thread Handles: 416   420

tock
Script Thread-B Waiting here for tick and tock to finish
CallBack Thread-A 2
tick
tock
CallBack Thread-A 3
tick
tock
CallBack Thread-A 4
tick
tock
CallBack Thread-A 5
tick
tock
Thread-A Main now finished
Thread-B tick & tock threads closed: 424, 428
CallBack Thread-A 1
CallBack Thread-A 2
CallBack Thread-A 3
CallBack Thread-A 4
CallBack Thread-A 5
Thread-B Main now finished
Thread scripts closed: 416  420
DLLs released

C:\sb_examples\dllc>

84
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 07, 2024, 02:36:19 PM »
I had added getting table schema info from the ODBC extension module that isn't documented in the ODBC extension module documentation. I also have a COM version that gets the INDEX / KEY info. I may release it at a later time..

The FetchSchema function is currently only available in the Windows 32 bit version of ScriptBasic.

Code: ScriptBasic
  1. IMPORT odbc.sbi
  2.  
  3. dbh = odbc::RealConnect("SQLDemo","","")
  4. odbc::Query(dbh,"SELECT * FROM products LIMIT 1")
  5. odbc::FetchSchema(dbh,col)
  6.  
  7. create_stmt = "CREATE TABLE products(\n"
  8. FOR x = 0 TO UBOUND(col) STEP 5
  9.   create_stmt &= col[x] & " "
  10.   IF col[x + 1] = -1 THEN create_stmt &= "TEXT(" & col[x + 2] & ") "
  11.   IF col[x + 1] = 3 THEN create_stmt &= "DECIMAL(" & col[x + 2] & "," & col[x + 3] & ") "
  12.   IF col[x + 1] = 5 THEN create_stmt &= "SMALLINT(" & col[x + 2] & ") "
  13.   IF col[x + 1] = 12 THEN create_stmt &= "VARCHAR(" & col[x + 2] & ") "
  14.   IF col[x + 1] = 91 THEN create_stmt &= "DATE "
  15.   IF col[x + 4] THEN
  16.     create_stmt &= "NULL,\n"
  17.   ELSE
  18.     create_stmt &= "NOT NULL,\n"
  19.   END IF
  20. NEXT
  21.  
  22. create_stmt = LEFT(create_stmt, LEN(create_stmt) - 2)
  23. create_stmt &= ")"
  24.  
  25. PRINT create_stmt, "\n"
  26.    
  27. odbc::Close(dbh)
  28.  

Output

CREATE TABLE products(
productCode VARCHAR(15) NOT NULL,
productName VARCHAR(70) NOT NULL,
productLine VARCHAR(50) NOT NULL,
productScale VARCHAR(10) NOT NULL,
productVendor VARCHAR(50) NOT NULL,
productDescription TEXT(65535) NOT NULL,
quantityInStock SMALLINT(5) NOT NULL,
buyPrice DECIMAL(10,2) NOT NULL,
MSRP DECIMAL(10,2) NOT NULL)



SQL_TEXT -1
SQL_UNKNOWN_TYPE 0   
SQL_CHAR 1           
SQL_NUMERIC 2       
SQL_DECIMAL 3       
SQL_INTEGER 4       
SQL_SMALLINT 5       
SQL_FLOAT 6         
SQL_REAL 7           
SQL_DOUBLE 8         
SQL_DATETIME 9       
SQL_VARCHAR 12       
SQL_TYPE_DATE 91     
SQL_TYPE_TIME 92     
SQL_TYPE_TIMESTAMP 93



Column Name: productCode, Type: 12, Size: 15, Digits: 0, Nullable: 0
Column Name: productName, Type: 12, Size: 70, Digits: 0, Nullable: 0
Column Name: productLine, Type: 12, Size: 50, Digits: 0, Nullable: 0
Column Name: productScale, Type: 12, Size: 10, Digits: 0, Nullable: 0
Column Name: productVendor, Type: 12, Size: 50, Digits: 0, Nullable: 0
Column Name: productDescription, Type: -1, Size: 65535, Digits: 0, Nullable: 0
Column Name: quantityInStock, Type: 5, Size: 5, Digits: 0, Nullable: 0
Column Name: buyPrice, Type: 3, Size: 10, Digits: 2, Nullable: 0
Column Name: MSRP, Type: 3, Size: 10, Digits: 2, Nullable: 0


Code: SQL
  1. CREATE TABLE `products` (
  2.   `productCode` VARCHAR(15) NOT NULL,
  3.   `productName` VARCHAR(70) NOT NULL,
  4.   `productLine` VARCHAR(50) NOT NULL,
  5.   `productScale` VARCHAR(10) NOT NULL,
  6.   `productVendor` VARCHAR(50) NOT NULL,
  7.   `productDescription` text NOT NULL,
  8.   `quantityInStock` SMALLINT(6) NOT NULL,
  9.   `buyPrice` DECIMAL(10,2) NOT NULL,
  10.   `MSRP` DECIMAL(10,2) NOT NULL,
  11.   PRIMARY KEY (`productCode`),
  12.   KEY `productLine` (`productLine`),
  13.   CONSTRAINT `products_ibfk_1` FOREIGN KEY (`productLine`) REFERENCES `productlines` (`productLine`)
  14. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  15.  
85
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 06, 2024, 06:50:35 PM »
The gfx extension module is based on SDL 1.2. I would like to see the gfx module for Windows 64 bit to be based on SDL 2.x. I found a migration guide that looks helpful.

SDL 1.2 to 2.0 Migration Guide

The ScriptBasic project is looking for someone to bring SDL-gfx to 64 bit. Hopefully you have gaming experience and can create a few examples as well.
86
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 05, 2024, 03:59:30 PM »
The DLLC extension module allows starting ScriptBasic scripts as threads with callbacks to function / subs in the main process. I will include an example after I get the ScriptBasic Windows 32 bit 3.0 installer released.

The SBT extension module offers a similar feature but you have to use the MT module to pass variables between the main process and other threads.
87
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 04, 2024, 04:22:17 PM »
Update

I have tested all the extension modules that will be included in the ScriptBasic Windows 32 bit 3.0 release. I've created an examples directory with sub-directories for each module. I'm finishing up the DLLC examples using Charles Pegge's test scripts as a resource.

I need to update the Inno installer script I have been using in prior releases with the new additions.

It won't be long before I get this on the ScriptBasic repository.
88
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 03, 2024, 01:12:42 PM »
This is the ScriptBasic include file for the DLLC extension module.

Code: ScriptBasic
  1. '  supported types:
  2. '  b bool
  3. '  c char
  4. '  d double precision float
  5. '  f float
  6. '  h handle
  7. '  i integer (32bit)
  8. '  p pointer
  9. '  q quad (64bit) integer
  10. '  s short (16bit) integer
  11. '  z null terminated string
  12.  
  13. '  supported calling conventions
  14. '  cdecl
  15. '  stdcall
  16.  
  17. '  '*' signifies pass variable by reference, otherwise by value
  18.  
  19.  
  20.   'DIAGNOSTICS  
  21.  declare sub dllhook alias "dllhook" lib "DLLC"
  22.   declare sub dllshow alias "dllshow" lib "DLLC"
  23.   declare sub dllreco alias "dllreco" lib "DLLC"
  24.   declare sub dllsecs alias "dllsecs" lib "DLLC"
  25.   declare sub dllerrc alias "dllerrc" lib "DLLC"
  26.   declare sub dllerrs alias "dllerrs" lib "DLLC"
  27.  
  28.  'CONSOLE
  29.  declare sub dllcnsl alias "dllcnsl" lib "DLLC"
  30.   declare sub dlllnpt alias "dlllnpt" lib "DLLC"
  31.   declare sub dllprnt alias "dllprnt" lib "DLLC"
  32.   declare sub dllcmnd alias "dllcmnd" lib "DLLC"
  33.   'DLL LINKAGE
  34.  declare sub dllfile alias "dllfile" lib "DLLC"
  35.   declare sub dllproc alias "dllproc" lib "DLLC"
  36.   'DLL CALLS
  37.  declare sub dllmeth alias "dllmeth" lib "DLLC"
  38.   declare sub dllcall alias "dllcall" lib "DLLC"
  39.   declare sub dllcald alias "dllcald" lib "DLLC"
  40.   declare sub dllcalt alias "dllcalt" lib "DLLC"
  41.   declare sub dllcobj alias "dllcobj" lib "DLLC"
  42.   declare sub dllcobt alias "dllcobt" lib "DLLC"
  43.   declare sub dllclbk alias "dllclbk" lib "DLLC"
  44.   'SBCALLS
  45.  declare sub dllprog alias "dllprog" lib "dllc"
  46.   declare sub dllendp alias "dllendp" lib "dllc"
  47.   declare sub dlltran alias "dlltran" lib "DLLC"
  48.   'CHANNELS AND THREADS
  49.  declare sub dllidat alias "dllidat" lib "DLLC"
  50.   declare sub dllodat alias "dllodat" lib "DLLC"
  51.   declare sub dllclos alias "dllclos" lib "DLLC"
  52.   declare sub dllwait alias "dllwait" lib "DLLC"
  53.   'DATA
  54.  declare sub dllsptr alias "dllsptr" lib "DLLC"
  55.   declare sub dlltype alias "dlltype" lib "DLLC"
  56.   declare sub dlldimv alias "dlldimv" lib "DLLC"
  57.   declare sub dllfill alias "dllfill" lib "DLLC"
  58.   declare sub dllgetm alias "dllgetm" lib "DLLC"
  59.   declare sub dllputm alias "dllputm" lib "DLLC"
  60.   declare sub dllptrm alias "dllptrm" lib "DLLC"
  61.   declare sub dllfrem alias "dllfrem" lib "DLLC"
  62.   'STRINGS / GUIDS
  63.  declare sub dlldelo alias "dlldelo" lib "DLLC"
  64.   declare sub dllostr alias "dllostr" lib "DLLC"
  65.   declare sub dllzstr alias "dllzstr" lib "DLLC"
  66.   declare sub dllastr alias "dllastr" lib "DLLC"
  67.   declare sub dllwstr alias "dllwstr" lib "DLLC"
  68.   declare sub dllcast alias "dllcast" lib "DLLC"
  69.   declare sub dllguid alias "dllguid" lib "DLLC"
  70.  
  71. '  current limits:
  72. '  ===============
  73.  
  74. '  32   parameters per procedure
  75. '  2048 entities (total of libs+procs+types+vars)
  76.  
89
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John on April 01, 2024, 05:06:50 PM »
I'm happy to announce that the current version of oxygen.dll (32 bit) works with DLLC and embedding with libscriba.dll.

You could create an extension module wrapping a C library with DLLC FFI scripting and not have to compile anything.

I plan to have a few examples of using DLLC on the ScriptBasic repo.
90
ScriptBasic Blog / Re: ScriptBasic 3.0
« Last post by John 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.  


Pages: 1 ... 7 8 [9] 10