std::wstring in ChaiScript -


i beginner chaiscript.

i try use std::wstring type in chaiscript.

std::string type works well.

#include <iostream> #include <chaiscript/chaiscript.hpp> #include <chaiscript/chaiscript_stdlib.hpp>  int main() {     chaiscript::chaiscript chai(chaiscript::std_lib::library());      std::cout << chai.eval<std::function<int (std::string)> >(         "fun(s){"                "   if(s==\"aaa\"){"         "       print(\"1\");"               "   }"               "   if(s[1]=='b'){"         "       print(\"2\");"         "   }"         "   return 3;"         "}"     )(std::string("abcd"));  }  d:\testwork\test_chaiscript>t1.exe 2 3 

std::wstring type raises exception.

#include <iostream> #include <chaiscript/chaiscript.hpp> #include <chaiscript/chaiscript_stdlib.hpp>  int main() {     chaiscript::chaiscript chai(chaiscript::std_lib::library());      std::cout << chai.eval<std::function<int (std::wstring)> >(         "fun(s){"                "   if(s==\"aaa\"){"         "       print(\"1\");"               "   }"               "   if(s[1]=='b'){"         "       print(\"2\");"         "   }"         "   return 3;"         "}"     )(std::wstring(l"abcd")); } 

d:\testwork\test_chaiscript>t2.exe
terminate called after throwing instance of 'chaiscript::exception::eval_error'
what(): error: "can not find appropriate '==' operator." parameters: (nst7__cxx1112basic_stringiwst11char_traitsiwesaiweee, const string)

this application has requested runtime terminate in unusual way.
please contact application's support team more information.

chaiscript git version , mingw-w64 builds 5.1.0 used.

g++ t2.cpp -std=c++14 -o2 -os -wall -mthreads -o t2.exe -dwin32 -d_win32 -dunicode -d_unicode -id:\myprj\chaiscript_git\include -static-libstdc++ -static-libgcc -wl,-bstatic -lstdc++ -lpthread -wl,-bdynamic 

it same in vs2013.

how can use std::wstring type in chaiscript?

std::wstring other type in chaiscript - have tell chaiscript how want use it.

in case, trying perform == comparison, have not provided chaiscript operator==(const std::wstring &, const std::wstring &) function use.

the easiest way use existing code std::string , expose of same functionality.

for example:

#include <chaiscript/dispatchkit/bootstrap_stl.hpp>  chai.add(chaiscript::bootstrap::standard_library::string_type<std::wstring>("wstring")); 

for reference, see bootstrap.hpp code initializes std::string.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -