Exchanging the String type with the plugin API

Started by Calin Leafshade, Sun 20/02/2011 01:53:35

Previous topic - Next topic

Calin Leafshade

How can i pass a string between AGS and the plugin API?

How do i pass a managed type like a string?

Wyz

AGS -> plugin
Let's say you have a plugin function that returns a string like this:
Code: ags

import void SetString(String input);


that would translate to:
Code: ags

void SetString(const char *input)
{
  // here you can just use input as a regular null terminated string.
}


plugin -> AGS
Let's say you want to retrun a string from a plugin function like this:
Code: ags

import String GetString();


that would translate to:
Code: ags

const char *GetString()
{
  return (engine->CreateScriptString(...));
}


Note that you need to use the CreateScriptString function for all strings you return.


Life is like an adventure without the pixel hunts.

Calin Leafshade


helios123

Also below excerpt from the AGS plugin API documentation should be kept in mind:

"The text script currently supports char, short and int types. These are 1, 2 and 4 byte integers respectively. Text script strings are implemented as standard C-style char* pointers, but with preallocated buffers of 200 bytes per string. Therefore, if you write a function which takes a string from the text script, make sure that if you add anything to it you don't write past 200 characters, or problems will result."

So I think we can safely declare and use character arrays of about 205 characters for passing strings between engine and plugin.
That's all for now,
helios123

Pumaman

Ooh, I should remove that. That 200-byte thing refers to old style "string" variables, not to the newer "String" variables in newer versions of AGS.

Wyz has given the answers you need, anyway!

SMF spam blocked by CleanTalk