Squirrel

The programming language
Welcome to Squirrel Sign in | Join | Help
in Search

std::string

Last post 06-02-2007, 7:04 AM by Katsuaki Kawachi. 7 replies.
Sort Posts: Previous Next
  •  12-14-2005, 8:15 AM 507

    std::string

    Hi,

    is there already a binding for std::string out there? I'm trying to bind a function that takes a std::string reference and I was wondering if there's already someone who wrote one and has it more or less tested. This would avoid having a bunch of binding-approaches out there and would focus bug-fixing, etc.

    Rincewind
  •  12-16-2005, 10:03 AM 508 in reply to 507

    Re: std::string

    Ok, here's a first attempt to allow the usage of std::string in SQplus.

    I'm not quite sure about how to handle unicode characters. Also, I'm not quite sure about the lifetime of the c_str() pointer in the Push-function.
    My first tests show it works though.

    Comments welcome.

    Rincewind

    inline bool    Match(TypeWrapper,HSQUIRRELVM v,int idx) {
            return sq_gettype(v,idx) == OT_STRING;
        }
        inline ::String Get(TypeWrapper,HSQUIRRELVM v,int idx)
        {
            const SQChar * s;
            SQPLUS_CHECK_GET(sq_getstring(v,idx,&s));
            return std::string(s);
        }

        inline void Push(HSQUIRRELVM v,const std::string& value) { sq_pushstring(v,value.c_str(),-1); }
  •  12-17-2005, 8:54 AM 509 in reply to 508

    Re: std::string

    To make a unicode/ascii stl string, typedef something like this:



    typedef std::basic_string < SQChar > SQString;


    Alberto

  •  12-17-2005, 11:00 AM 510 in reply to 509

    Re: std::string

    Hmmm, most people will probably just be using std::string or wstring. Will have to see what kind of copy-constructors are implemented. Thanks for the hint though. I will look into it.

    Rincewind
  •  01-22-2006, 1:29 PM 564 in reply to 508

    Re: std::string

     rincewind wrote:
    inline bool    Match(TypeWrapper,HSQUIRRELVM v,int idx) {
            return sq_gettype(v,idx) == OT_STRING;
        }
        inline ::String Get(TypeWrapper,HSQUIRRELVM v,int idx)
        {
            const SQChar * s;
            SQPLUS_CHECK_GET(sq_getstring(v,idx,&s));
            return std::string(s);
        }

        inline void Push(HSQUIRRELVM v,const std::string& value) { sq_pushstring(v,value.c_str(),-1); }
     
    I downloaded sqplus from the Wiki, and the above code is not there - can I just add it to the other match functions somewhere in sqplus?
     
    Otherwise: I love Squirrel!
    Squirrel won in tough competion between GameMonkey Script and Angelscript. Great job!
    And sqplus was what made me decide.
  •  08-04-2006, 6:42 AM 1098 in reply to 507

    Re: std::string

    Sorry to wake this old topic up, but I tried to make SqPlus work with std::string, and i encountered this problem : in sqplus.h, uncommenting "#define SQPLUS_SUPPORT_STD_STRING" isn't enough, i had to add "#include <string>" outside the SqPlus namespace.
    That's almost nothing, but can be confusing (i'm a very beginner with SqPlus, and it at least confused me ;))
  •  05-31-2007, 12:38 AM 1864 in reply to 1098

    Re: std::string

    Hi.

    I use the 20070304 snapshot, I just saw the newly one but seeing the changelog, it won't be of any use.

    I use SqPlus with SQPLUS_CONST_OPT and SQPLUS_SUPPORT_STD_STRING defined. It works fine under Windows with MinGW as the compiler. However, I just discovered that it doesn't work when building it with GCC under Linux. When I run "make" in the sqplus directory it fails to compile at the definition of Push, Match and Get functions for std::string.

    It seems that I'm not the only one, seeing this thread. So, I did the same as Ceacy and it worked. I think it should be included in the next snapshot. Here is the code, added right after all the defines of sqplus.h:

    #ifdef SQPLUS_SUPPORT_STD_STRING
    } // close SqPlus namespace
    #include <string>
    namespace SqPlus {
    #endif

    Any remarks about this ?

    Thanks,
    Sebastien
  •  06-02-2007, 7:04 AM 1869 in reply to 1864

    Re: std::string

    Thank you for your fix.
    It is merged in 20070602 snapshot.
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems