Does anyone know how to get the address of a method in a SimpleOOP class?
I make heavy use of callback functions, using @ to pass around the address of the function I want to call later, but the same doesn't seem to work with SimpleOOP class methods. Any idea how to achieve the same thing with these methods? I would like to be able to register the address of a method to call it later as a callback.
Thanks in advance
SimpleOOP method addresses
Re: SimpleOOP method addresses
Ok After studying the SimpleOOP generated code I managed to find a solution, you just need to pass the element whose method you are calling as the first parameter of CallFunctionFast! This really puts a hell of a power into the language!
Re: SimpleOOP method addresses
Example, please?
Re: SimpleOOP method addresses
Say you have an object called 'objName'. You wish to call indirectly the 8th method listed in its virtual table. Then this will do it:
Code: Select all
address.i = PeekI(PeekI(objName) + SizeOf(Integer) * 7)
CallFunctionFast(address, objName)
Re: SimpleOOP method addresses
For examplechris319 wrote:Example, please?
Code: Select all
Class foo
Public Method bar()
Debug "hello!"
EndMethod
EndClass
*foo.foo = NewObject.foo
CallFunctionFast( *foo\bar, *foo )
While this example doesn't really show anything useful, using pointers to reference methods inside objects enable event-driven programming to be used together with SimpleOOP objects and methods. This is really the top of both worlds. I'm easily building a GUI framework and it's working flawlessly.