embind doesn't support references to std::string (because the C++ program
can't modify the JavaScript heap, and JavaScript strings are immutable
anyway).

Can you instead wrap it with a function that takes an input std::string and
returns an output std::string?


On Fri, Apr 25, 2014 at 12:05 AM, Eric.Yang <[email protected]> wrote:

> Hi Chad,
>
> Thank you for your prompt reply. : D
>
> The second argument(char * data)'s content will be changed directly after
> the method(encryptData/decryptData) called.
>
> So second "data" argument is not only INPUT but also OUTPUT.(the others
> [encryptType, Len] are INPUT only)
>
> In your relay, you give me a great idea to deal with char point by
> wrapping it.
>
> And I write a test case for testing the idea.
> ------------------------------------------------------------
>   #include <emscripten/bind.h>
>   #include <iostream>
>   using namespace emscripten;
>
>   void test(char *s) {
>       s[0]=0x64;  // change to lower case 'd'
>   }
>
>   bool charWrap(std::string &s) {
>       test(&s[0]);
>       return true;
>   }
>
>   int main () {
>       std::string data = "Data";
>       std::cout << data << "-"<< data.length()<<"\n";
>       charWrap(data);
>       std::cout << data << "-"<< data.length()<<"\n";
>       return 0;
>   }
> ------------------------------------------------
> I  run this in nodeJS and It works by wrapping it.
> *Execute result:*
> Data-4
> data-4
>
> But when I use embind to export charWrap function,I get error.
> EMSCRIPTEN_BINDINGS(test) {
>       function("charWrap",&charWrap);
> }
> ---------------------------------------------
> emscripten/system/include/emscripten/bind.h:271:25: error: non-const
> lvalue reference to type
>       'basic_string<[3 * ...]>' cannot bind to a temporary of type
> 'basic_string<[3 * ...]>'
>                         internal::BindingType<Args>::fromWireType(args)...
>                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> emscripten/system/include/emscripten/bind.h:306:78: note: in instantiation
> of member function
>       'emscripten::internal::Invoker<bool, std::__1::basic_string<char,
> std::__1::char_traits<char>,
>       std::__1::allocator<char> > &>::invoke' requested here
>             reinterpret_cast<GenericFunction>(&Invoker<ReturnType,
> Args...>::invoke),
>
> ^
> cc.cpp:23:2: note: in instantiation of function template specialization
> 'emscripten::function<bool,
>       std::__1::basic_string<char, std::__1::char_traits<char>,
> std::__1::allocator<char> > &, >' requested
>       here
>         function("charWrap",&charWrap);
>         ^
> 1 error generated.
> ERROR    root: compiler frontend failed to generate LLVM bitcode, halting
> -------------------------------------
> Any comments?
>
> Thanks a lot again.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Chad Austin
Technical Director, IMVU
http://engineering.imvu.com <http://www.imvu.com/members/Chad/>
http://chadaustin.me

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to