Should avoid unexpected error if trying to tostring a method that's now filtered out.

Clearing out callback cache when a world is unloaded.
This commit is contained in:
Florian Nücke 2015-04-21 12:02:02 +02:00
parent 8a31eba5c3
commit ce552ff99d
4 changed files with 11 additions and 2 deletions

View File

@ -25,6 +25,7 @@ import li.cil.oc.common.tileentity.traits.power
import li.cil.oc.integration.Mods
import li.cil.oc.integration.util
import li.cil.oc.server.component.Keyboard
import li.cil.oc.server.machine.Callbacks
import li.cil.oc.server.machine.Machine
import li.cil.oc.server.{PacketSender => ServerPacketSender}
import li.cil.oc.util.ExtendedWorld._
@ -357,6 +358,8 @@ object EventHandler {
e.world.loadedEntityList.collect {
case host: MachineHost => host.machine.stop()
}
Callbacks.clear()
}
}

View File

@ -27,6 +27,12 @@ object Callbacks {
case _ => cache.getOrElseUpdate(host.getClass, dynamicAnalyze(host))
}
// Clear the cache; used when world is unloaded, mostly to allow reacting to
// stuff (aka configs) that may influence which @Callbacks are enabled.
def clear(): Unit = {
cache.clear()
}
def fromClass(environment: Class[_]) = staticAnalyze(environment)
private def dynamicAnalyze(host: Any) = {

View File

@ -83,7 +83,7 @@ class ComponentAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) {
withComponent(lua.checkString(1), component => {
val method = lua.checkString(2)
val methods = machine.methods(component.host)
owner.documentation(() => methods(method).doc)
owner.documentation(() => Option(methods.get(method)).map(_.doc).orNull)
})
})
lua.setField(-2, "doc")

View File

@ -71,7 +71,7 @@ class ComponentAPI(owner: LuaJLuaArchitecture) extends LuaJAPI(owner) {
withComponent(args.checkjstring(1), component => {
val method = args.checkjstring(2)
val methods = machine.methods(component.host)
owner.documentation(() => methods(method).doc)
owner.documentation(() => Option(methods.get(method)).map(_.doc).orNull)
})
})