Oxygen Basic
Programming => Example Code => Topic started by: JRS 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.
'--------------------------------
'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)
-
Hi John,
projectsB/ScriptBasic/SBembed1.o2bas
My latest work with DLLC + sbo2util.inc is based on this piece. Not much has changed.
-
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?
-
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.
-
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.