Results 1 to 10 of 10

Thread: Oxygen can call thinBasic functions

  1. #1

    Oxygen can call thinBasic functions



    thinBasic calls Oxygen function -<-----> Oxygen calls thinBasic function

    With the latest Oxygen, it is now possible to read the PB version of thincore.inc ( included in the example zip below).

    Using two of the more recent thincore functions enables Oxygen to obtain a function token from thinBasic then use it to invoke the thinBasic function.


    Latest Oxygen: http://community.thinbasic.com/index.php?topic=2517

    [code=thinbasic]

    uses "oxygen"

    '-------------------------------
    'thinBasic calls Oxygen function
    'Oxygen calls thinBasic function
    '===============================

    dim v as long
    dim p1,p2,p3,p4 as long
    dim src as string

    src = "
    '
    #o2h
    '
    '
    include `thincore.inc`
    '
    '---------------------------------------
    function callback_token() as long at #p2
    '=======================================
    function=thinBasic_FunctionParseAndGetPtr 0
    end function

    '--------------------------------------------------
    function callback_to(byval a as long) as long at #p3
    '==================================================
    dim as double d
    dim as string s
    dim as double p(10)
    p(1)=42
    thinBasic_FunctionCall_ByPtr a, 1,&p, d,s
    print `thinBasic returns: ` str d
    function=1
    end function

    '------------------
    sub finish() at #p1
    '==================
    terminate
    end sub
    '
    "




    '===============================================================


    'msgbox 0, o2_prep src
    o2_basic src
    if len(o2_error) then
    msgbox 0, o2_error : stop
    end if
    o2_exec

    declare sub finish() at p1
    declare function callback_token() as long at p2
    declare function callback_to(byval a as long) as long at p3

    '===============================================================


    '----------------------------------------------
    function targetfun(byval a as double) as double
    '==============================================
    msgbox 0, "ThinBasic receives: "+str$(a)
    function=a*2
    end function

    '----
    'TEST
    '====

    v=callback_token targetfun
    'v=callback_token "targetfun"
    callback_to v

    finish
    [/code]
    Attached Files Attached Files

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    Re: Oxygen can call thinBasic functions

    You are working like a Caterpillar Charles.
    Thank you very much.


    _________________________________________________
    Latest Oxygen will be natively present in next thinBasic beta 1.7.8.0
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3

    Re: Oxygen can call thinBasic functions


    Thanks Eros,

    A fundamental update to Oxygen will be dispatched in the next 2 hours or so. This will enable o2 to be accessed as a standard dll - an important step towards being able to create TB modules in O2 basic.

    Charles
    \/
    (O)
    (O)(O)(O)(O)(O)
    ^ ^ ^ ^ ^

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736

    Re: Oxygen can call thinBasic functions

    Thanks for your work Charles

    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    Re: Oxygen can call thinBasic functions

    Quote Originally Posted by Charles Pegge

    Thanks Eros,

    A fundamental update to Oxygen will be dispatched in the next 2 hours or so. This will enable o2 to be accessed as a standard dll - an important step towards being able to create TB modules in O2 basic.

    Charles
    \/
    (O)
    (O)(O)(O)(O)(O)
    ^ ^ ^ ^ ^
    I was actually thinking that it was possible allready but that would be an awesome addition and I would see if I can use it to develop a module with it.

  6. #6

    Re: Oxygen can call thinBasic functions


    Hi Michael,

    yes I had a primitive version - assembler only with a very limited set of run time functions. This will tap into the Oxygen module for its runtime but there are a few more steps to take on the DLL generation side.

    Charles

  7. #7
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    55
    Posts
    1,554
    Rep Power
    174
    OK, what I don't understand- I post the changed script as I have it on my pc. - It's a "modern" version of the first - so uses Link instead of At.
    You'll need to have thinCore.inc saved next to the script to run it.
    uses "oxygen"
    
    '-------------------------------
    'thinBasic calls Oxygen function
    'Oxygen calls thinBasic function
    '===============================
    
    'REQUIRES THINCORE.INC from thinBasic SDK.
    
    
    Dim p1,p2,p3 As Long
    String src = RawText
      '
      #basic
      '
      '
      include "thincore.inc"
      '
      '------------------------------------------
      function callback_token() as long  link #p2
      '==========================================
        function=thinBasic_FunctionParseAndGetPtr 0
      end function
    
      '------------------------------------------------------
      function callback_to(byval a as long) as long  link #p3
      '======================================================
        dim as double d
        dim as string s
        dim as double p(10)
        p(1)=42
        s="!!"
    ###
        thinBasic_FunctionCall_ByPtr  a,  1, &p, d, s
    ###
        print `thinBasic returns to Oxygen: `  s
        'print `thinBasic returns to Oxygen: `  str d
        function=1
      end function
    
      '------------------
      Sub finish() link #p1
      '==================
        terminate
      end sub
      '
    
    End RawText
      
      
      '===============================================================
    
    
      o2_basic src
      if len(o2_error) then
        msgbox 0, o2_error : stop
      end if
      o2_exec
      
      declare sub finish() at p1
      declare function callback_token() as long at p2
      Declare Function callback_to(ByVal Long) As Long At p3
    
      '===============================================================
    
    
      '-----------------------------------------------------------------
      function targetfun(byval a as double) as string
      '=================================================================
        msgbox 0, "ThinBasic receives from Oxygen: "+str$(a)
        function=str$(a*2)
      end function
    
      '----
      'TEST 
      '====
       callback_to callback_token targetfun    
       
      finish
    
    now my question - what I don't get is -
    - see lines 61, 77 and also 20... how can "function callback_token" use "targetfun" as a parameter?
    - line 34: does "&p" flush the whole array p(10) ?

    and Edit: some smaller questions
    So in the meantime I think to have found out that o2 can share previously in tB dimensioned variables with the current running tB-script by prefixing them with some # ?
    Would that also work with UDT and arrays?
    Just globals or also locals from within the function or sub that called O2_Exec ?
    What means ### ? Some remark?
    Would it be possible to execute for example TBGL-statements when I include it through O2 somehow?
    Are arrays 0 or 1-based?
    Last edited by ReneMiner; 18-07-2013 at 21:31.
    I think there are missing some Forum-sections as beta-testing and support

  8. #8
    This is not the easiest example to understand. It had trouble understanding it myself. Who wrote this stuff?!

    - see lines 61, 77 and also 20... how can "function callback_token" use "targetfun" as a parameter?

    The thinBasic function's token is passed as an integer, for use by thincore to invoke it.

    and Edit: some smaller questions
    So in the meantime I think to have found out that o2 can share previously in tB dimensioned variables with the current running tB-script by prefixing them with some # ?
    Would that also work with UDT and arrays?
    Just globals or also locals from within the function or sub that called O2_Exec ?
    What means ### ? Some remark?
    Would it be possible to execute for example TBGL-statements when I include it through O2 somehow?
    Are arrays 0 or 1-based?

    Arrays:

    are 1 based by default, but this can be changed with indexbase 0 'or any other base

    Sharing global variables directly with ThinBasic:

    dim as long a at #a ' Oxygen a is mapped to thinBasic a

    String variables

    dim as bstring s at #s 'use bstrings to map thinBasic strings

    Arrays:

    dim as single arr[100] at #arr 'Oxy arr is mapped to thinBasic arr, but no boundary checks.

    UDTs:

    These are also similarly supported

    type vector
    single x
    single y
    end type

    'the user must ensure that the types match.
    vector v at #vec ' v mapped to thinBasic vec.

    ###
    ...
    ###


    used to define a block window for display of assembly code.
    Use o2_prep(src) instead of o2_basic(src), and a string containing the assembly code will be returned instead of compilation.







    Last edited by Charles Pegge; 18-07-2013 at 21:48.

  9. #9
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    55
    Posts
    1,554
    Rep Power
    174
    Quote Originally Posted by Charles Pegge View Post
    This is not the easiest example to understand. It had trouble understanding it myself. Who wrote this stuff?!

    ...
    ...and why do almost all O2-examples return the Answer to the Ultimate Question of Life, the Universe, and Everything (42)?
    perhaps there are some white mice working while you're deep within your dreams
    Last edited by ReneMiner; 18-07-2013 at 22:40.
    I think there are missing some Forum-sections as beta-testing and support

  10. #10
    Habit I think.

    360 would be better. A more meaningful number in many ways.

Similar Threads

  1. Using Oxygen subs and functions in thinBasic
    By Charles Pegge in forum O2h Compiler
    Replies: 0
    Last Post: 18-03-2009, 13:25

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •