PDA

View Full Version : [Q]: Function f() PTR?



ReneMiner
18-07-2013, 12:11
I saw in some code-example from Charles (http://www.thinbasic.com/community/showthread.php?t=9866&highlight=calls+oxygen) some method to set a pointer at the end of the oxygen-function alike



Function F() As Long At #P


and I tried to find some further information about this and discovered that tB also seems to allow appending some pointers to functions.
In tB-help it says:


...
Function declaration:
Function FunctionName [([arguments])] [AsType [PTR]]
...


Now I'm nosy because there's nothing more explained about "PTR".
How would that work - and what type of pointer?

Charles Pegge
18-07-2013, 19:15
Oxygen now uses the word link to pass a function pointer to a thinBasic pointer. ThinBasic uses at ​to map a function address to a pointer

This is the standard way of interfacing OxygenBasic procedures and thinBasic procedures.



uses "oxygen"


dim as string src
dim as long pHypot3d
dim as long pFinish


src="
function hypot3d(double a,double b, double c) as double link #pHypot3d
return sqr( a*a+b*b+c*c)
end function


sub finish() link #pFinish
terminate 'release all resources
end sub
"
o2_basic src
if o2_error then
msgbox 0,o2_error
stop
else
o2_exec
end if


declare function Hypot3d(byval double, byval double, byval double ) as double at pHypot3d
declare sub Finish() at pFinish


msgbox 0,Hypot3d(2,3,4)
Finish()

ReneMiner
18-07-2013, 19:51
OK, thanks for your reply. First at all I prefer using Rawtext-method from tB because of syntax highlighting.
Edit- O2-question here now (http://www.thinbasic.com/community/showthread.php?t=9866&p=89299#post89299)

ReneMiner
18-07-2013, 20:29
ok, this was more about the thinBasic "function f() as whatever Ptr"- so I move the oxygen-specific questions over here (http://www.thinbasic.com/community/showthread.php?t=9866&p=89299#post89299)