Author Topic: O2 Interpreter  (Read 1770 times)

0 Members and 1 Guest are viewing this topic.

JRS

  • Guest
O2 Interpreter
« on: April 01, 2013, 10:27:05 AM »
Charles,

Can you show me an updated version of how I can embed ScriptBasic using OxygenBasic? (scriba shell replacement) Here is the code you submitted for the SB embedding code challenge done back in Sept. of 2009.

Code: [Select]

'--------------------------------
'EMBEDDING SCRIPT BASIC IN OXYGEN
'================================

  #basic
  #file "o2embeds.exe"
   

  Dim pProgram,iError
 
  Function newmem CDECL (ByVal le As Long) As Long Export
  'print `newmem`
  Function=news le
  End Function

  Function freemem CDECL (ByVal p As Long) Export
    'print `freemem`
    frees p
  End Function


  '-----------
  'WINDOWS API
  '===========


  declare function AllocConsole lib "kernel32.dll" alias "AllocConsole" () as long
  declare function SetConsoleTitle lib "kernel32.dll" alias "SetConsoleTitleA" (lpConsoleTitle as asciiz) as long
  declare function GetStdHandle lib "kernel32.dll" alias "GetStdHandle" (byval nStdHandle AS dword) as long
  declare function WriteConsole lib "kernel32.dll" alias "WriteConsoleA" (byval hConsoleOutput as dword, lpBuffer as asciiz, BYVAL nNumberOfCharsToWrite AS LONG, lpNumberOfCharsWritten AS LONG, byval lpReserved as long) as long

  %STD_INPUT_HANDLE  = -10
  %STD_OUTPUT_HANDLE = -11
  %STD_ERROR_HANDLE  = -12


  AllocConsole

  '-----------------
  'CONSOLE INTERFACE
  '=================
  '
  'DIM consIn AS LONG,consOut AS LONG,consErr AS LONG
  'ConsIn =GetStdHandle (%STD_INPUT_HANDLE)
  'ConsOut=GetStdHandle (%STD_OUTPUT_HANDLE)
  'ConsErr=GetStdHandle (%STD_ERROR_HANDLE)
  '
  'DIM bufout AS ASCIIZ(8000)
  'DIM buflen AS LONG
  'DIM bufrit AS LONG

  ' BOOL WINAPI WriteConsole(
  '   __in        HANDLE hConsoleOutput,
  '   __in        const VOID *lpBuffer,
  '   __in        DWORD nNumberOfCharsToWrite,
  '   __out       LPDWORD lpNumberOfCharsWritten,
  '   __reserved  LPVOID lpReserved
  ' );


  ' BOOL WINAPI SetConsoleTitle(
  '   __in  LPCTSTR lpConsoleTitle
  '
  ' );


  SetConsoleTitle "Oxygen ScriptBasic Embedding Test"

  'TEST CONSOLE OUTPUT
  '
  'bufout="Hello"
  ' buflen=LEN(bufout) 'buggy with static strings
  'buflen=5
  'WriteConsole ConsOut,bufout,buflen,bufrit,0


  '------------------------------------
  'EARLY BINDING (no access to console)
  '------------------------------------
  '
  '%o2Basic=1
  '#include "scriba.inc"

  '------------------------
  'LATE BINDING (LOW LEVEL)
  '------------------------

  dim sbl

  sbl=loadlibrary "libscriba.dll"
  bind sbl
  (
    scriba_new               scriba_new
    scriba_LoadConfiguration scriba_LoadConfiguration
    scriba_SetFileName       scriba_SetFileName
    scriba_LoadSourceProgram scriba_LoadSourceProgram
    scriba_Run               scriba_Run
    scriba_destroy           scriba_destroy
  )

  pProgram=scriba_new &newmem, &freemem
  scriba_LoadConfiguration(pProgram,"c:\scriptbasic\bin\scriba.conf")
  scriba_SetFileName(pProgram,"E02.bas")
  scriba_LoadSourceProgram(pProgram)
  iError=scriba_Run(pProgram,"Hello")
  scriba_destroy(pProgram)

  freelibrary sbl

  'PRINT "ok:  " hex(iError) "  " hex(pProgram)

Charles Pegge

  • Guest
Re: O2 Interpreter
« Reply #1 on: April 01, 2013, 01:24:39 PM »
Hi John,

projectsB/ScriptBasic/SBembed1.o2bas

My latest work with DLLC + sbo2util.inc is based on this piece. Not much has changed.

JRS

  • Guest
Re: O2 Interpreter
« Reply #2 on: April 01, 2013, 08:49:09 PM »
How do I get what is being passed on the command line from O2?

Is there anything special I need to do to give SB console (STDIN/OUT) support?


Charles Pegge

  • Guest
Re: O2 Interpreter
« Reply #3 on: April 02, 2013, 04:47:38 AM »
Hi John,

Oxygen does not normally use a console, but I hope my example Customisable DOS Console will help. You can use GetCommandline to read the commandline - you will need to do some parsing to extract what you need from it.

JRS

  • Guest
Re: O2 Interpreter
« Reply #4 on: April 02, 2013, 06:36:24 AM »
Sounds like too much work. I'll stick with scriba as the Windows shell for SB and modify that. Thanks for the console info with O2.