mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 19:56:17 -04:00
catching error when creating lua state due to missing libraries in factory and logging it right there, to allow printing error to chat the first time, too; different name the lib is saved to the tmp folder to reduce the chance of collisions; explicit message for windows users reminding them to install the vc2012 runtimes on library load errors
This commit is contained in:
parent
fb6f0a8866
commit
55524c4a78
@ -5,6 +5,7 @@ import com.naef.jnlua.{LuaState, NativeSupport}
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.nio.channels.Channels
|
import java.nio.channels.Channels
|
||||||
|
import java.util.logging.Level
|
||||||
import li.cil.oc.server.component.Computer
|
import li.cil.oc.server.component.Computer
|
||||||
import li.cil.oc.util.ExtendedLuaState._
|
import li.cil.oc.util.ExtendedLuaState._
|
||||||
import li.cil.oc.{OpenComputers, Settings}
|
import li.cil.oc.{OpenComputers, Settings}
|
||||||
@ -27,6 +28,8 @@ object LuaStateFactory {
|
|||||||
/** Set to true in initialization code below if available. */
|
/** Set to true in initialization code below if available. */
|
||||||
private var haveNativeLibrary = false
|
private var haveNativeLibrary = false
|
||||||
|
|
||||||
|
private var isWindows = false
|
||||||
|
|
||||||
private var _is64Bit = false
|
private var _is64Bit = false
|
||||||
|
|
||||||
def is64Bit = _is64Bit
|
def is64Bit = _is64Bit
|
||||||
@ -76,6 +79,7 @@ object LuaStateFactory {
|
|||||||
break()
|
break()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
isWindows = extension == ".dll"
|
||||||
val libPath = "/assets/" + Settings.resourceDomain + "/lib/"
|
val libPath = "/assets/" + Settings.resourceDomain + "/lib/"
|
||||||
|
|
||||||
val tmpPath = {
|
val tmpPath = {
|
||||||
@ -92,7 +96,7 @@ object LuaStateFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Found file with proper extension. Create a temporary file.
|
// Found file with proper extension. Create a temporary file.
|
||||||
val file = new File(tmpPath + library)
|
val file = new File(tmpPath + "OpenComputersMod-" + library)
|
||||||
// Try to delete an old instance of the library, in case we have an update
|
// Try to delete an old instance of the library, in case we have an update
|
||||||
// and deleteOnExit fails (which it regularly does on Windows it seems).
|
// and deleteOnExit fails (which it regularly does on Windows it seems).
|
||||||
try {
|
try {
|
||||||
@ -145,6 +149,7 @@ object LuaStateFactory {
|
|||||||
def createState(): Option[LuaState] = {
|
def createState(): Option[LuaState] = {
|
||||||
if (!haveNativeLibrary) return None
|
if (!haveNativeLibrary) return None
|
||||||
|
|
||||||
|
try {
|
||||||
val state = new LuaState(Int.MaxValue)
|
val state = new LuaState(Int.MaxValue)
|
||||||
try {
|
try {
|
||||||
// Load all libraries.
|
// Load all libraries.
|
||||||
@ -278,12 +283,26 @@ object LuaStateFactory {
|
|||||||
|
|
||||||
state.setGlobal("unicode")
|
state.setGlobal("unicode")
|
||||||
|
|
||||||
Some(state)
|
return Some(state)
|
||||||
} catch {
|
}
|
||||||
case ex: Throwable =>
|
catch {
|
||||||
ex.printStackTrace()
|
case t: Throwable =>
|
||||||
|
OpenComputers.log.log(Level.WARNING, "Failed creating Lua state.", t)
|
||||||
state.close()
|
state.close()
|
||||||
return None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch {
|
||||||
|
case _: UnsatisfiedLinkError =>
|
||||||
|
OpenComputers.log.severe("Failed loading the native libraries.")
|
||||||
|
if (isWindows) {
|
||||||
|
OpenComputers.log.severe(
|
||||||
|
"Please ensure you have the Visual C++ 2012 Runtime installed " +
|
||||||
|
"(when on 64 Bit, both the 32 bit and 64 bit version of the " +
|
||||||
|
"runtime).")
|
||||||
|
}
|
||||||
|
case t: Throwable =>
|
||||||
|
OpenComputers.log.log(Level.WARNING, "Failed creating Lua state.", t)
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user