compare std::wstring type and represent of wstring literal in ChaiScript -


i want write chaiscript code using std::wstring type below c++ code.

#include <iostream>  int testfunc(std::wstring s, std::wstring t) {     if(s==t)     {         std::cout << "1" << std::endl;     }      if(s[1]==t[1])     {         std::cout << "2" << std::endl;     }      if(s==l"aaaa")     {         std::cout << "3" << std::endl;     }      if(s[1]==l'b')     {         std::cout << "4" << std::endl;     }      return 5; }  int main() {     std::cout << testfunc(std::wstring(l"abcd"), std::wstring(l"abbb"));      return 0; }  d:\testwork\test_chaiscript>t6 2 4 5 

to compare instances of std::wstring type good.

#include <iostream> #include <chaiscript/chaiscript.hpp> #include <chaiscript/chaiscript_stdlib.hpp> #include <chaiscript/dispatchkit/bootstrap_stl.hpp>  int main() {     chaiscript::chaiscript chai(chaiscript::std_lib::library());      chai.add(chaiscript::bootstrap::standard_library::string_type<std::wstring>("wstring"));      std::cout << chai.eval<std::function<int (std::wstring, std::wstring)> >(         "fun(s, t){"         "   if(s==t){"         "       print(\"1\");"         "   }"         "   return 3;"         "}"     )(std::wstring(l"abcd"), std::wstring(l"abaa"));      return 0; }  d:\testwork\test_chaiscript>t5 3 

to compare instances of wchar_t type doesn't work.

do compare operator method must added?

        "   if(s[1]==t[1]){"         "       print(\"2\");"         "   }"  d:\testwork\test_chaiscript>t5 terminate called after throwing instance of 'chaiscript::exception::eval_error'   what():  error: "error numeric operator calling: ==" 

to compare instance of std::wstring type literal of string type doesn't work. cannot input literal of wstring type.

is possible input literal of wstring type in chaiscript?

        "   if(s==\"aaaa\"){"         "       print(\"2\");"         "   }"  d:\testwork\test_chaiscript>t5 terminate called after throwing instance of 'chaiscript::exception::eval_error'   what():  error: "can not find appropriate '==' operator." parameters: (wstring, const string) 

to compare instance of wchar_t type literal of wchar_t type doesn't work. cannot input literal of wchat_t type.

is possible input literal of wchat_t type in chaiscript?

        "   if(s[1]=='b'){"         "       print(\"2\");"         "   }"  d:\testwork\test_chaiscript>t5 terminate called after throwing instance of 'chaiscript::exception::eval_error'   what():  error: "error numeric operator calling: ==" 

yes, need tell chaiscript wchar_t, such == operator. example:

chai.add(   chaiscript::fun<bool (wchar_t, wchar_t)>(     [](wchar_t lhs, wchar_t rhs) { return lhs == rhs; }   ), "==" ); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -