21
Problems & Solutions / Re: O2 SB Embed
« Last post by JRS on March 28, 2021, 07:11:01 PM »I started building the sbembed.inc file and got console support working.
test.sb
sbembed.inc
C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>a2s
C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>
a2s.exe Size: 14,848 bytes
Total Seconds: 0.066272
I will be enhancing this include to make the interface to ScriptBasic more seamless.
Code: OxygenBasic
- ' O2 SB Array Passing
- % filename "a2s.exe"
- includepath "$/inc/"
- include "RTL32.inc"
- include "sbembed.inc"
- #console
- uses console
- sys pProgram. fnsn
- sbData *arg
- sbData *argr
- pProgram = scriba_new(@newmem, @freemem)
- scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI")
- scriba_SetFileName(pProgram, "test.sb")
- scriba_LoadSourceProgram(pProgram)
- scriba_Run(pProgram, "")
- @arg = scriba_NewSbArgs(pProgram, "u")
- fnsn = scriba_LookupFunctionByName(pProgram, "main::a2s")
- @argr = scriba_NewSbArgs(pProgram,"s", "")
- scriba_CallArgEx(pProgram, fnsn, argr, 0, arg)
- print argr.str
- scriba_DestroySbArgs(pProgram, arg, 1)
- scriba_DestroySbArgs(pProgram, argr, 1)
- scriba_destroy(pProgram)
test.sb
Code: Script BASIC
- DECLARE COMMAND ArrayToXML ALIAS "xmlserialize" LIB "t"
- FUNCTION a2s
- a{"One"} = 1
- a{"Two"} = .2
- a{"3"} = "Three"
- a2s = ArrayToXML(a)
- END FUNCTION
sbembed.inc
Code: OxygenBasic
- ' ScriptBasic Embedding Include
- % libScriba = "libScriba.dll"
- type SbData
- typ as dword
- siz as dword
- union {
- dbl as double
- lng as sys
- str as char*
- gen as sys
- }
- end type
- sys sb = LoadLibrary libScriba
- extern cdecl
- bind sb
- {
- scriba_new
- scriba_LoadConfiguration
- scriba_SetFileName
- scriba_LoadSourceProgram
- scriba_Run
- scriba_LookupFunctionByName
- scriba_NewSbArgs
- scriba_CallArgEx
- scriba_DestroySbArgs
- scriba_destroy
- }
- end extern
- function newmem cdecl (sys le) as sys, export
- return getmemory le
- end function
- function freemem cdecl (sys p) export
- freememory p
- end function
C:\OxygenBasic\projectsC\ScriptBasic\EmbedSb>a2s
Code: XML
- <?xml version="1.0" encoding="UTF-8"?><V><A l="0" h="5"><S>One</S><I>1</I><S>Two</S><R>0.200000</R><S>3</S><S>Three</S></A></V>
a2s.exe Size: 14,848 bytes
Total Seconds: 0.066272
I will be enhancing this include to make the interface to ScriptBasic more seamless.