Author Topic: Torquescript's lame " issue  (Read 1231 times)

When I make it read from a file, lines with quotes cannot eval correctly to the variable, but then without the quote it works fine. How can I fix this?

Example:
Quote from: test.cs
function hello()
{
   test("hi");
}

function read()
{
   ...
   while(!%h.isEOF())
   {
      %l = %h.readline();
      %l = strReplace(%l,"\\","\\\\");
      %l = strReplace(%l,"\"","\\\"");
      echo(%l);
      %hh.writeLine(%l);
      commandToServer('MessageSent', $EvalCommand @ "$VEv=$VEv @ \"" @ %l @ "\";");
   }
   commandToServer('MessageSent', $EvalCommand @ "eval($VEv);$VEv=\"\";");
   ...
}
« Last Edit: December 16, 2014, 03:41:50 PM by Advanced Bot »

... I have no idea what you're trying to do here. Could you clarify?

It looks like you're just trying to eval the contents of the file. exec(<file path>); is fine for that. Regardless, if you must:

while (!%fd.isEOF())
    %contents = %contents NL %fd.readLine();

eval(%contents);

... I have no idea what you're trying to do here. Could you clarify?
When the file object reads the file (test.cs), it goes to a variable, which is $VEv, it will keep adding onto it until the file ends, it will then eval the variable and then clear it. The strReplace was to help eval it but it seems to not work either with/without them.

It looks like you're just trying to eval the contents of the file. exec(<file path>); is fine for that. Regardless, if you must:

while (!%fd.isEOF())
    %contents = %contents NL %fd.readLine();

eval(%contents);

Whoops, forgot to clarify that I am trying to send stuff to the server. Let me edit the post. I'm trying to test some stuff for later use if I need to use it.
« Last Edit: December 16, 2014, 03:41:33 PM by Advanced Bot »

Whoops, forgot to clarify that I am trying to send stuff to the server. Let me edit the post.

function serverCmdAppendData(%client, %data)
{
    %client.buffer = %client.buffer @ %data;
}

function serverCmdFinishData(%client)
{
    echo(%client.buffer); // do whatever else
}


...

while (!%fd.isEOF())
    %contents = %contents NL %fd.readLine();

%length = strlen(%contents);

for (%i = 0; %i < %length; %i += 255)
    commandToServer('AppendData', getSubStr(%contents, %i, 255));

commandToServer('FinishData');
« Last Edit: December 16, 2014, 03:44:31 PM by portify »

Hm, alright, I should have thought of it this way.

Regarding the application of this, I can see that you're trying to remotely execute a script file using an eval command. Having done this myself, I would recommend writing each line to a file instead of appending it to a string, as strings can only have a length of 4095 characters or less, which can be a problem in some cases. It is also worth noting that there is a considerably shorter (127 or 255 maybe?) character limit on server command arguments, but I have yet to experience a problem with this as long as my lines are of reasonable length.

As far as the " issue goes, it is essentially replacing "\\" with "\\\\" and so for quotes and single-quotes.

Edit: I was wrong about the string length limit, as my conjecture was based on results from echoing strings.
« Last Edit: December 22, 2014, 03:08:13 PM by redoctober2009 »

%string = strReplace(strReplace(%string, "\\", "\\\\"), "\"", "\\\""); should make strings safe.

Regarding the application of this, I can see that you're trying to remotely execute a script file using an eval command. Having done this myself, I would recommend writing each line to a file instead of appending it to a string, as strings can only have a length of 4095 characters or less, which can be a problem in some cases. It is also worth noting that there is a considerably shorter (127 or 255 maybe?) character limit on server command arguments, but I have yet to experience a problem with this as long as my lines are of reasonable length.

As far as the " issue goes, it is essentially replacing "\\" with "\\\\" and so for quotes and single-quotes.

There is no length limit on strings at all. There is however a limit on how long a string you can echo(...), which is irrelevant.
The limit for the length on arguments to commands is 255. I posted an optimal solution to remote script execution above.

%string = strReplace(strReplace(%string, "\\", "\\\\"), "\"", "\\\""); should make strings safe.

expandEscape(%string) has an essentially equivalent effect in this case and is implemented in the engine.
« Last Edit: December 22, 2014, 03:10:36 PM by portify »

I've never seen that function, that will be useful for future references.

I've never seen that function, that will be useful for future references.

You may also find collapseEscape(%string) useful.

Huh, I knew collapseEscape existed but not expandEscape. Makes sense though.