The
SBT extension allows you to develop your SB embedded scripts using ScriptBasic as the host language. An added feature of SBT is you can run your scripts as threads. The MT extension module allows you to share variables between theads and the parent process.
SBT ModuleMODULE SBT
DECLARE SUB ::SB_New ALIAS "SB_New" LIB "sbt"
DECLARE SUB ::SB_Configure ALIAS "SB_Configure" LIB "sbt"
DECLARE SUB ::SB_Load ALIAS "SB_Load" LIB "sbt"
DECLARE SUB ::SB_LoadStr ALIAS "SB_LoadStr" LIB "sbt"
DECLARE SUB ::SB_Run ALIAS "SB_Run" LIB "sbt"
DECLARE SUB ::SB_NoRun ALIAS "SB_NoRun" LIB "sbt"
DECLARE SUB ::SB_ThreadStart ALIAS "SB_ThreadStart" LIB "sbt"
DECLARE SUB ::SB_ThreadEnd ALIAS "SB_ThreadEnd" LIB "sbt"
DECLARE SUB ::SB_GetVar ALIAS "SB_GetVar" LIB "sbt"
DECLARE SUB ::SB_SetUndef ALIAS "SB_SetUndef" LIB "sbt"
DECLARE SUB ::SB_SetInt ALIAS "SB_SetInt" LIB "sbt"
DECLARE SUB ::SB_SetDbl ALIAS "SB_SetDbl" LIB "sbt"
DECLARE SUB ::SB_SetStr ALIAS "SB_SetStr" LIB "sbt"
DECLARE SUB ::SB_ResetVars ALIAS "SB_ResetVars" LIB "sbt"
DECLARE SUB ::SB_msSleep ALIAS "SB_msSleep" LIB "sbt"
DECLARE SUB ::SB_CallSub ALIAS "SB_CallSub" LIB "sbt"
DECLARE SUB ::SB_CallSubArgs ALIAS "SB_CallSubArgs" LIB "sbt"
DECLARE SUB ::SB_Destroy ALIAS "SB_Destroy" LIB "sbt"
END MODULE
An example of using
SBT.
' SBT Demo
IMPORT sbt.sbi
sb_code = """
FUNCTION prtvars(a, b, c)
PRINT a,"\\n"
PRINT FORMAT("%g\\n", b)
PRINT c,"\\n"
prtvars = "Function Return"
END FUNCTION
a = 0
b = 0
c = ""
"""
sb = SB_New()
SB_Configure sb, "C:/Windows/SCRIBA.INI"
SB_Loadstr sb, sb_code
SB_NoRun sb
' Call function before running script
funcrtn = SB_CallSubArgs(sb,"main::prtvars", 123, 1.23, "One, Two, Three")
PRINT funcrtn,"\n"
' Run script initializing globals
SB_Run sb, ""
' Assign variables values
SB_SetInt sb, "main::a", 321
SB_SetDbl sb, "main::b", 32.1
SB_SetStr sb, "main::c", "Three,Two,One" & CHR(0)
' Call function again with variables assigned in the previous step
SB_CallSubArgs sb, "main::prtvars", _
SB_GetVar(sb, "main::a"), _
SB_GetVar(sb, "main::b"), _
SB_GetVar(sb, "main::c")
SB_Destroy sb
Output
123
1.23
One, Two, Three
Function Return
321
32.1
Three,Two,One
This is an example of running a script as a thread and using MT as status flag variable.
sbt_main.sb' SBT Main
IMPORT mt.bas
IMPORT sbt.bas
SBT::SB_ThreadStart("sbt_thread.sb", "","C:/Windows/SCRIBA.INI")
FOR x = 1 TO 10
PRINT "M:",x,"\n"
SBT::sb_msSleep(100)
NEXT
SBT::SB_msSleep(1000)
PRINT "Thread ",mt::GetVariable("thread_status"),"\n"
sbt_thread.sb' SBT Thread
IMPORT mt.bas
IMPORT sbt.bas
FOR x = 1 TO 10
PRINT "T:",x,"\n"
SBT::SB_msSleep(100)
NEXT
mt::SetVariable "thread_status","Completed"
SBT::SB_ThreadEnd
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>