-> now returns function name.

This commit is contained in:
gnembon committed 2019-10-24 00:20:29 -03:00
1 parent 7f941e02f5
commit 835f63755d
3 files changed
+10 -6

No files matched your search

@@ -71,7 +71,8 @@ public class ScriptCommand
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
{ {
LiteralArgumentBuilder<ServerCommandSource> b = literal("globals"). LiteralArgumentBuilder<ServerCommandSource> b = literal("globals").
executes(ScriptCommand::listGlobals); executes(context -> listGlobals(context, false)).
then(literal("all").executes(context -> listGlobals(context, true)));
LiteralArgumentBuilder<ServerCommandSource> o = literal("stop"). LiteralArgumentBuilder<ServerCommandSource> o = literal("stop").
executes( (cc) -> { CarpetServer.scriptServer.stopAll = true; return 1;}); executes( (cc) -> { CarpetServer.scriptServer.stopAll = true; return 1;});
LiteralArgumentBuilder<ServerCommandSource> u = literal("resume"). LiteralArgumentBuilder<ServerCommandSource> u = literal("resume").
@@ -308,13 +309,13 @@ public class ScriptCommand
} }
return 1; return 1;
} }
private static int listGlobals(CommandContext<ServerCommandSource> context) private static int listGlobals(CommandContext<ServerCommandSource> context, boolean all)
{ {
ScriptHost host = getHost(context); ScriptHost host = getHost(context);
ServerCommandSource source = context.getSource(); ServerCommandSource source = context.getSource();
Messenger.m(source, "lb Stored functions"+((host == CarpetServer.scriptServer.globalHost)?":":" in "+host.getName()+":")); Messenger.m(source, "lb Stored functions"+((host == CarpetServer.scriptServer.globalHost)?":":" in "+host.getName()+":"));
for (String fname : host.getAvailableFunctions()) for (String fname : host.getAvailableFunctions(all))
{ {
Expression expr = host.getExpressionForFunction(fname); Expression expr = host.getExpressionForFunction(fname);
Tokenizer.Token tok = host.getTokenForFunction(fname); Tokenizer.Token tok = host.getTokenForFunction(fname);
+4 -1
View File
@@ -978,17 +978,20 @@ public class Expression implements Cloneable
addLazyBinaryOperatorWithDelegation("->", precedence.get("def->"), false, (c, type, e, t, lv1, lv2) -> addLazyBinaryOperatorWithDelegation("->", precedence.get("def->"), false, (c, type, e, t, lv1, lv2) ->
{ {
Value v1 = lv1.evalValue(c, Context.SIGNATURE); Value v1 = lv1.evalValue(c, Context.SIGNATURE);
String result;
if (v1 instanceof FunctionSignatureValue) if (v1 instanceof FunctionSignatureValue)
{ {
FunctionSignatureValue sign = (FunctionSignatureValue) v1; FunctionSignatureValue sign = (FunctionSignatureValue) v1;
addContextFunction(c, sign.getName(), e, t, sign.getArgs(), sign.getGlobals(), lv2); addContextFunction(c, sign.getName(), e, t, sign.getArgs(), sign.getGlobals(), lv2);
result = sign.getName();
} }
else else
{ {
v1.assertAssignable(); v1.assertAssignable();
c.setVariable(v1.getVariable(), lv2); c.setVariable(v1.getVariable(), lv2);
result = v1.getVariable();
} }
return (cc, tt) -> new StringValue("OK"); return (cc, tt) -> new StringValue(result);
}); });
addFunction("exit", (lv) -> { throw new ExitStatement(lv.size()==0?Value.NULL:lv.get(0)); }); addFunction("exit", (lv) -> { throw new ExitStatement(lv.size()==0?Value.NULL:lv.get(0)); });
+2 -2
View File
@@ -108,9 +108,9 @@ public class ScriptHost
{ {
return globalFunctions.keySet().stream().filter((str) -> !str.startsWith("_")).collect(Collectors.toList()); return globalFunctions.keySet().stream().filter((str) -> !str.startsWith("_")).collect(Collectors.toList());
} }
public List<String> getAvailableFunctions() public List<String> getAvailableFunctions(boolean all)
{ {
return globalFunctions.keySet().stream().filter((str) -> !str.startsWith("__")).collect(Collectors.toList()); return globalFunctions.keySet().stream().filter((str) -> all || !str.startsWith("__")).collect(Collectors.toList());
} }
public String call(ServerCommandSource source, String call, List<Integer> coords, String arg) public String call(ServerCommandSource source, String call, List<Integer> coords, String arg)