Old_LIT2/base/t2csri/rubyUtils.cs
2026-02-27 21:56:30 -05:00

95 lines
1.9 KiB
C#
Executable file

// Lit2
$LIT2::WaitTime = 2; // Seconds
function rubyCmp(%first, %second)
{
%result = rubyEval("cmp('" @ %first @ "', '" @ %second @ "')");
return getSubStr(%result, 0, 1);
}
function rubyExec(%file)
{
%data = "";
%handle = new FileObject();
%handle.openForRead(%file);
while (!%handle.isEOF())
%data = %data @ %handle.readLine();
return rubyEval(%data);
}
function rubyGetValue(%value, %length)
{
$temp = "";
$temp = rubyEval(%value);
return $temp;
}
function rubyEval(%expression)
{
%connection = new TCPObject(LIT2Client) { connected = false; };
%connection.connect("127.0.0.1:2000");
%expression = %expression @ "<END>";
%connection.send(%expression);
%connection.disconnect();
%received = false;
%response = "";
%countedSeconds = 0;
%currentSeconds = formatTimeString("ss");
while (!%received)
{
%newSeconds = formatTimeString("ss");
if (%newSeconds != %currentSeconds)
{
%countedSeconds++;
%currentSeconds = %newSeconds;
}
if (%countedSeconds >= $LIT2::WaitTime)
return "<TIMEOUT>";
%handle = new FileObject();
%handle.openForRead("lit2.txt");
%data = %handle.readLine();
%ending = strStr(%data, "<END>");
if (%ending > -1)
{
%response = getSubStr(%data, 0, %ending);
%received = true;
}
%handle.close();
%handle.delete();
}
%handle = new FileObject();
%handle.openForWrite("lit2.txt");
%handle.writeLine("<EMPTY>");
%handle.close();
%handle.delete();
return %response;
}
function LIT2Client::onLine(%this, %line)
{
if (%line !$= "")
%this.last = %line;
}
function LIT2Client::onConnect(%this)
{
}
function LIT2Client::onDisconnect(%this)
{
%this.delete();
}
function LIT2Client::onConnectFailed(%this)
{
error("LIT2 Connection Failed---");
}