Just as the title suggests, in addition to obtaining a pointer to a member procedure, we'll also call it in a new thread, just to explore the possibilities..
type ThreadTest
declare property getThreadProc() as any ptr
declare sub ThreadProc()
declare sub ThreadStart()
declare sub ThreadWait()
as any ptr m_Thread
end type
property ThreadTest.getThreadProc() as any ptr
dim r as any ptr = any
asm
lea eax, ThreadProc
mov [r], eax
end asm
return r
end property
sub ThreadTest.ThreadProc()
print "Output from thread "; m_Thread
end sub
sub ThreadTest.ThreadStart()
m_Thread = threadcreate(this.getThreadProc, @this)
end sub
sub ThreadTest.ThreadWait()
..threadwait(m_Thread)
end sub
dim v as ThreadTest ptr
v = new ThreadTest
v->threadstart()
v->threadwait()
delete v
Note: I know this is UNSAFE, Just a hack that could prove to be useful in certain situations :)
Type ThreadTest
Declare Property getThreadProc() As Any Ptr
Declare static Sub Proc(Me as ThreadTest ptr)
Declare Sub Start()
Declare Sub Wait()
private:
As Any Ptr m_Thread
End Type
Property ThreadTest.getThreadProc() As Any Ptr
return @Proc
End Property
Sub ThreadTest.Proc(Me as ThreadTest ptr)
for i as integer=1 to 10
Print "Output from thread " & i
sleep(500,1)
next
End Sub
Sub ThreadTest.Start()
m_Thread = ThreadCreate(this.getThreadProc, @this)
End Sub
Sub ThreadTest.Wait()
ThreadWait(m_Thread)
End Sub
Dim v As ThreadTest Ptr
v = New ThreadTest
v->Start()
? "wait ..."
v->Wait()
? "ok"
Delete v
sleep
Cherry, as anonymous1337 pointed out, the ".." (or just ".") prefix allows you to reference symbols from the global namespace, even if your local context has its own duplicate symbols with the same name.
@D.J.Peters: and your point is? this code demonstrates how to obtain pointers of non-static member procedures.. currently, the compiler does not allow this syntax-wise, and this is a way to get around it, the threading bit was just to demonstrate this, as requested by anonymous1337.
I would've probably written a more through-out example that builds vtables with GCC ABI-compatible virtual class interfaces, but unfortunately, I don't have much time at hand at the moment :)