Author Topic: Calling the Oxygen DLL  (Read 33468 times)

AIR

  • Guest
Re: Calling the Oxygen DLL
« Reply #30 on: September 12, 2010, 12:43:57 AM »
Glad that worked.

I have a question:  you're trying to return strings from the DLL calls, but are they _supposed_ to be returning strings?

JRS

  • Guest
Re: Calling the Oxygen DLL
« Reply #31 on: September 12, 2010, 01:00:06 AM »
Quote
I have a question:  you're trying to return strings from the DLL calls, but are they _supposed_ to be returning strings?

There are two o2 error functions.

o2_error() which I assume returns a error message string

o2_errno() that should return a error number

I only get a numeric representation of an address (both functions) if the script has syntax errors.

P.S.

See my last message about where I think the July 18th build came from.

AIR

  • Guest
Re: Calling the Oxygen DLL
« Reply #32 on: September 12, 2010, 01:04:48 AM »
Quote
I have a question:  you're trying to return strings from the DLL calls, but are they _supposed_ to be returning strings?

There are two o2 error functions.

o2_error() which I assume returns a error message string

o2_errno() that should return a error number

I only get a numeric representation of an address (both functions) if the script has syntax errors.


I think o2_error returns a number, based on this:
Code: [Select]
e=dyc::dyc("ms,i,OXYGEN.DLL,o2_error,C")
'e=0
if e=0 then

JRS

  • Guest
Re: Calling the Oxygen DLL
« Reply #33 on: September 12, 2010, 01:08:58 AM »
Quote from: SB DYC Docs
Xr RETURN VALUE

The return value should be specified using a single character. This can be:

i or I int, l or L long, p or P pointer, f or F float, d or D for double or v or V for __int64.

The int and long types are converted to a BASIC integer number, which is stored as a long in ScriptBasic. float and double values are returned as real number, which is stored as double in ScriptBasic. A pointer value is converted to long and is returned in an integer value. An __int64 value is returned as an 8 byte string copiing the bytes of the original __int64 value to the bytes of the BASIC string.

Looks like a number is all that is returned.

JRS

  • Guest
Re: Calling the Oxygen DLL
« Reply #34 on: September 12, 2010, 01:23:07 AM »
Code: [Select]
'---------------------------------
'USING OXYGEN WITH SCRIPTBASIC DYC
'---------------------------------

DECLARE SUB DLL ALIAS "dyc" LIB "dyc"

src = """
  print "Greetings from OxygenBasic!"
""" & CHR(0)

DLL "ms,i,OXYGEN.DLL,o2_mode,L", 0
DLL "ms,i,OXYGEN.DLL,o2_basic,Z", src

e = DLL("ms,i,OXYGEN.DLL,o2_error,C")

IF e = 0 THEN
  DLL "ms,i,OXYGEN.DLL,o2_exec,L", 0
END IF

This format works for me.

DYC Documentation
« Last Edit: September 13, 2010, 12:30:58 AM by JRS »

cevpegge

  • Guest
Re: Calling the Oxygen DLL
« Reply #35 on: September 12, 2010, 02:52:20 AM »

o2_errno returns an integer of value 0 if the compilation was successful

o2_error returns a pointer to a Zstring describing the error. If there is no error then the string is empty.

Neither of these expect any arguments and will not clear them from the stack. When there is a Linux version (with CDecl calling), this will not be a problem since the caller performs the stack cleanup.

Anyway the SBO2 solution will allow us 2 way traffic using string pointer arguments.

Charles

verhas

  • Guest
Re: Calling the Oxygen DLL
« Reply #36 on: September 12, 2010, 03:01:51 AM »
From my point of view the macros are there to easy the creation of an extension module in C. I never intended to extend ScriptBasic in any other language than C, but it is possible if you can provide C calling interface.

If there is an extension module that uses a certain version of the interface that ScriptBasic provides towards extension modules then it should work with the next version of the interface. If it does not it means that somebody was creating the interface against the design principles. All modules should negotiate the module interface version as described in:

http://www.scriptbasic.com/html/texi/devguide/devguide_4.2.html

The only file you have to look at is basext.c All the macros are defined here.

cevpegge

  • Guest
Re: Calling the Oxygen DLL
« Reply #37 on: September 12, 2010, 06:38:47 AM »

Hi Peter,

Thank you for the info.

If the fundamental interface does not change over time very much then it would be easier for other languages to port from  the C function headers directly.

Oxygen has a basic understanding of C headers but does not cover C in its entirety. (yet! :) )

Charles

JRS

  • Guest
Re: Calling the Oxygen DLL
« Reply #38 on: September 12, 2010, 02:42:09 PM »
Quote
Anyway the SBO2 solution will allow us 2 way traffic using string pointer arguments.

