Author Topic: ScriptBasic 3.0  (Read 11086 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #30 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.
« Last Edit: April 01, 2024, 05:27:39 PM by John »

Offline John

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

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #32 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.
« Last Edit: April 04, 2024, 08:08:40 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #33 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.
« Last Edit: April 05, 2024, 04:05:02 PM by John »

Offline John

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

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #35 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.  
« Last Edit: April 07, 2024, 07:36:28 PM by John »

Offline John

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

« Last Edit: April 08, 2024, 10:09:52 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #37 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.
« Last Edit: May 16, 2024, 07:31:25 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #38 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.
« Last Edit: April 09, 2024, 09:21:47 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #39 on: April 09, 2024, 11:39:02 AM »
This is a memory allocation test is both 64 and 32 bit Windows.

Code: ScriptBasic
  1. a = STRING(MAXINT - 4, " ")
  2. PRINT LEN(a), "\n"
  3.  


C:\ScriptBasic64\bin>scriba.exe bigstr.sb   <-- ScriptBasic Windows 64 Bit
2147483643

C:\ScriptBasic64\bin>sbc bigstr.sb   <-- ScriptBasic Windows 32 Bit
(0): error &H1:Not enough memory

C:\ScriptBasic64\bin>sbc bigstr.sb   <-- ScriptBasic Windows 32 Bit
1000000000

C:\ScriptBasic64\bin>

jrs@linux-dev:~/sb/examples$ scriba memtest.sb   <-- Linux 64 Bit
4000000000
jrs@linux-dev:~/sb/examples$


Quote
The LongLong data type is a signed 64-bit integer that is only available on 64-bit versions of Office. Use LongLong for 64-bit integrals. Conversion functions must be used to explicitly assign LongLong (including LongPtr on 64-bit platforms) to smaller integral types.
« Last Edit: April 12, 2024, 08:26:57 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #40 on: April 10, 2024, 06:56:03 PM »
At this point the only major outstanding issue is libscriba on Windows 64 bit. It works fine on 64 Linux and 32 Windows. It returns the object handle but fails with any further calls.

Running libscriba as threads work using the SBT extension module. I'm beginning to wonder if this is a SBT issue not libscriba. Writing a C program to call libscriba seems like the next step.

If another set of eyes could have a look, it would be appreciated.
« Last Edit: April 10, 2024, 07:42:39 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #41 on: April 10, 2024, 10:24:12 PM »
It seems my only option with using libscriba within ScriptBasic on Windows 64 is running as threads. The embedding of SB in SB doesn't want to work on Windows 64 bit. I can communicate with the threads using the MT extension module. It's good to know libscriba is working in Windows 64 bit.


Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #42 on: April 10, 2024, 11:44:56 PM »
Here is a Windows 32 bit example of using the SBT start as a thread feature and using the libscriba API to access it. This is what I can't get working on Windows 64 bit.

sbt_start
Code: ScriptBasic
  1. IMPORT mt.sbi
  2. IMPORT sbt.sbi
  3.  
  4. sb = SBT::SB_ThreadStart("sbt_base.sb", "","C:/Windows/SCRIBA.INI")
  5.  
  6. ' Assign variables values
  7. SBT::SB_SetInt(sb, "main::a", 123)
  8. SBT::SB_SetDbl(sb, "main::b", 12.3)
  9. SBT::SB_SetStr(sb, "main::c", "One,Two,Three" & CHR(0))
  10. ' Call function with variables assigned in the previous step
  11. SBT::SB_CallSubArgs(sb, "main::prtvars", _
  12.           SBT::SB_GetVar(sb, "main::a"), _
  13.           SBT::SB_GetVar(sb, "main::b"), _
  14.           SBT::SB_GetVar(sb, "main::c"))
  15. ' Terminate Thread
  16. SBT::SB_CallSub(sb, "main::end_thread")
  17.  

sbt_base - (thread)
Code: ScriptBasic
  1. IMPORT mt.sbi
  2. IMPORT sbt.sbi
  3.  
  4. FUNCTION prtvars(a, b, c)
  5.   PRINT a,"\n"
  6.   PRINT FORMAT("%g\n", b)
  7.   PRINT c,"\n"
  8.   prtvars = "Function Return"
  9. END FUNCTION
  10.  
  11. a = 0
  12. b = 0
  13. c = ""
  14.  
  15. SUB End_Thread
  16.   PRINT "Good-Bye\n"
  17.   SBT::SB_ThreadEnd
  18. END SUB
  19.  

Output


C:\ScriptBasic\test>sbc sbt_start.sb
123
12.3
One,Two,Three
Good-Bye

C:\ScriptBasic\test>

   
« Last Edit: April 11, 2024, 12:32:55 AM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #43 on: April 11, 2024, 12:57:36 PM »
I noticed <io.h> was missing from the Windows 64 bit version of SBT but included in the 32 bit version. No luck getting it working. The Windows 32 bit and Linux 64 bit version were compiled using GCC not MSVC.

I tried using the TDM-GCC-64 version of SBT.DLL with the MSVC build but it still doesn't work. Interesting that the MSVC version of SBT is 119K and the GCC version is 577K. The Windows 64 version only allows me to use libscriba if I'm calling it from C and starting it as a thread. No libscriba API calls seem to work from SBT.  The GCC version runs mt thread test as does the MSVC version. Neither allows SBT to make API calls.

This is looking more like a Windows 64 environment issue than SBT being at fault.

Hopefully AIR will find a moment to have a look. I've tried everything I can think of.
« Last Edit: April 11, 2024, 03:37:52 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3597
    • ScriptBasic Open Source Project
Re: ScriptBasic 3.0
« Reply #44 on: April 11, 2024, 03:45:42 PM »
This works as it should using the MSVC SBT.

sbt_main.sb
Code: ScriptBasic
  1. ' SBT Main
  2.  
  3. IMPORT mt.bas
  4. IMPORT sbt.bas
  5.  
  6. SBT::SB_ThreadStart("sbt_thread.sb", "","C:/Windows/SCRIBA.INI")
  7.  
  8. FOR x = 1 TO 10
  9.   PRINT "M:",x,"\n"
  10.   SBT::sb_msSleep(100)
  11. NEXT
  12.  
  13. SBT::SB_msSleep(1000)
  14.  
  15. PRINT "Thread ",mt::GetVariable("thread_status"),"\n"
  16.  

sbt_thread.sb
Code: ScriptBasic
  1. ' SBT Thread
  2.  
  3. IMPORT mt.bas
  4. IMPORT sbt.bas
  5.  
  6. FOR x = 1 TO 10
  7.   PRINT "T:",x,"\n"
  8.   SBT::SB_msSleep(100)
  9. NEXT
  10.  
  11. mt::SetVariable "thread_status","Completed"
  12.  
  13. SBT::SB_ThreadEnd
  14.  

Output


C:\ScriptBasic64\examples>scriba sbt_main.sb
T:1
T:2
T:3
T:4
T:5
M:1
T:6
M:2
T:7
M:3
T:8
M:4
T:9
M:5
T:10
M:6
M:7
M:8
M:9
M:10
Thread Completed

C:\ScriptBasic64\examples>