• Advertisement
Sign in to follow this  

const char* returns and script string

This topic is 1857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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:

[code]
// 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);
[/code]

Regards,
Andreas

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement