mirror of
https://git.ragorasplace.com/Ragora/Old_LIT2.git
synced 2026-03-24 18:19:06 +00:00
96 lines
1.9 KiB
C#
96 lines
1.9 KiB
C#
|
|
// 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---");
|
||
|
|
}
|
||
|
|
|