-> now returns function name.
This commit is contained in:
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)
|
||||
{
|
||||
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").
|
||||
executes( (cc) -> { CarpetServer.scriptServer.stopAll = true; return 1;});
|
||||
LiteralArgumentBuilder<ServerCommandSource> u = literal("resume").
|
||||
@@ -308,13 +309,13 @@ public class ScriptCommand
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
private static int listGlobals(CommandContext<ServerCommandSource> context)
|
||||
private static int listGlobals(CommandContext<ServerCommandSource> context, boolean all)
|
||||
{
|
||||
ScriptHost host = getHost(context);
|
||||
ServerCommandSource source = context.getSource();
|
||||
|
||||
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);
|
||||
Tokenizer.Token tok = host.getTokenForFunction(fname);
|
||||
|
||||
@@ -978,17 +978,20 @@ public class Expression implements Cloneable
|
||||
addLazyBinaryOperatorWithDelegation("->", precedence.get("def->"), false, (c, type, e, t, lv1, lv2) ->
|
||||
{
|
||||
Value v1 = lv1.evalValue(c, Context.SIGNATURE);
|
||||
String result;
|
||||
if (v1 instanceof FunctionSignatureValue)
|
||||
{
|
||||
FunctionSignatureValue sign = (FunctionSignatureValue) v1;
|
||||
addContextFunction(c, sign.getName(), e, t, sign.getArgs(), sign.getGlobals(), lv2);
|
||||
result = sign.getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
v1.assertAssignable();
|
||||
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)); });
|
||||
|
||||
@@ -108,9 +108,9 @@ public class ScriptHost
|
||||
{
|
||||
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)
|
||||
|
||||
Reference in new issue
Block a user