Another BCX embedded example to help you take your next step. Notice this example shows the results if you just load your script and access functions and variables and what the results are if you run the script.
BCX_embed4.bas
#include "\scriptbasic\source\scriba.h"
#include "\scriptbasic\source\getopt.h"
$LIBRARY "libscriba.lib"
' NOTE: Windows specific above this line and generic BCX below.
Dim pProgram As pSbProgram
Dim v As long
Dim f1 As long
Dim f2 As long
Dim dVal=11 as long
Dim cArgs As long
Dim ReturnData As SbData
dim ArgData[4] As SbData
' LOADING AND RUNNING THE PROGRAM
pProgram = scriba_new(malloc, free)
scriba_SetFileName(pProgram, "E03.bas")
scriba_LoadSourceProgram(pProgram)
scriba_NoRun(pProgram)
'' ACCESSING GLOBAL DATA
v = scriba_LookupVariableByName(pProgram, "main::a")
scriba_SetVariable(pProgram, v, 2, 500, 0, "", 0)
'' CALLING SIMPLE SUBROUTINE
f1 = scriba_LookupFunctionByName(pProgram, "main::dprint")
scriba_Call(pProgram, f1)
' CALLING FUNCTION, RETURNING DATA AND GETTING ALTERED PARAMS
f2 = scriba_LookupFunctionByName(pProgram, "main::eprint")
' SETUP ARGUMENTS
for cArgs=0 to 3
ArgData[cArgs].type = SBT_DOUBLE
ArgData[cArgs].size = 0
ArgData[cArgs].v.d = dVal+cArgs
next
scriba_CallArgEx(pProgram, f2, &ReturnData, cArgs, ArgData)
print "Return type:",ReturnData.type
print "Value:";
' READ RETURNED VALUE
select case ReturnData.type
case SBT_UNDEF : print "Undefined"
case SBT_DOUBLE : print ReturnData.v.d
case SBT_LONG : print ReturnData.v.l
case =SBT_STRING or =SBT_ZCHAR : print (CHAR PTR)ReturnData.v.s
end select
scriba_destroy(pProgram)
ScriptBasic - E03.bas
' ----------------
' GLOBAL VARIABLES
' ================
'
a=42
b=sqr(2)
s="hello world!"
q=dprint()
q=eprint(1,2,3,4)
'print "Enter: "
'line input q
' ---------
' FUNCTIONS
' =========
function dprint
sp=" "
cr="\n"
tab=chr$(9)
print "Dprint Globals: " & s & sp & a & sp & b & cr
' line input q
dprint=1
end function
function eprint(a,b,c,d)
sp=" "
cr="\n"
tab=chr$(9)
print "Eprint Args: " & a & sp & b & sp & c & sp & d & cr
' line input q
ans=a+b+c+d
eprint="Sum = " & ans
end function
Results:(scriba_NoRun)
C:\Program Files\BCX\sb>BCX_embed4
Dprint Globals: 500
Eprint Args: 11.000000 12.000000 13.000000 14.000000
Return type: 3
Value:Sum = 50
C:\Program Files\BCX\sb>
Results: (Scriba_Run)
C:\Program Files\BCX\sb>BCX_embed4
Dprint Globals: hello world! 42 1.414214
Eprint Args: 1 2 3 4
Dprint Globals: hello world! 500 1.414214
Eprint Args: 11.000000 12.000000 13.000000 14.000000
Return type: 3
Value:Sum = 50
C:\Program Files\BCX\sb>