Is your direction at this point to create an extension module (SBO2.DLL) and will act as interface for variable sharing?

I assume if your going to use the extension module API rather then the embedding API then multi-threading O2 may be a future option. (SBO2.EXE)

Let me know if there is anything I can do to help with this project.


cevpegge

  • Guest
Re: Calling the Oxygen DLL
« Reply #39 on: September 12, 2010, 03:37:43 PM »
John,

I thought of testing the concept first with the the DYC / SBO2 linkage and then think about making SBO2 an extension module.

Multithreading will be important for running Windows to avoid having to break out of the Windows message loop to service ScriptBasic.

Charles

JRS

  • Guest
Re: Calling the Oxygen DLL
« Reply #40 on: September 12, 2010, 04:39:16 PM »
Sounds like a great plan.

I'm really excited about this project and hope other Basic languages take note of the advantages of having an embeddable JIT compiler at their disposal.

cevpegge

  • Guest
Re: Calling the Oxygen DLL
« Reply #41 on: September 15, 2010, 11:45:56 PM »

John,

I'm making progress. I've included a folder for ScriptBasic in the examples. SBO2. We can now compile and run O2 scripts through ScriptBasic using DYC and SBO2.

For SBdemo3, The relative paths of the folders should be maintained so that the graphics library can be located. Oxygen also required a minor addition to aid relative path mapping.


SBO2demo3.sb
Code: [Select]
'---------------------------------
'USING SBO2 WITH SCRIPTBASIC DYC
'---------------------------------

'ScriptBasic

module cio
  declare sub ::detach        alias "sbdetach"   lib "cio"
end module

cio::Detach()

module dyc
  declare sub     ::dyc alias "dyc" lib "dyc"
end module



'OXYGEN SOURCE CODE
'------------------

send="""

  basic
  #include PortViewer2.o2bas

""" & chr$(0)

bufferlength=1000
receive=space(bufferlength)

replylength=dyc::dyc("ms,i,sbo2.dll,run,ZZL",send,receive,bufferlength)

'print replylength
'print left(receive,replylength)
'line input w

SBO2.DLL
Code: [Select]
basic

  #file "sbo2.dll"

  library "oxygen.dll"

  declare sub      o2_asmo  (byval s as string)
  declare sub      o2_basic (byval s as string)
  declare function o2_buf   (byval n as long) as long
  declare function o2_errno () as long
  declare function o2_error () as string
  declare function o2_exec  (optional byval p as long) as long
  declare function o2_get   () as string
  declare function o2_len   () as long
  declare function o2_prep  (byval srcBSTR as string) as string
  declare sub      o2_put   (byval c as string)
  declare function o2_view  (byval srcBSTR as string) as string

  library ""



  '----------------------------------------------------------------------
  function message(sys send, sys receive, sys bufferlength) as sys export
  '======================================================================
  '
  zstring * z : &z=send
  print z
  '
  s="Greetings from sbo2 oxygen!"
  replylength=len s
  if replylength>bufferlength then replylength=bufferlength
  copy receive, *s, replylength
  return replylength
  end function



  '------------------------------------------------------------------
  function run(sys send, sys receive, sys bufferlength) as sys export
  '==================================================================
  '
  zstring * z : &z=send
  string c=z
  string s=""
  o2_asmo c
  if o2_errno then
    s=o2_error
  else
    o2_exec
    s="Okay"
  end if
  '
  replylength=len s
  if replylength>bufferlength then replylength=bufferlength
  copy receive, *s, replylength
  return replylength
  end function

Charles

Alpha006
https://sourceforge.net/projects/oxygenbasic/files/


JRS

  • Guest
Re: Calling the Oxygen DLL
« Reply #42 on: September 16, 2010, 12:05:22 AM »
I didn't think I was going to hear from you for awhile. (working on compiler)

I tried to download the Alpha06 (twice) and it said the zip file is bad.

Looking forward to playing with this.


cevpegge

  • Guest
Re: Calling the Oxygen DLL
« Reply #43 on: September 16, 2010, 12:27:09 AM »

I checked the download and the zip works correctly. Is this Mr Kapersky interfering again?

On Vista, there are the usual security questions about running new software, and the manual has to be unblocked - (going into properties). But otherwise no problems here.

Charles

JRS

  • Guest
Re: Calling the Oxygen DLL
« Reply #44 on: September 16, 2010, 12:52:39 AM »
Quote
I checked the download and the zip works correctly. Is this Mr Kapersky interfering again?

I'm able to unzip all your previous zips, just Alpha06 pops a dialog in PowerArchiever saying the zip has an error then exits.

It's Alpha05 Mr. Kaspersky doesn't like (false positive e-mail virus/worm) and makes me deleted your files.