Thanks, I cloned your project and played with it for a while. Actually, you were really close to succeeding. Your setup and everything you do until sending the expression via WSTP is fine.
The problem in your code (I will refer to what you have on github, which is slightly different from what you posted here) is that you send a string "2+2+2". When WSStream
sees a string it sends it as a String
expression, which in WL evaluates to itself.
The expression that you want to send is Plus[2, 2, 2]
, which in WL evaluates to 6. So I modified your code as follows:
// Write the expression to the stream
std::cout << "Add 2+2+2 to the stream" << std::endl;
LLU::WS::Function enterExpressionFunction {"EnterExpressionPacket", 1};
test << enterExpressionFunction << LLU::WS::Function("Plus", 3) << 2 << 2 << 2;
// Wait for output packet Out[1]:= and the computed results
And the output I get from your debug prints is:
(...)
Add 2+2+2 to the stream
Wait for output packet
Function head:OutputNamePacket Arguments :1 String : Out[1]=
Function head:ReturnExpressionPacket Arguments :1 String : 6
(...)
So the result is 6, as expected.