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]
Bookmarks