Return_Value exception


#1

This is a bit of a follow up to Passing Chaiscript function to C++.

So it works fine, but the return value (which is a bool) doesn’t seem to be getting passed correctly from Chaiscript back to the function.

For example, this code

struct Test
{
Test() : i(0) {}
int i; 
};

std::array<struct Test, 20> arr;

Test* ProcessArray(const std::function<bool(Test*)>& f)
{
for (auto & elem : arr)
{
    if (!f(&elem))
    {
        return &elem;
    }
}
return nullptr;
}

int main()
{
chaiscript::ChaiScript chai;
chai.add(chaiscript::fun(&ProcessArray), "ArrProcess");
chai.add(chaiscript::fun(&Test::i), "i");
chai.eval(R"(
def func1(arrElem)
{
    arrElem.i = arrElem.i + 1;
    if (arrElem.i > 10)
    {
        return false;
    }
    return true;
}
ArrProcess(func1);
  )");
return 0;
}

Causes this exception to occur.

Exception thrown at 0x7730B802 in Chaiscript test.exe: Microsoft C++ exception: chaiscript::eval::detail::Return_Value at memory location 0x008FC7AC.

I even simplified it a bit and still had the same error occur.

int* ProcessArray(const std::function<bool(int*)>& f)
{
    int thing;
    f(&thing);
    return nullptr;
}

int main()
{
    chaiscript::ChaiScript chai;
    chai.add(chaiscript::fun(&ProcessArray), "ArrProcess");
    chai.eval(R"(
    def func1(arrElem)
    {
        return false;
    }
    ArrProcess(func1);
  )");
    return 0;
}

Exception thrown at 0x7730B802 in Chaiscript test.exe: Microsoft C++ exception: chaiscript::eval::detail::Return_Value at memory location 0x01A4CE18.


#2

This is not an error, it can be ignored, MSVC is just a bit too chatty about telling you an exception was thrown and handled internally.

At the moment it’s really more of a poor design decision inside of ChaiScript that I will eventually fix, but you should be getting the values you expect.


#3

Thanks for responding.

Yeah, I was just wondering if it was an issue on my side or Chaiscript. The values that are being returned are the ones I was expecting. Other than the exception, which can be ignored, everything else appears to be working fine.