I want to write ChaiScript code using std::wstring type like 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 the instances of std::wstring type is 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 the instances of wchar_t type doesn't work.
Do the compare operator method must be added?
" if(s[1]==t[1]){"
" print(\"2\");"
" }"
D:\TestWork\test_chaiscript>t5
terminate called after throwing an instance of 'chaiscript::exception::eval_error'
what(): Error: "Error with numeric operator calling: =="
To compare the instance of std::wstring type with the literal of string type doesn't work. I cannot input the literal of wstring type.
Is it possible to input the literal of wstring type in ChaiScript?
" if(s==\"aaaa\"){"
" print(\"2\");"
" }"
D:\TestWork\test_chaiscript>t5
terminate called after throwing an instance of 'chaiscript::exception::eval_error'
what(): Error: "Can not find appropriate '==' operator." With parameters: (wstring, const string)
To compare the instance of wchar_t type with the literal of wchar_t type doesn't work. I cannot input the literal of wchat_t type.
Is it possible to input the literal of wchat_t type in ChaiScript?
" if(s[1]=='b'){"
" print(\"2\");"
" }"
D:\TestWork\test_chaiscript>t5
terminate called after throwing an instance of 'chaiscript::exception::eval_error'
what(): Error: "Error with numeric operator calling: =="
Yes, you will need to tell ChaiScript something about
wchar_t
, such as the==
operator. For example: