more MSES crap

This commit is contained in:
Boblet 2026-06-26 12:54:35 +02:00
parent 85a15f1bbd
commit 24ed4224a8
2 changed files with 24 additions and 1 deletions

View File

@ -111,6 +111,17 @@ public class ParseMSES1 implements IParse {
return EnumStatementReturn.OK;
}
// runs the calculation from the buffer, allows string substitution, saves result to buffer
if(lower.equals("eval")) {
if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR;
String statement = substitute(ctx, ctx.readBuffer(), true);
try {
double result = Calculator.evaluateExpression(statement);
ctx.writeBuffer("" + result);
} catch(Throwable ex) { return EnumStatementReturn.PARAMETER_ERROR; }
return EnumStatementReturn.OK;
}
// runs the calculation, allows string substitution, rounds, saves result to buffer,
if(lower.startsWith("evalr ")) {
if(line.length() <= 6) return EnumStatementReturn.PARAMETER_ERROR;
@ -122,7 +133,7 @@ public class ParseMSES1 implements IParse {
return EnumStatementReturn.OK;
}
// runs the calculation from the buffer, allows string substitution, saves result to buffer
// runs the calculation from the buffer, allows string substitution, saves rounded result to buffer
if(lower.equals("evalr")) {
if(ctx.readBuffer().isEmpty()) return EnumStatementReturn.PARAMETER_ERROR;
String statement = substitute(ctx, ctx.readBuffer(), true);

View File

@ -3,6 +3,9 @@ package com.hbm.module;
import java.util.Locale;
import java.util.regex.Pattern;
import com.hbm.tileentity.network.RTTYSystem;
import com.hbm.tileentity.network.RTTYSystem.RTTYChannel;
/**
* MSES1-FEIS: Machine Script, Equestrian Standard - First Extended Instruction Set (v1.1)
*
@ -10,6 +13,7 @@ import java.util.regex.Pattern;
* * Support for splitter chars, splitting and split count
* * Support for the stack, a secondary buffer that can push, pop and peek
* * Support for getting string length and substring using first and last
* * Support for listening only to recent RoR signals using poll
*
* @author hbm
*/
@ -108,6 +112,14 @@ public class ParseMSES1Ext1 extends ParseMSES1 {
} catch(Exception x) { return EnumStatementReturn.PARAMETER_ERROR; }
}
// listens to an RoR signal using the supplied channel name and saves it to the buffer
if(lower.startsWith("poll ")) {
if(line.length() <= 5) return EnumStatementReturn.PARAMETER_ERROR;
RTTYChannel chan = RTTYSystem.listen(ctx.world, substitute(ctx, line.substring(5), false));
if(chan != null && chan.timeStamp >= ctx.world.getTotalWorldTime() - 1) ctx.writeBuffer(chan.signal + "");
return EnumStatementReturn.OK;
}
return super.eval(ctx, line);
}
}