Programming > Problems & Solutions

O2 SB Embed

<< < (2/5) > >>

JRS:
It seems that the sbProgram TYPE wasn't needed so I removed it from my examples. The clue was pProgram was being declared as a sys.

I also removed include "minwin.inc" and finit as they weren't required either.

I'm wondering if I can use the scriba.h directly in O2? I'm going to give that a try.

JRS:
Charles,

I gave using scriba.h a try but it's complaining about syntax of one of the ScriptBasic .h files. Is this a show stopper using scriba.h with O2?

This seems to be a 'rabbit hole' that keeps getting deeper as I try to fill the holes. The bind seems like the way to go.


--- Code: OxygenBasic ---% filename "weather.exe"includepath "$/inc/"    include "RTL32.inc"includepath "C:\sbgcc\source\" extern lib "libscriba.dll" cdecl   include "scriba.h"end extern function newmem cdecl (sys le) as sys, export  return getmemory leend function function freemem cdecl (sys p) export  freememory pend function sys pProgram, fnsnsbData *argsbData *argr pProgram = scriba_new(@newmem, @freemem)scriba_LoadConfiguration(pProgram, "C:\Windows\SCRIBA.INI")scriba_SetFileName(pProgram, "weather.sb")scriba_LoadSourceProgram(pProgram)scriba_Run(pProgram, "") @arg = scriba_NewSbArgs(pProgram, "s", "Anacortes,US")fnsn = scriba_LookupFunctionByName(pProgram, "main::get_weather")  @argr = scriba_NewSbArgs(pProgram,"s", "")scriba_CallArgEx(pProgram, fnsn, argr, 1, arg)print argr.v.s scriba_DestroySbArgs(pProgram, arg, 1)scriba_DestroySbArgs(pProgram, argr, 1)scriba_destroy(pProgram) 
This seems to be the problem area in the lexer.h include file.


--- Code: C ---enum LexemeType {  LEX_T_DOUBLE = 1,  LEX_T_LONG,  LEX_T_STRING,  LEX_T_ASYMBOL,  LEX_T_NSYMBOL,  LEX_T_CHARACTER,   LEX_T_SKIP,                     LEX_T_SKIP_SYMBOL,   LEX_T_DUMMY  };  typedef struct _Lexeme {  enum LexemeType type;     union {    double dValue;            long   lValue;            char  *sValue;            } value;  long sLen;                char *szFileName;         long lLineNumber;         struct _Lexeme *next;     }Lexeme, *pLexeme; 
I tried the basext.h ScriptBasic include which is the include file for the ScriptBasic extension API.

JRS:
I'm moving on with trying to access ScriptBasic array structures from O2. Luckily Dave's SB IDE/Debugger shows SB arrary structures so I have some example code to reference.

FYI
It seems that trying to create a COM  instance via 2 cascading DLLs calls doesn't work. My insurance plan went up in smoke. Hope you have better luck than me with your COM/OLE automation library.

I turns out embedding ScriptBasic in O2 is a lightweight solution for off loading code requirements to ScriptBasic you don't want to recreate the wheel in O2. You could use it as a prototyping tool as well.

JRS:
There doesn't seem to be any API based functions to pass ScriptBasic arrays back to the the caller. This is my workaround.  ArrayToXML This shouldn't be too hard to parse on the O2 side as the bounds, variable types and element contents are returned.


--- Code: OxygenBasic ---' O2 SB Syntax Embed % filename "a2s.exe"includepath "$/inc/"include "RTL32.inc"% libScriba="libScriba.dll"indexbase 0 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 libScribaextern 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 leend function function freemem cdecl (sys p) export  freememory pend function sys pProgram. fnsnsbData *argsbData *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, argr, 1)scriba_destroy(pProgram) 
test.sb

--- Code: Script BASIC ---declare command ArrayToXML alias "xmlserialize" lib "t" FUNCTION a2s  b[10] = "Ten"  b[11] = 11   a[0] = "ZERO"  a[1] = 1  a[2] = .2  a[3] = b   a2s = ArrayToXML(a)END FUNCTION    
Array2XML also handles associative arrays.


--- 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   

JRS:
Code Challenge:

Anyone interested in creating a routine in O2 to parse the XML array definition I return from SB to an O2 array?

I would love to have a SPLITA and LIKE feature in O2.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version