renamed main

This commit is contained in:
gnembon committed 2020-01-08 23:47:54 -04:00
1 parent 4f65be946c
commit f674936199
5 files changed
+20 -20

No files matched your search

@@ -289,7 +289,7 @@ public class ScriptCommand
private static Collection<String> suggestFunctionCalls(CommandContext<ServerCommandSource> c) private static Collection<String> suggestFunctionCalls(CommandContext<ServerCommandSource> c)
{ {
CarpetScriptHost host = getHost(c); CarpetScriptHost host = getHost(c);
return host.globaFunctionNames(host.myCode, s -> !s.startsWith("_")).sorted().collect(Collectors.toList()); return host.globaFunctionNames(host.main, s -> !s.startsWith("_")).sorted().collect(Collectors.toList());
} }
private static int listEvents(ServerCommandSource source) private static int listEvents(ServerCommandSource source)
{ {
@@ -315,7 +315,7 @@ public class ScriptCommand
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()+":"));
host.globaFunctionNames(host.myCode, (str) -> all || !str.startsWith("__")).sorted().forEach( (s) -> { host.globaFunctionNames(host.main, (str) -> all || !str.startsWith("__")).sorted().forEach( (s) -> {
FunctionValue fun = host.getFunction(s); FunctionValue fun = host.getFunction(s);
Expression expr = fun.getExpression(); Expression expr = fun.getExpression();
Tokenizer.Token tok = fun.getToken(); Tokenizer.Token tok = fun.getToken();
@@ -330,7 +330,7 @@ public class ScriptCommand
//Messenger.m(source, "w "+code); //Messenger.m(source, "w "+code);
Messenger.m(source, "w "); Messenger.m(source, "w ");
Messenger.m(source, "lb Global variables"+((host == CarpetServer.scriptServer.globalHost)?":":" in "+host.getName()+":")); Messenger.m(source, "lb Global variables"+((host == CarpetServer.scriptServer.globalHost)?":":" in "+host.getName()+":"));
host.globaVariableNames(host.myCode, (s) -> s.startsWith("global_")).sorted().forEach( (s) -> { host.globaVariableNames(host.main, (s) -> s.startsWith("global_")).sorted().forEach( (s) -> {
Messenger.m(source, "wb "+s+": ", "w "+ host.getGlobalVariable(s).evalValue(null).getPrettyString()); Messenger.m(source, "wb "+s+": ", "w "+ host.getGlobalVariable(s).evalValue(null).getPrettyString());
}); });
return 1; return 1;
@@ -399,7 +399,7 @@ public class ScriptCommand
ServerCommandSource source = context.getSource(); ServerCommandSource source = context.getSource();
CarpetScriptHost host = getHost(context); CarpetScriptHost host = getHost(context);
handleCall(source, host, () -> { handleCall(source, host, () -> {
CarpetExpression ex = new CarpetExpression(host.myCode, expr, source, new BlockPos(0, 0, 0)); CarpetExpression ex = new CarpetExpression(host.main, expr, source, new BlockPos(0, 0, 0));
return ex.scriptRunCommand(host, new BlockPos(source.getPosition())); return ex.scriptRunCommand(host, new BlockPos(source.getPosition()));
}); });
return 1; return 1;
@@ -410,7 +410,7 @@ public class ScriptCommand
ServerCommandSource source = context.getSource(); ServerCommandSource source = context.getSource();
CarpetScriptHost host = getHost(context); CarpetScriptHost host = getHost(context);
MutableIntBoundingBox area = new MutableIntBoundingBox(a, b); MutableIntBoundingBox area = new MutableIntBoundingBox(a, b);
CarpetExpression cexpr = new CarpetExpression(host.myCode, expr, source, origin); CarpetExpression cexpr = new CarpetExpression(host.main, expr, source, origin);
int int_1 = area.getBlockCountX() * area.getBlockCountY() * area.getBlockCountZ(); int int_1 = area.getBlockCountX() * area.getBlockCountY() * area.getBlockCountZ();
if (int_1 > CarpetSettings.fillLimit) if (int_1 > CarpetSettings.fillLimit)
@@ -461,7 +461,7 @@ public class ScriptCommand
ServerCommandSource source = context.getSource(); ServerCommandSource source = context.getSource();
CarpetScriptHost host = getHost(context); CarpetScriptHost host = getHost(context);
MutableIntBoundingBox area = new MutableIntBoundingBox(a, b); MutableIntBoundingBox area = new MutableIntBoundingBox(a, b);
CarpetExpression cexpr = new CarpetExpression(host.myCode, expr, source, origin); CarpetExpression cexpr = new CarpetExpression(host.main, expr, source, origin);
int int_1 = area.getBlockCountX() * area.getBlockCountY() * area.getBlockCountZ(); int int_1 = area.getBlockCountX() * area.getBlockCountY() * area.getBlockCountZ();
if (int_1 > CarpetSettings.fillLimit) if (int_1 > CarpetSettings.fillLimit)
{ {
@@ -60,7 +60,7 @@ public class CarpetScriptHost extends ScriptHost
return null; return null;
} }
host.setChatErrorSnooper(source); host.setChatErrorSnooper(source);
CarpetExpression ex = new CarpetExpression(host.myCode, code, source, new BlockPos(0, 0, 0)); CarpetExpression ex = new CarpetExpression(host.main, code, source, new BlockPos(0, 0, 0));
ex.getExpr().asATextSource(); ex.getExpr().asATextSource();
ex.scriptRunCommand(host, new BlockPos(source.getPosition())); ex.scriptRunCommand(host, new BlockPos(source.getPosition()));
} }
@@ -78,7 +78,7 @@ public class CarpetScriptHost extends ScriptHost
@Override @Override
protected ScriptHost duplicate() protected ScriptHost duplicate()
{ {
return new CarpetScriptHost(scriptServer, myCode, false, this); return new CarpetScriptHost(scriptServer, main, false, this);
} }
@Override @Override
@@ -312,19 +312,19 @@ public class CarpetScriptHost extends ScriptHost
private void dumpState() private void dumpState()
{ {
myCode.saveData(null, globalState); main.saveData(null, globalState);
} }
private Tag loadState() private Tag loadState()
{ {
return myCode.getData(null); return main.getData(null);
} }
public Tag getGlobalState(String file) public Tag getGlobalState(String file)
{ {
if (getName() == null ) return null; if (getName() == null ) return null;
if (file != null) if (file != null)
return myCode.getData(file); return main.getData(file);
if (parent == null) if (parent == null)
return globalState; return globalState;
return ((CarpetScriptHost)parent).globalState; return ((CarpetScriptHost)parent).globalState;
@@ -336,7 +336,7 @@ public class CarpetScriptHost extends ScriptHost
if (file!= null) if (file!= null)
{ {
myCode.saveData(file, tag); main.saveData(file, tag);
return; return;
} }
@@ -217,7 +217,7 @@ public class CarpetScriptServer
return 1; return 1;
}); });
for (String function : host.globaFunctionNames(host.myCode, s -> !s.startsWith("_")).sorted().collect(Collectors.toList())) for (String function : host.globaFunctionNames(host.main, s -> !s.startsWith("_")).sorted().collect(Collectors.toList()))
{ {
command = command. command = command.
then(literal(function). then(literal(function).
@@ -48,8 +48,8 @@ public class ExpressionInspector
// not that useful in commandline, more so in external scripts, so skipping here // not that useful in commandline, more so in external scripts, so skipping here
//scarpetMatches.addAll(CarpetServer.scriptServer.events.eventHandlers.keySet().stream(). //scarpetMatches.addAll(CarpetServer.scriptServer.events.eventHandlers.keySet().stream().
// filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> "__"+s+"(").collect(Collectors.toList())); // filter(s -> s.startsWith(prefix) && s.length() <= maxLen).map(s -> "__"+s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(host.globaFunctionNames(host.myCode, s -> s.startsWith(prefix)).map(s -> s+"(").collect(Collectors.toList())); scarpetMatches.addAll(host.globaFunctionNames(host.main, s -> s.startsWith(prefix)).map(s -> s+"(").collect(Collectors.toList()));
scarpetMatches.addAll(host.globaVariableNames(host.myCode, s -> s.startsWith(prefix)).collect(Collectors.toList())); scarpetMatches.addAll(host.globaVariableNames(host.main, s -> s.startsWith(prefix)).collect(Collectors.toList()));
return scarpetMatches; return scarpetMatches;
} }
} }
+5 -5
View File
@@ -64,16 +64,16 @@ public abstract class ScriptHost
protected ScriptHost parent; protected ScriptHost parent;
protected boolean perUser; protected boolean perUser;
public String getName() {return myCode==null?null:myCode.getName();} public String getName() {return main ==null?null: main.getName();}
public final Module myCode; public final Module main;
public Fluff.TriFunction<Expression, Tokenizer.Token, String, List<String>> errorSnooper = null; public Fluff.TriFunction<Expression, Tokenizer.Token, String, List<String>> errorSnooper = null;
protected ScriptHost(Module code, boolean perUser, ScriptHost parent) protected ScriptHost(Module code, boolean perUser, ScriptHost parent)
{ {
this.parent = parent; this.parent = parent;
this.myCode = code; this.main = code;
this.perUser = perUser; this.perUser = perUser;
ModuleData moduleData = new ModuleData(code); ModuleData moduleData = new ModuleData(code);
initializeModuleGlobals(moduleData); initializeModuleGlobals(moduleData);
@@ -138,7 +138,7 @@ public abstract class ScriptHost
protected abstract void runModuleCode(Context c, Module module); // this should be shell out in the executor protected abstract void runModuleCode(Context c, Module module); // this should be shell out in the executor
public FunctionValue getFunction(String name) { return getFunction(myCode, name); } public FunctionValue getFunction(String name) { return getFunction(main, name); }
public FunctionValue getAssertFunction(Module module, String name) public FunctionValue getAssertFunction(Module module, String name)
{ {
FunctionValue ret = getFunction(module, name); FunctionValue ret = getFunction(module, name);
@@ -178,7 +178,7 @@ public abstract class ScriptHost
return null; return null;
} }
public LazyValue getGlobalVariable(String name) { return getGlobalVariable(myCode, name); } public LazyValue getGlobalVariable(String name) { return getGlobalVariable(main, name); }
public LazyValue getGlobalVariable(Module module, String name) public LazyValue getGlobalVariable(Module module, String name)
{ {
ModuleData local = moduleData.get(module); ModuleData local = moduleData.get(module);