|
@@ -2,7 +2,9 @@
|
|
|
|
|
|
module Main where
|
|
|
|
|
|
+import qualified Control.Applicative as App
|
|
|
import qualified Control.Exception as Exn
|
|
|
+import qualified Control.Monad as Monad
|
|
|
import qualified Foreign.Lua as Lua
|
|
|
|
|
|
data Config = Config
|
|
@@ -12,6 +14,16 @@ data Config = Config
|
|
|
}
|
|
|
deriving (Show)
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+errorConversion :: Lua.ErrorConversion
|
|
|
+errorConversion = Lua.ErrorConversion {Lua.errorToException, Lua.addContextToException, Lua.alternative, Lua.exceptionToError}
|
|
|
+ where
|
|
|
+ errorToException = Lua.throwTopMessageWithState
|
|
|
+ addContextToException _ x = x
|
|
|
+ alternative x y = x App.<|> y
|
|
|
+ exceptionToError = id
|
|
|
+
|
|
|
readConfig :: FilePath -> IO Config
|
|
|
readConfig configPath =
|
|
|
|
|
@@ -19,14 +31,18 @@ readConfig configPath =
|
|
|
|
|
|
|
|
|
|
|
|
- Lua.unsafeRunWith st $ do
|
|
|
+ Lua.runWithConverter errorConversion st $ do
|
|
|
|
|
|
|
|
|
|
|
|
Lua.openlibs
|
|
|
-
|
|
|
-
|
|
|
- _ <- Lua.loadfile configPath
|
|
|
+
|
|
|
+ res <- Lua.loadfile configPath
|
|
|
+
|
|
|
+
|
|
|
+ Monad.when
|
|
|
+ (res /= Lua.OK)
|
|
|
+ Lua.throwErrorAsException
|
|
|
|
|
|
|
|
|
Lua.call 0 0
|