forked from fadookie/particleman
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from FxMorin/molang/basic-string-support
Molang/basic string support
- Loading branch information
Showing
16 changed files
with
319 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/eliotlash/molang/functions/strings/Length.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.eliotlash.molang.functions.strings; | ||
|
||
import com.eliotlash.molang.ast.Expr; | ||
import com.eliotlash.molang.functions.Function; | ||
import com.eliotlash.molang.variables.ExecutionContext; | ||
|
||
public class Length extends Function { | ||
public Length(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public double _evaluate(Expr[] arguments, ExecutionContext ctx) { | ||
return ctx.getEvaluator().evaluateString(arguments[0]).length(); | ||
} | ||
|
||
@Override | ||
public int getRequiredArguments() { | ||
return 1; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/eliotlash/molang/functions/strings/Print.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.eliotlash.molang.functions.strings; | ||
|
||
import com.eliotlash.molang.ast.Expr; | ||
import com.eliotlash.molang.functions.Function; | ||
import com.eliotlash.molang.variables.ExecutionContext; | ||
|
||
public class Print extends Function { | ||
public Print(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public double _evaluate(Expr[] arguments, ExecutionContext ctx) { | ||
if (arguments[0] instanceof Expr.Str) { | ||
System.out.println(ctx.getEvaluator().evaluateString(arguments[0])); | ||
} else { | ||
System.out.println(this.evaluateArgument(arguments, ctx, 0)); | ||
} | ||
return 1.0; | ||
} | ||
|
||
@Override | ||
public int getRequiredArguments() { | ||
return 1; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/eliotlash/molang/functions/strings/StrEquals.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.eliotlash.molang.functions.strings; | ||
|
||
import com.eliotlash.molang.ast.Expr; | ||
import com.eliotlash.molang.functions.Function; | ||
import com.eliotlash.molang.utils.MolangUtils; | ||
import com.eliotlash.molang.variables.ExecutionContext; | ||
|
||
public class StrEquals extends Function { | ||
public StrEquals(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public double _evaluate(Expr[] arguments, ExecutionContext ctx) { | ||
final String first = ctx.getEvaluator().evaluateString(arguments[0]); | ||
final String second = ctx.getEvaluator().evaluateString(arguments[1]); | ||
return MolangUtils.booleanToFloat(first.equals(second)); | ||
} | ||
|
||
@Override | ||
public int getRequiredArguments() { | ||
return 2; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/eliotlash/molang/functions/strings/StrEqualsIgnoreCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.eliotlash.molang.functions.strings; | ||
|
||
import com.eliotlash.molang.ast.Expr; | ||
import com.eliotlash.molang.functions.Function; | ||
import com.eliotlash.molang.utils.MolangUtils; | ||
import com.eliotlash.molang.variables.ExecutionContext; | ||
|
||
public class StrEqualsIgnoreCase extends Function { | ||
public StrEqualsIgnoreCase(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public double _evaluate(Expr[] arguments, ExecutionContext ctx) { | ||
final String first = ctx.getEvaluator().evaluateString(arguments[0]); | ||
final String second = ctx.getEvaluator().evaluateString(arguments[1]); | ||
return MolangUtils.booleanToFloat(first.equalsIgnoreCase(second)); | ||
} | ||
|
||
@Override | ||
public int getRequiredArguments() { | ||
return 2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.