how to deal with extern cpp's string

About Monkey 2 Forums Monkey 2 Programming Help how to deal with extern cpp's string

This topic contains 3 replies, has 2 voices, and was last updated by  abakobo 1 year, 4 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #12151

    abakobo
    Participant

    I have an extern method i’d like to import/wrap to mx2 but it has a cpp string& as argument. I’ve already successful played with extern cher* using Cstring but can’t figure out how to play with thesestd cpp strings.
    Is there something out of the box provided in mx2 (like Cstring/String.FromCstring) or do i have to convert it by myself cpp side?

    the method (the std::string& errorMsg is my trouble):

    #12177

    abakobo
    Participant

    there’s the std::string.c_str() method that returns a char array, i’ll go with thar cpp side..

    #12186

    nerobot
    Participant

    Also there is a method std::string::data() but:

    There are no guarantees that a null character terminates the character sequence pointed by the value returned by this function.

    AFAIK monkey’s CString is null-terminated, therefore  c_str() is a right choice. 🙂

    #12188

    abakobo
    Participant

    I finaly decided to go with std::copy so I keep the memory allocated by mx2 and don’t have to worry about GC/memory stuffs.
    It’s passing a fixed size char_t array and then transforms it to string when back to mx2. It the way I felt the safest (with my knowledge;)

    the aim was to deal with the error message..

    cpp side

    mx2 side

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.