Author Topic: OxygenBasic embeddable scripting interpreter  (Read 24050 times)

JRS

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #15 on: September 20, 2010, 08:35:14 PM »
Charles,

If we can get away from having to use a console window at all when the O2 application is declared GUI based than I couldn't be happier.

Peter Verhas alpha released a Windows version of the remote debugger which I got working on Linux and used Telnet for the client. It's still needs a few tweaks but it will be a good starting point for the O2 version of the SB GUI debugger.

JRS

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #16 on: September 23, 2010, 02:07:03 PM »
Charles,

While your working on O2 getting it ready for beta, I'm going to start building my multi-threaded SB application with sbhttpd. The only twist to this approach is that instead of running a script in a thread with a function call, I'll send a CGI header request to sbhttpd (running as a service on 127.0.0.1) which runs the script. I see some advantages to this approach as I can intermix desktop GUI and HTML in a browser container using SB alone. It gives me shared variable support (with locking) between threads and the main control program. I can also create session variables that remain static between iterations if needed. (MT extension module)

I use sbhttpd as a proxy server for websites I host for clients on a CentOS dedicated server at a data center. (this site is running on that server)

I'll post something on the All Basic interpreter board when I have an example to show.

John

cevpegge

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #17 on: September 24, 2010, 02:28:01 AM »

John,

If you are able to use a browser for interfacing your SB applications, what kind of advantages are you looking for in a native MS Windows GUI? I ask this question because the long term trend in computing (if you agree with Google)  is to use a browser exclusively as the front end for everything.

Charles

cevpegge

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #18 on: September 27, 2010, 04:54:15 PM »
John,

First stage demo of SB embedded in Oxygen now done. Its called SBembed1.o2bas and runs SBProg1.bas, both in the SBO2 folder. No need to compile it if you run through the IDE.

The output is very plain, but its one of the biggest steps - demonstrating program control, variable data going both ways and no console :)

I don't think Kaspersky will throw out the new compiler tools EXO2 and GXO2

My bed time.

Charles

JRS

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #19 on: September 27, 2010, 06:00:11 PM »
If you are able to use a browser for interfacing your SB applications, what kind of advantages are you looking for in a native MS Windows GUI? I ask this question because the long term trend in computing (if you agree with Google)  is to use a browser exclusively as the front end for everything.

The ScriptBasic httpd application server is nothing more than a C program embedding SB and running the scripts in a thread of the same process. The C host program takes care of installing itself as a service and listening for http/CGI requests that run SB scripts. Session support is done in memory and supports a global variable sharing scheme with locking among threads and the host C program.

I plan to use Gtk-Server for GUI on all platforms. I may use O2 and Gtk API to get the DLLs loaded and create the launcher. The main goal with the O2 front end is to build a multi-threaded  scriba interpreter.

JRS

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #20 on: September 27, 2010, 06:28:55 PM »
Quote
First stage demo of SB embedded in Oxygen now done. Its called SBembed1.o2bas and runs SBProg1.bas, both in the SBO2 folder. No need to compile it if you run through the IDE.

Thanks Charles!

Works great and a clean example how to embed ScriptBasic. This example shows running a SB script, calling a SB function and get/set a SB global variable from O2. The no-console feature is a nice touch. (8KB .exe generated)



This is the OxygenBasic program that embeds ScriptBasic.

Code: Text
  1. '#file "SBembed1.exe"
  2.  
  3.   include "scriba.inc"
  4.   indexbase 0
  5.  
  6.   dim as long pProgram,iError,cArgs
  7.   dim as long f1,f2,v
  8.   dim as long n,m
  9.   dim as SbData ReturnData,ArgData(3)
  10.   dim as sbdata byref pdat
  11.   dim as long qdat
  12.   '
  13.   cr=chr(13)+chr(10)
  14.   '
  15.   pr="Embedded ScriptBasic Tests" cr cr
  16.  
  17.   function newmem CDECL (ByVal le As Long) As BSTR Export
  18.     return nuls le
  19.   end function
  20.  
  21.   sub freemem CDECL (ByVal p As bstr) Export
  22.     frees p
  23.   end sub
  24.  
  25.   'SetConsoleTitle "FreeBasic ScriptBasic Embedding Test"
  26.  
  27.  
  28.  
  29.   '
  30.   'LOADING AND RUNNING A PROGRAM
  31.   '-----------------------------
  32.   '
  33.   pProgram=scriba_new (& newmem, & freemem)
  34.   'scriba_LoadConfiguration(pProgram,"c:\scriptbasic\bin\scriba.conf")
  35.   '
  36.   finit 'reinitialise FPU
  37.   '
  38.   scriba_SetFileName(pProgram,"SBProg1.bas")
  39.  
  40.   iError=scriba_LoadSourceProgram(pProgram)
  41.   if iError then goto ending
  42.  
  43.   iError=scriba_Run(pProgram,"Hello")
  44.   if iError then goto ending
  45.  
  46.   '
  47.   'ACCESSING GLOBAL DATA
  48.   '---------------------
  49.   '
  50.   v=scriba_LookupVariableByName(pProgram,"main::a")  
  51.   scriba_GetVariable(pProgram,v,& pdat)
  52.   '
  53.   pr+="read A: "str(pdat.lng) cr
  54.   '
  55.   m=pdat.lng+100
  56.   pr+="add 100 to A" cr
  57.   '
  58.   scriba_SetVariable(pProgram,v,2,m,0,"",0)
  59.   scriba_GetVariable(pProgram,v, & pdat)
  60.   '
  61.   pr+="read A: "str(pdat.lng) cr
  62.   '
  63.   'CALLING SIMPLE SUBROUTINE
  64.   '-------------------------
  65.   '
  66.   f1=scriba_LookupFunctionByName(pProgram,"main::dprint")
  67.   if f1=0 then print "Unable to locat Dprint" : goto ending
  68.  
  69.   iError=scriba_Call(pProgram,f1)
  70.   if iError then goto ending
  71.   '
  72.   '
  73.   '
  74.   'CALLING FUNCTION, RETURNING DATA AND GETTING ALTERED PARAMS
  75.   '-----------------------------------------------------------
  76.  
  77.   f2=scriba_LookupFunctionByName(pProgram,"main::eprint")
  78.   if f2=0 then print "Unable to locate Eprint" : goto ending
  79.  
  80.  
  81.   'SETUP ARGUMENTS
  82.   '---------------
  83.  
  84.   'these can be used for both input and output
  85.  
  86.   ArgData(0).typ=SBT_DOUBLE
  87.   ArgData(1).typ=SBT_DOUBLE
  88.   ArgData(2).typ=SBT_DOUBLE
  89.   ArgData(3).typ=SBT_DOUBLE
  90.  
  91.   ArgData(0).siz=0
  92.   ArgData(1).siz=0
  93.   ArgData(2).siz=0
  94.   ArgData(3).siz=0
  95.    
  96.   ArgData(0).dbl=11
  97.   ArgData(1).dbl=12
  98.   ArgData(2).dbl=13
  99.   ArgData(3).dbl=14
  100.  
  101.   cArgs=4
  102.  
  103.   '
  104.   pr+="call F2:" cr
  105.   '
  106.   iError=scriba_CallArgEx(pProgram, f2, ReturnData, cArgs, ArgData)
  107.   if iError then goto ending
  108.  
  109.   sys c=ReturnData.typ
  110.   '
  111.   'READ RETURNED VALUE
  112.   '-------------------
  113.   '
  114.   select case  c
  115.     case SBT_UNDEF  : pr+= "Undefined "
  116.     case SBT_DOUBLE : pr+="double "  ReturnData.dbl
  117.     case SBT_LONG   : pr+="long "    ReturnData.lng
  118.     case SBT_STRING : pr+="zstring " ReturnData.str
  119.     case SBT_ZCHAR  : pr+="zchar "   ReturnData.str
  120.   end select
  121.   '
  122.   pr+=cr
  123.   '
  124.   print pr
  125.  
  126.   '------
  127.   ending:
  128.   '======
  129.  
  130.   scriba_destroy(pProgram)
  131.  
  132.   if iError then print "ERROR:  " + hex(iError)  ' + "  " + hex(pProgram)
  133.  

This is the SB script being run by O2.

Code: ScriptBasic
  1. '
  2. ' SCRIPTBASIC
  3. '
  4.  
  5. ' ----------------
  6. ' GLOBAL VARIABLES
  7. ' ================
  8. '
  9. a=42
  10. b=sqr(2)
  11. s="hello world!"
  12. '
  13.  
  14. ' ---------
  15. ' FUNCTIONS
  16. ' =========
  17.  
  18.  
  19. function dprint
  20.   sp="  "
  21.   cr="\n"
  22.   tab=chr$(9)
  23. end function
  24.  
  25.  
  26. function eprint(a,b,c,d)
  27.   'eprint=a+b+c+d
  28.  'eprint=a+b+c+d+0.5
  29.  eprint="ans " & a+b+c+d
  30. end function
  31.  



Notice that A isn't preset to 42 this time? That's because I changed Charles's O2 program to call Scriba_NoRun() instead.

Quote from: Scriba_NoRun()
If the embedding program wants to set global variables and execute subroutines without or before starting the main program it has to call this function first. It does all the initializations that are done by scriba_Run() except that it does not actually execute the program. After calling this function the main program may access global variables and call ScriptBasic functions.

That is so cool to be able to RUN an O2 program in the IDE without having to compile it first.

small bug: The IDE creates a .exe executable with no prefix filename. (should be SBembed1.exe)

The attached zip includes the O2 program .exe, the libscriba.dll (SBAPI) and the SB script O2 runs and calls.
« Last Edit: September 27, 2010, 11:01:04 PM by JRS »

cevpegge

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #21 on: September 28, 2010, 12:33:28 AM »

Glad it works John.

I have corrected the .exe problem and ensured the co2.exe is not present in the zip as it is no longer needed. In future I will try to avoid dispatching new releases late at night :)

One problem which defeats me utterly: When I changed the email address in my FreeBasic Forum profile, it nobbled my account so I am unable to respond there. I can't even find out who to contact since email to admin@freebasic.net is rejected.


Charles

JRS

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #22 on: September 28, 2010, 12:45:22 AM »
Can you setup a new FreeBASIC account? Might be faster than trying to fix the old one. The FB board is an old custom phpBB forum. I'm surprised it hasn't been been trashed already by hackers preying on outdated forum software and CMS packages that are full of security holes. (php is a magnet for web hackers) I don't think anyone is steering the ship over there.

What is next on the list? (threading scripts?)

cevpegge

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #23 on: September 28, 2010, 12:57:22 AM »

Yes I'll do that. I spent a long time fumbling around but the site offers no clues as to who to contact when things go wrong.

Charles

cevpegge

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #24 on: September 28, 2010, 01:17:01 AM »
Its no good. When I try to do a new registration, I can't get past the image code test - its case sensitive and the letters are all ambiguous to me. It did have a contact address however.

rubentbstk@gmail.com <rubentbstk@gmail.com>

Charles

JRS

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #25 on: September 28, 2010, 01:27:47 AM »
I posted a request for one of the FreeBASIC admins to fix your account.

You are well liked and they should take care of it. Now if that happened to me, they would write it off as a blessing and I would be left in FreeBASIC limbo.  :D

cevpegge

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #26 on: September 28, 2010, 02:10:25 AM »
Thanks John!

We will see how long it takes to get a response.

And if it is so difficult to register for the forum, I am surprised they get any new members. I have tried several times to register but now I am denied access to the registration process. (please try later)

Charles

JRS

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #27 on: September 28, 2010, 05:13:56 PM »
Glad to see you're back online on the FreeBASIC forum. Mathew (counting pine) is one of the good guys and has always been fair with me.


JRS

  • Guest
Re: OxygenBasic embeddable scripting interpreter
« Reply #28 on: October 16, 2010, 07:38:19 PM »
Charles,

Quote
What is next on the list? (threading scripts?)

I know your busy with O2h internals but I was wondering if you could post an example of O2h calling SB in a threaded manor. I can probably figure out how to add the shared variable (MT) support.

I'm sure glad you were able to solve the riddles passing over the virus and FB bridges. It's cool that you are talented enough to drop down to byte/register level and fight back with a vengeance.

John