Copyright | © 2007–2012 Gracjan Polak 2012–2016 Ömer Sinan Ağacan 2017-2020 Albert Krewinkel |
---|---|
License | MIT |
Maintainer | Albert Krewinkel <tarleb+hslua@zeitkraut.de> |
Stability | beta |
Portability | non-portable (depends on GHC) |
Safe Haskell | None |
Language | Haskell2010 |
HsLua utility functions.
Synopsis
- getglobal' :: String -> Lua ()
- setglobal' :: String -> Lua ()
- run :: Lua a -> IO a
- run' :: ErrorConversion -> Lua a -> IO a
- runEither :: Exception e => Lua a -> IO (Either e a)
- raiseError :: Pushable a => a -> Lua NumResults
- newtype Optional a = Optional {
- fromOptional :: Maybe a
- runWith :: State -> Lua a -> IO a
- peekEither :: Peekable a => StackIndex -> Lua (Either String a)
- peekRead :: Read a => StackIndex -> Lua a
- popValue :: Peekable a => Lua a
Documentation
getglobal' :: String -> Lua () Source #
Like getglobal
, but knows about packages and nested tables. E.g.
getglobal' "math.sin"
will return the function sin
in package math
.
setglobal' :: String -> Lua () Source #
Like setglobal
, but knows about packages and nested tables. E.g.
pushstring "0.9.4" setglobal' "mypackage.version"
All tables and fields, except for the last field, must exist.
Run Lua computation using the default HsLua state as starting point. Exceptions are masked, thus avoiding some issues when using multiple threads. All exceptions are passed through; error handling is the responsibility of the caller.
run' :: ErrorConversion -> Lua a -> IO a Source #
Run Lua computation using the default HsLua state as starting point.
Conversion from Lua errors to Haskell exceptions can be controlled through
.ErrorConversion
runEither :: Exception e => Lua a -> IO (Either e a) Source #
Run the given Lua computation; exceptions raised in haskell code are caught, but other exceptions (user exceptions raised in haskell, unchecked type errors, etc.) are passed through.
raiseError :: Pushable a => a -> Lua NumResults Source #
Raise a Lua error, using the given value as the error object.
Newtype wrapper intended to be used for optional Lua values. Nesting this type is strongly discouraged as missing values on inner levels are indistinguishable from missing values on an outer level; wrong values would be the likely result.
Optional | |
|
Default error handling
runWith :: State -> Lua a -> IO a Source #
Run Lua computation with the given Lua state and the default
error-to-exception converter (
). Exception
handling is left to the caller.throwTopStringAsException
getting values
peekEither :: Peekable a => StackIndex -> Lua (Either String a) Source #
Try to convert the value at the given stack index to a Haskell value.
Returns Left
with an error message on failure.
WARNING: this is not save to use with custom error handling!