Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xor and Euler #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/org/meteordev/starscript/StandardLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class StandardLib {
public static void init(Starscript ss) {
// Variables
ss.set("PI", Math.PI);
ss.set("EULER", Math.E);
ss.set("time", () -> Value.string(timeFormat.format(new Date())));
ss.set("date", () -> Value.string(dateFormat.format(new Date())));

Expand All @@ -27,6 +28,7 @@ public static void init(Starscript ss) {
ss.set("ceil", StandardLib::ceil);
ss.set("abs", StandardLib::abs);
ss.set("random", StandardLib::random);
ss.set("xor", StandardLib::xor);

// Strings
ss.set("string", StandardLib::string);
Expand Down Expand Up @@ -106,6 +108,22 @@ else if (argCount == 2) {
return Value.null_();
}

public static Value xor(Starscript ss, int argCount) {
if (argCount != 2) ss.error("xor() requires 2 argument, got %d.", argCount);

double a = ss.popNumber("Second argument to xor() needs to be a number.");
double b = ss.popNumber("First argument to xor() needs to be a number.");

long long1 = (long) a;
long long2 = (long) b;

if (a != long1 || b != long2) {
ss.error("Xor expects only non-decimal values");
}

return Value.number(long1 ^ long2);
}

// Strings

private static Value string(Starscript ss, int argCount) {
Expand Down