mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-13 09:18:05 -04:00
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:
parent
8a31eba5c3
commit
ce552ff99d
@ -25,6 +25,7 @@ import li.cil.oc.common.tileentity.traits.power
|
|||||||
import li.cil.oc.integration.Mods
|
import li.cil.oc.integration.Mods
|
||||||
import li.cil.oc.integration.util
|
import li.cil.oc.integration.util
|
||||||
import li.cil.oc.server.component.Keyboard
|
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.machine.Machine
|
||||||
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
||||||
import li.cil.oc.util.ExtendedWorld._
|
import li.cil.oc.util.ExtendedWorld._
|
||||||
@ -357,6 +358,8 @@ object EventHandler {
|
|||||||
e.world.loadedEntityList.collect {
|
e.world.loadedEntityList.collect {
|
||||||
case host: MachineHost => host.machine.stop()
|
case host: MachineHost => host.machine.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Callbacks.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,12 @@ object Callbacks {
|
|||||||
case _ => cache.getOrElseUpdate(host.getClass, dynamicAnalyze(host))
|
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)
|
def fromClass(environment: Class[_]) = staticAnalyze(environment)
|
||||||
|
|
||||||
private def dynamicAnalyze(host: Any) = {
|
private def dynamicAnalyze(host: Any) = {
|
||||||
|
@ -83,7 +83,7 @@ class ComponentAPI(owner: NativeLuaArchitecture) extends NativeLuaAPI(owner) {
|
|||||||
withComponent(lua.checkString(1), component => {
|
withComponent(lua.checkString(1), component => {
|
||||||
val method = lua.checkString(2)
|
val method = lua.checkString(2)
|
||||||
val methods = machine.methods(component.host)
|
val methods = machine.methods(component.host)
|
||||||
owner.documentation(() => methods(method).doc)
|
owner.documentation(() => Option(methods.get(method)).map(_.doc).orNull)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
lua.setField(-2, "doc")
|
lua.setField(-2, "doc")
|
||||||
|
@ -71,7 +71,7 @@ class ComponentAPI(owner: LuaJLuaArchitecture) extends LuaJAPI(owner) {
|
|||||||
withComponent(args.checkjstring(1), component => {
|
withComponent(args.checkjstring(1), component => {
|
||||||
val method = args.checkjstring(2)
|
val method = args.checkjstring(2)
|
||||||
val methods = machine.methods(component.host)
|
val methods = machine.methods(component.host)
|
||||||
owner.documentation(() => methods(method).doc)
|
owner.documentation(() => Option(methods.get(method)).map(_.doc).orNull)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user