Open Sage

BOI => BOI Overview => Topic started by: root on May 19, 2026, 07:11 PM

Title: SBT Embedding
Post by: root on May 19, 2026, 07:11 PM
ScriptBasic can be embedded into other applications as a DLL interface. I wrote the SBT extension module which embeds ScriptBasic in ScriptBasic to help others with the ScriptBasic API. I also added the ability to embed ScriptBasic as a thread.

The following example demonstrates accessing the ScriptBasic API

' 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_32"
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

This is an example of embedding ScriptBasic as a thread process and using the MT extension module to share a common status variable among processes.

Code (main) Select

' SBT Main

IMPORT mt.sbi
IMPORT sbt.sbi

SB_ThreadStart("sbt_thread.sb", "","C:/Windows/SCRIBA.INI")

FOR x = 1 TO 10
  PRINT "M:",x,"\n"
  sb_msSleep(20)
NEXT

SB_msSleep(1000)

PRINT "Thread ",mt::GetVariable("thread_status"),"\n"

Code (thread) Select
' SBT Thread

IMPORT mt.sbi
IMPORT sbt.sbi

FOR x = 1 TO 10
  PRINT "T:",x,"\n"
  SB_msSleep(20)
NEXT

mt::SetVariable "thread_status","Completed"

SB_ThreadEnd