Jump to content

  • Log In with Google      Sign In   
  • Create Account

- - - - -

const char* returns and script string


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Starfox   Members   -  Reputation: 504

Like
0Likes
Like

Posted 17 December 2012 - 07:25 AM

Can I bind a function that returns a char* in the script as one that returns a string? Here's the binding I'm using and it doesn't seem to be working:

Engine->RegisterObjectMethod("event", "string characters() const", asMETHODPR(event, characters, (void) const, const char* const), asCALL_THISCALL);

The function declaration is along the lines of:

class event
{
...
const char* const characters() const;
...
};

Do I have to wrap it somehow or can I hint AS to convert to a string? I'm using the string binding code that comes with the SDK.
Holy crap I started a blog - http://unobvious.typepad.com/

Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3377

Like
0Likes
Like

Posted 17 December 2012 - 08:20 AM

Unfortunately you'll need to create a wrapper for this.

There is no automatic conversion from const char * to std::string or vice versa.

You don't need to change your class to create the wrapper. You can implement a global function and register it with AngelScript as if it was a class member:

// Create a wrapper to convert const char * to std::string
std::string event_characters(const event &self)
{
   return std::string(self.characters());
}

// Register the wrapper instead of the method
engine->RegisterObjectMethod("event", "string characters() const", asFUNCTIONPR(event_characters, (const event &), std::string), asCALL_CDECL_OBJLAST);

Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 Starfox   Members   -  Reputation: 504

Like
0Likes
Like

Posted 17 December 2012 - 06:07 PM

Great, thanks.
Holy crap I started a blog - http://unobvious.typepad.com/




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS