Kamd Cheater Reputation: 1
Joined: 02 May 2018 Posts: 28
|
Posted: Sat Jan 19, 2019 10:13 pm Post subject: C# script for CE Lua pipe that returns string? |
|
|
I still cannot figure how to return string from Lua in C#.
I have tried using command type 3 too, but always ends up either hanging/never return or Lua doesn't run code and just returns nothing in C#
I'm probably doing everything wrong -- I have basically no knowledge of pipe client
I have only got my workarounds successful, like writing result to file & read in C#, or convert every character to number and then keep asking Lua for next character number until Lua says it is done (stream I guess)
Considering it seems possible to return string directly, I don't want to use my workarounds because they would not be as good. but I just can't understand how to create the working method.
If anyone has working solution, please let me know.
For reference, this is the script to just execute string and return numbers (all result bytes will be 0 if try return string)
Code: | public int Exec(string cmdstring, int timeout = 1000, RichTextBox output = null)
{
NamedPipeClientStream s = new NamedPipeClientStream("test");
if (!s.IsConnected) s.Connect(timeout);
if (s.IsConnected)
{
byte[] result = new byte[8];
byte[] command = Encoding.ASCII.GetBytes(cmdstring);
byte[] size = BitConverter.GetBytes(command.Length);
byte[] fullcommand = new byte[1];
fullcommand[0] = 1; // Execute string
fullcommand = fullcommand.Concat(size).ToArray();
fullcommand = fullcommand.Concat(command).ToArray();
fullcommand = fullcommand.Concat(BitConverter.GetBytes((long)0)).ToArray(); // Parameter value
s.Write(fullcommand, 0, fullcommand.Length);
s.Read(result, 0, 8);
foreach (byte b in result) output.AppendText(b + ", ");
output.AppendText("\n");
s.Close();
return (int)BitConverter.ToUInt64(result, 0);
}
else
{
Console.WriteLine("PipeClient not connected!");
return 0;
}
} |
|
|