Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Calin Leafshade on Sun 20/02/2011 01:53:35

Title: Exchanging the String type with the plugin API
Post by: Calin Leafshade on Sun 20/02/2011 01:53:35
How can i pass a string between AGS and the plugin API?

How do i pass a managed type like a string?
Title: Re: Exchanging the String type with the plugin API
Post by: Wyz on Sun 20/02/2011 11:36:34
AGS -> plugin
Let's say you have a plugin function that returns a string like this:

import void SetString(String input);


that would translate to:

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:

import String GetString();


that would translate to:

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


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


Title: Re: Exchanging the String type with the plugin API
Post by: Calin Leafshade on Sun 20/02/2011 13:07:04
Thanks Wyz!
Title: Re: Exchanging the String type with the plugin API
Post by: helios123 on Sun 20/02/2011 19:26:50
Also below excerpt from the AGS plugin API documentation (http://adventuregamestudio.co.uk/acplugin.htm) 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.
Title: Re: Exchanging the String type with the plugin API
Post by: Pumaman on Sun 20/02/2011 19:33:31
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!