Compiling a plugin

Started by Calin Leafshade, Tue 13/07/2010 15:35:03

Previous topic - Next topic

Calin Leafshade

heh well now i'm trying to do this:

http://curlpp.org/index.php/examples/71-example-21

or at least this is what i think i want..

obviously if you want to *return* data from a php script you have to wait for the transfer but i obviously cant make the player physically wait.

So i thought i could use a 'stream' and terminate it once its done.

then i can have a function in AGS which returns the string so far and get ags to check for the termination string.

... this is harder than i thought :p

Calin Leafshade

Another c++ question..

I know this is getting to the point of not being AGS relevant but it seemed wise to keep it in a single thread.

Code: ags

std::istringstream myStream("a");
string GetString(){
       
      return  myStream.str()
       
       }


ok so this creates a global stream (myStream) and the function GetString() is supposed to return the current value of the stream.

The function .str() should return the string value of the stream but for some reason you cant declare a function like that.

the proper declaration seems to be char* GetString() but thats an array of chars right? and str() doesnt return an array of chars it returns a cstring..

so how do i get a function to return a string?

Wyz

#22
AGS uses c-style strings, you can retrieve them with the c_str() method on a string object.

This should do the trick:
Code: ags

std::istringstream myStream("a");

std::string buffer;

const char *GetString()
{     
	buffer = myStream.str();
	return buffer.c_str();
}
Life is like an adventure without the pixel hunts.

Calin Leafshade

ok that seems pretty straight forward but i dont understand the const keyword.. why is that necessary?

Wyz

Const indicates that the variable is constant and may not be changed by anything that uses the function. IN this case AGS I guess, AGS will make a copy of the string anyway which can be changed. The string buffer does not allow the string to be changed in this way, so that's why it's in there.
Life is like an adventure without the pixel hunts.

Calin Leafshade

#25
Ok now i have a new problem (beside my ineptitude) but i think this may be a limitation of the way AGS works.

When running the request function from libcurl it freezes ags for a good 15 seconds. Is this just a limitation of the way the threading works within ags? or is there a way to run the plugin on a separate thread parallel to AGS's?

EDIT: Nevermind, plugin abandoned

Wyz

It is possible yes. The Windows API has the CreatThread function.
Life is like an adventure without the pixel hunts.

Monsieur OUXX

 

Calin Leafshade

abandoned only because a better plugin has already been made... sans source unfortunately.

This one is a direct tcp/ip plugin so it is far more lightweight and flexible, you just need to supply the http requests yourself.

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=35018.msg458420#msg458420

Wyz

Right, ok. How convenient. :D
Life is like an adventure without the pixel hunts.

Calin Leafshade

Sorry for getting you mess around with libcurl unnecessarily :p

you can have kisses.  :-X

SMF spam blocked by CleanTalk