pointer mayhem

BlitzMax Forums/BlitzMax Programming/pointer mayhem

Chris C(Posted 2006) [#1]
if have a type like this (notice the ptr is the first variable this will always remain so)
Type XGgadget
Field WidgetPtr:Byte Ptr

a callback provides me with a value equal to widgetptr
however I want to be able to call a method of the XGgadget that has a widgetptr = the callbacks widget ptr


Function optioncallback(o:Byte Ptr,i:Int)
Print Int o
Print Int check1.widgetptr
(if the callback was caused by the check1 gadget check1.widgetptr==o

bloody 'ell aint pointers fun!

o.getValue() would be nice...


Chris C(Posted 2006) [#2]
No one got any bright ideas?...


Dreamora(Posted 2006) [#3]
Callbacks only work like this
Type Trala
  field WidgetCallback(o:Byte Ptr, i:int)

end type

function redrawWindow(x:Byte Ptr, i:int)

local test:trala = new trala
test.WidgetCallback = redrawWindow

test.WidgetCallback(someBytePtr,someInt)


that should be the correct usage. Byte pointers don't work, BM is a type safe language, so you have to use the delegate like approach.
And you can only use Functions (if regular or type based functions does not make a difference) for function pointers, not methods!


Chris C(Posted 2006) [#4]
nah thats not what I meant!!

the field isnt a callback ptr its a ptr to a C object...


Dreamora(Posted 2006) [#5]
If you assign the C object to the BytePtr then you can't do anything with it. BM is type save, casting around unsave stuff is not possible.

If you want to use the object within BM, check out bbObject (it shows 2 fields that you need, think it was there. are pointers to the constructor / destructor) and declare the whole type in extern. After that you should be able to use it, thought you can't extend it or anything.


Chris C(Posted 2006) [#6]
can you be a bit more specific, I just need to call methods of the object...