Callbacks

Monkey Forums/Monkey Programming/Callbacks

bruZard(Posted 2011) [#1]
can anyone tell me whats wrong with my try to create a callback system?

C++
class CTest;

CTest* app;

class CTest : public Object{
public:

	CTest();
	~CTest();

	virtual int callback01();
	virtual int callback02();

	int invokeCallback01();
	int invokeCallback02();
	
	int Run();
};

void runApp(){
	app->Run();
}

CTest::CTest(){
	app = this;
	runApp();
}

CTest::~CTest(){
	delete app;
};

int CTest::callback01(){
	return 0;
}

int CTest::callback02(){
	return 0;
}

int CTest::invokeCallback01(){
	callback01();
	return 0;
};

int CTest::invokeCallback02(){
	callback02();
	return 0;
};

int CTest::Run(){
	invokeCallback01();
	invokeCallback02();

	return 0;
}

Monkey:
Strict

Import "callbackTest.cpp"

Extern 

Class CTest = "CTest"
	Method callback01:Int()
	Method callback02:Int()
End

Private 

Class CApp extends CTest
	Field app:App
	
	method new(app:App)
		Self.app = app
	End
	
	Method callback01:Int()
		Self.app.callback01()
		Return 0
	End
	
	Method callback02:Int()
		Self.app.callback02()
		Return 0
	End
End

Public

Global dev:CApp

Class App
	Method new()
		dev = New CApp(Self) 
	End
	
	Method callback01:Int()
		Return 0
	End
	
	Method callback02:Int()
		Return 0
	End
End

Class myApp extends App
	Method callback01:Int()
		Print "Callback 01"
		Return 0
	End
	
	Method callback02:Int()
		Print "Callback 02"
		Return 0
	End
End

Function Main:Int()
	Print "Start"
	New myApp
	Return 0
End



bruZard(Posted 2011) [#2]
omg ... i think Mark has a potion of fairy dust used for this magic ... what should i do to make this **** work?


bruZard(Posted 2011) [#3]
got it ... i forgot to declare "int (*runner)()"