11
Problems & Solutions / Re: O2 SB Embed
« Last post by JRS on March 31, 2021, 11:53:05 PM »This is an example of getting and setting ScriptBasic variables from O2.
testvars.sb
C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>getsetvars
1
0.2
Three
101
2.2000000000000002
Thirty Three
C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>
testvars.sb
Code: Script BASIC
- a = 1
- b = .2
- c = "Three"
Code: Text
- % filename "getsetvars.exe"
- includepath "$/inc/"
- include "RTL32.inc"
- include "sbembed.inc"
- #console
- uses console
- sys pProgram
- sbData *arg
- string cr = chr(13,10)
- string src = `IMPORT "testvars.sb"` + cr
- pProgram = scriba_new(@newmem, @freemem)
- scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI")
- scriba_SetFileName(pProgram, "none")
- scriba_LoadProgramString(pProgram, src, len(src))
- scriba_Run(pProgram, "")
- sys v_a = scriba_LookupVariableByName(pProgram, "main::a")
- sys v_b = scriba_LookupVariableByName(pProgram, "main::b")
- sys v_c = scriba_LookupVariableByName(pProgram, "main::c")
- ' Get defined variable values
- scriba_GetVariable(pProgram, v_a, @@arg)
- print arg.lng + cr
- scriba_GetVariable(pProgram, v_b, @@arg)
- print arg.dbl + cr
- scriba_GetVariable(pProgram, v_c, @@arg)
- print arg.str + cr + cr
- ' Set variable values
- scriba_SetVariable(pProgram, v_a, SBT_LONG, 101, 0.0, "", 0)
- scriba_SetVariable(pProgram, v_b, SBT_DOUBLE, 0, 2.2, "", 0)
- scriba_SetVariable(pProgram, v_c, SBT_STRING, 0, 0.0, "Thirty Three", 12)
- ' Get changed variable values
- scriba_GetVariable(pProgram, v_a, @@arg)
- print arg.lng + cr
- scriba_GetVariable(pProgram, v_b, @@arg)
- print arg.dbl + cr
- scriba_GetVariable(pProgram, v_c, @@arg)
- print arg.str + cr
- scriba_DestroySbArgs(pProgram, arg, 1)
- scriba_destroy(pProgram)
C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>getsetvars
1
0.2
Three
101
2.2000000000000002
Thirty Three
C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>