Search code examples
c++chaiscript

Chaiscript string problem between Visual Studio and Xcode


I've hit a very weird bug or most probably I'm missing something. My script runs perfectly when compiled with VS 2015 but fails when I switch to Mac and use Xcode 9.

The problem is, on Mac, chaiscript removes the beginning of returned strings. I don't know why? Here's the problem: On C++ side I have a class like this that connects to an API and stores API reply in JSONString:

class MyClass
{
  public string JSONString;
  public void Get(URL);
}

This class is instantiated from chaiscript and contains JSON data. Here's the code:

def GetAPIData()
{
  var myurl = "Https://api.domain.com";
  auto &request = MyClass();
  request.Get(myurl);
  return request.JSONString;
}

var response = GetAPIData();

When I log the string from GetAPIData, on Windows it's something like this:

[{"id": 91, "name": "aaa", "status": "Active"}, {"id": 2, "name": "bbb", "status": "Active"}]

On Mac:

: "aaa", "status": "Active"}, {"id": 2, "name": "bbb", "status": "Active"}]

Why this could be happening?


Solution

  • I'm pretty sure this a bug. I was able to work around the issue by wrapping request.JSONString with to_string().

    def GetAPIData()
    {
      var myurl = "Https://api.domain.com";
      auto &request = MyClass();
      request.Get(myurl);
      return to_string(request.JSONString);
    }