Trans problem with glfw

Monkey Forums/Monkey Bug Reports/Trans problem with glfw

Rushino(Posted 2012) [#1]
Hello,

I am using the version 65 of monkey.

I created a simple cpp file to make an extension which is going to be for the glfw target and i get an error regarding this line in the generated code main.cpp...

..\main.cpp(4544): error C2039: 'mark' : is not a member of 'Wsock' [G:\Programmes\MonkeyPro65\modules\wsock\wsock_demo.build\glfw\vc2010\MonkeyGame.vcxproj]

...
void bb_wsock_demo_WsockTesting::mark(){
	Wsock::mark();
}
...


It try to call 'mark' (Marksibly related ? XD) on my class extension which is obviously not there..

Here my cpp file.

#pragma comment( lib, "PocoNet.lib" )

//#include "Wsock.h"
#include <iostream>
#include <string>
//#include "HTTPClientSession.h"

class Wsock
{

public:

	bool Wsock::Connect(std::string str)
	{
		return true;
	};

	void Wsock::Disconnect()
	{
	};

	int Wsock::GetReadyState()
	{
		return 10;
	};

	void Wsock::Send(std::string message)
	{
	};

	bool Wsock::IsConnected()
	{
		return true;
	};

	void Wsock::OnConnecting()
	{
	};

	void Wsock::OnDataReceived(std::string data)
	{
	};

	void Wsock::OnDisconnect(std::string code, std::string reason, bool cleanClose)
	{
	};

	void Wsock::OnError(std::string error)
	{
	};
	
	Wsock::Wsock(void)
	{
	};

	Wsock::~Wsock(void)
	{
	};
};


And here my monkey module that import this cpp file...

[code­]

Strict

#If TARGET = "html5"
Import "native/html5/wsock.html5.js"
#ElseIf TARGET = "glfw"
Import "native/glfw/PocoNet.lib"
Import "native/glfw/PocoNet.dll"
Import "native/glfw/wsock.cpp"
#Else
#Error "Sorry, this module is only available for HTML 5 and GLFW target!"
#End

Public

Class WsockStatus

Const IDLE:Int = -1
Const CONNECTING:Int = 0
Const CONNECTED:Int = 1
Const CLOSING:Int = 2
Const CLOSED:Int = 3

End

Extern

Class Wsock = "Wsock"
Method Connect:Bool(url:String)
Method Disconnect:Void(reason:String)
Method GetReadyState:Int()
Method Send:Void(message:String)
Method IsConnected:Bool()
Method OnConnecting:Void()
Method OnDataReceived:Void(data:String)
Method OnDisconnect:Void(code:String, reason:String, cleanClose:Bool)
Method OnError:Void(error:String)
End Class

[/code]

I had to create the mark method in my cpp class to make it build...


Any ideas ?


AdamRedwoods(Posted 2012) [#2]
Hi. this is not a bug report for Monkey, so this post would be better just under the general monkey progrmaming forum.


I had to create the mark method in my cpp class to make it build...


Correct. If you want monkey to manage GC in your native class, then you will need to allow monkey's GC to "mark" it somehow.
class MyClass : public Object {
  mark() { Object::mark(); };
}

is generally how i add it.
(I should also note that generally you cannot overload the monkey New method when applying GC to your own native classes.)


Rushino(Posted 2012) [#3]
So you saying this is a normal behavior ? From what ive seen here (http://code.google.com/p/mnet/source/browse/mnet/native/mnet.glfw.cpp) it doesn't seem to have this and it still work.. it is because the class is static ? to be honest i didn't heard anywhere in the doc about 'marking' a class about this. Is there any reference i can get somewhere regarding this or guidance on how to make a cpp extension for the glfw target ?

Also could you explain a bit this part of your reply.. :)

(I should also note that generally you cannot overload the monkey New method when applying GC to your own native classes.)


Thanks Adam !


AdamRedwoods(Posted 2012) [#4]
it is because the class is static ?

yes, all static, and they use a "close" function to cleanup memory buffers.

Is there any reference i can get somewhere regarding this or guidance on how to make a cpp extension for the glfw target ?

nope, although someday when i'm in a good mood i'll write a tutorial. or Mark can.
Meanwhile, here's some info:
http://monkeycoder.co.nz/Community/posts.php?topic=3598#39348


(I should also note that generally you cannot overload the monkey New method when applying GC to your own native classes.)

it's complicated:
i've encountered problems when extending extern classes and trying to overload the New() method. i doesn't seem to call the original constructor. This can be overcome if Monkey allows us to Extern the New method (currently does not).

this is overcome by leaving New() and use a Create() method to fill in parameters. see my wxMonkey examples.


Rushino(Posted 2012) [#5]
Do you actually can create an instance of the object or it have to be all static ?


AdamRedwoods(Posted 2012) [#6]
using the GC, you can create instances.
if it's all static (or all contained within the native code) you do not have to add any GC, but you will need a "close" or "discard" function.


Rushino(Posted 2012) [#7]
Alright.. one last thing.. in your sample

class MyClass :
public Object {
mark() { Object::mark(); };
}

Object doesn't seem to work there. I am missing something ? Did you meant..

void mark()
{
MyClass::mark();
};


AdamRedwoods(Posted 2012) [#8]
this is what i have...
class wxMonkeyDC : public Object {
public:
	wxMonkeyDC() {};
	~wxMonkeyDC() {};
	void mark() { Object::mark(); };
};


in monkey:
Extern

Class wxDC = "wxMonkeyDC"
End

Public



Rushino(Posted 2012) [#9]
Why public object in class ?


Rushino(Posted 2012) [#10]
Damn.. really harder than i though to make a websocket client library. I am not very good in C++. The problem is that hte websocket lib is using the boost lib so i have to deal with that.