cleanup undef
This commit is contained in:
1 parent
24c1ee8d3d
commit
6413c17657
5 files changed
+62
-24
No files matched your search
@@ -479,6 +479,7 @@ public class CarpetEventServer
|
||||
return Event.byName.get(event).handler.addEventCallDirect(host, function);
|
||||
}
|
||||
|
||||
|
||||
public boolean removeEvent(String event, String funName)
|
||||
{
|
||||
|
||||
@@ -489,6 +490,11 @@ public class CarpetEventServer
|
||||
return true;
|
||||
}
|
||||
|
||||
public void removeEventDirectly(String event, ScriptHost host, String funName)
|
||||
{
|
||||
Event.byName.get(event).handler.removeEventCall(host.getName(), funName);
|
||||
}
|
||||
|
||||
public void removeAllHostEvents(String hostName)
|
||||
{
|
||||
Event.byName.values().forEach((e) -> e.handler.removeAllCalls(hostName));
|
||||
|
||||
@@ -61,6 +61,20 @@ public class CarpetScriptHost extends ScriptHost
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delFunction(String funName)
|
||||
{
|
||||
super.delFunction(funName);
|
||||
// mcarpet
|
||||
if (funName.startsWith("__on_"))
|
||||
{
|
||||
// this is nasty, we have the host and function, yet we add it via names, but hey - works for now
|
||||
String event = funName.replaceFirst("__on_","");
|
||||
if (CarpetEventServer.Event.byName.containsKey(event))
|
||||
scriptServer.events.removeEventDirectly(event, this, funName);
|
||||
}
|
||||
}
|
||||
|
||||
public CarpetScriptHost retrieveForExecution(ServerCommandSource source)
|
||||
{
|
||||
if (!perUser)
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Context
|
||||
static final int LOCALIZATION = 8;
|
||||
static final int LVALUE = 9;
|
||||
|
||||
private Map<String, LazyValue> variables = new HashMap<>();
|
||||
public Map<String, LazyValue> variables = new HashMap<>();
|
||||
|
||||
protected ScriptHost host;
|
||||
|
||||
@@ -56,20 +56,6 @@ public class Context
|
||||
|
||||
void delVariable(String variable)
|
||||
{
|
||||
if (variable.startsWith("global_"))
|
||||
{
|
||||
host.globalVariables.remove(variable);
|
||||
return;
|
||||
}
|
||||
variables.remove(variable);
|
||||
}
|
||||
void clearAll(String variable)
|
||||
{
|
||||
if (variable.startsWith("global_"))
|
||||
{
|
||||
host.globalVariables.remove(variable);
|
||||
return;
|
||||
}
|
||||
variables.remove(variable);
|
||||
}
|
||||
|
||||
|
||||
@@ -2864,27 +2864,49 @@ public class Expression implements Cloneable
|
||||
|
||||
addLazyFunction("undef", 1, (c, t, lv) ->
|
||||
{
|
||||
String varname = lv.get(0).evalValue(c).getString();
|
||||
if (varname.startsWith("_"))
|
||||
throw new InternalExpressionException("Cannot replace local built-in variables, i.e. those that start with '_'");
|
||||
if (varname.endsWith("*"))
|
||||
Value remove = lv.get(0).evalValue(c);
|
||||
if (remove instanceof FunctionValue)
|
||||
{
|
||||
c.host.delFunction(remove.getString());
|
||||
return (cc, tt) -> Value.NULL;
|
||||
}
|
||||
String varname = remove.getString();
|
||||
boolean isPrefix = varname.endsWith("*");
|
||||
if (isPrefix)
|
||||
varname = varname.replaceAll("\\*+$", "");
|
||||
if (isPrefix)
|
||||
{
|
||||
for (String key: c.host.globalFunctions.keySet())
|
||||
{
|
||||
if (key.startsWith(varname)) c.host.globalFunctions.remove(key);
|
||||
if (key.startsWith(varname)) c.host.delFunction(key);
|
||||
}
|
||||
for (String key: c.host.globalVariables.keySet())
|
||||
if (varname.startsWith("global_"))
|
||||
{
|
||||
if (key.startsWith(varname)) c.host.globalVariables.remove(key);
|
||||
for (String key : c.host.globalVariables.keySet())
|
||||
{
|
||||
if (key.startsWith(varname)) c.host.delGlobalVariable(key);
|
||||
}
|
||||
}
|
||||
if (!varname.startsWith("_"))
|
||||
{
|
||||
for (String key : c.variables.keySet())
|
||||
{
|
||||
if (key.startsWith(varname)) c.delVariable(key);
|
||||
}
|
||||
}
|
||||
c.clearAll(varname);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.host.globalFunctions.remove(varname);
|
||||
c.host.delFunction(varname);
|
||||
if (varname.startsWith("global_"))
|
||||
{
|
||||
c.host.delGlobalVariable(varname);
|
||||
}
|
||||
if (!varname.startsWith("_"))
|
||||
{
|
||||
c.delVariable(varname);
|
||||
}
|
||||
}
|
||||
return (cc, tt) -> Value.NULL;
|
||||
});
|
||||
|
||||
|
||||
@@ -46,6 +46,16 @@ public class ScriptHost
|
||||
globalFunctions.put(funName, function);
|
||||
}
|
||||
|
||||
public void delFunction(String funName)
|
||||
{
|
||||
globalFunctions.remove(funName);
|
||||
}
|
||||
|
||||
public void delGlobalVariable(String varName)
|
||||
{
|
||||
globalFunctions.remove(varName);
|
||||
}
|
||||
|
||||
public ScriptHost retrieveForExecution(String /*Nullable*/ user)
|
||||
{
|
||||
if (!perUser)
|
||||
|
||||
Reference in new issue
Block a user