| Copyright | © 2007–2012 Gracjan Polak; © 2012–2016 Ömer Sinan Ağacan; © 2017-2024 Albert Krewinkel |
|---|---|
| License | MIT |
| Maintainer | Albert Krewinkel <tarleb@hslua.org> |
| Stability | beta |
| Portability | non-portable (depends on GHC) |
| Safe Haskell | None |
| Language | Haskell2010 |
HsLua
Description
Functions and utilities enabling the seamless integration of a Lua interpreter into a Haskell project.
This module combines and re-exports the functionality of the HsLua
framework. Basic access to the Lua API is provided by from
Hackage package lua.Core
Synopsis
- type Lua a = LuaE Exception a
- newtype LuaE e a = Lua {
- unLua :: ReaderT LuaEnvironment IO a
- data RelationalOperator
- newtype Integer = Integer Int64
- data Type
- concat :: LuaError e => NumArgs -> LuaE e ()
- compare :: LuaError e => StackIndex -> StackIndex -> RelationalOperator -> LuaE e Bool
- error :: LuaE e NumResults
- rotate :: StackIndex -> Int -> LuaE e ()
- newtype Number = Number Double
- newtype Exception = Exception {}
- insert :: StackIndex -> LuaE e ()
- liftIO :: MonadIO m => IO a -> m a
- close :: State -> IO ()
- gc :: GCControl -> LuaE e Int
- try :: Exception e => LuaE e a -> LuaE e (Either e a)
- copy :: StackIndex -> StackIndex -> LuaE e ()
- newtype State = State (Ptr ())
- pcall :: NumArgs -> NumResults -> Maybe StackIndex -> LuaE e Status
- next :: LuaError e => StackIndex -> LuaE e Bool
- type CFunction = FunPtr PreCFunction
- data Status
- load :: Reader -> Ptr () -> Name -> LuaE e Status
- refnil :: Int
- noref :: Int
- newtype NumResults = NumResults {}
- newtype NumArgs = NumArgs {
- fromNumArgs :: CInt
- newtype StackIndex = StackIndex {}
- type PreCFunction = State -> IO NumResults
- data Reference
- fromReference :: Reference -> CInt
- toReference :: CInt -> Reference
- nthTop :: CInt -> StackIndex
- nthBottom :: CInt -> StackIndex
- nth :: CInt -> StackIndex
- top :: StackIndex
- newtype Name = Name {}
- data GCControl
- type HaskellFunction e = LuaE e NumResults
- newtype LuaEnvironment = LuaEnvironment {
- luaEnvState :: State
- state :: LuaE e State
- runWith :: State -> LuaE e a -> IO a
- unsafeRunWith :: State -> LuaE e a -> IO a
- multret :: NumResults
- registryindex :: StackIndex
- newhsuserdatauv :: a -> Int -> LuaE e ()
- newudmetatable :: Name -> LuaE e Bool
- fromuserdata :: forall a e. StackIndex -> Name -> LuaE e (Maybe a)
- putuserdata :: StackIndex -> Name -> a -> LuaE e Bool
- getupvalue :: StackIndex -> Int -> LuaE e (Maybe Name)
- setupvalue :: StackIndex -> Int -> LuaE e (Maybe Name)
- class Exception e => LuaError e where
- popException :: LuaE e e
- pushException :: e -> LuaE e ()
- luaException :: String -> e
- failLua :: LuaError e => String -> LuaE e a
- throwErrorAsException :: LuaError e => LuaE e a
- throwTypeMismatchError :: LuaError e => ByteString -> StackIndex -> LuaE e a
- changeErrorType :: forall old new a. LuaE old a -> LuaE new a
- popErrorMessage :: State -> IO ByteString
- pushTypeMismatchError :: ByteString -> StackIndex -> LuaE e ()
- absindex :: StackIndex -> LuaE e StackIndex
- call :: LuaError e => NumArgs -> NumResults -> LuaE e ()
- checkstack :: Int -> LuaE e Bool
- createtable :: Int -> Int -> LuaE e ()
- equal :: LuaError e => StackIndex -> StackIndex -> LuaE e Bool
- getfield :: LuaError e => StackIndex -> Name -> LuaE e Type
- getglobal :: LuaError e => Name -> LuaE e Type
- getmetatable :: StackIndex -> LuaE e Bool
- gettable :: LuaError e => StackIndex -> LuaE e Type
- gettop :: LuaE e StackIndex
- getiuservalue :: StackIndex -> Int -> LuaE e Type
- isboolean :: StackIndex -> LuaE e Bool
- iscfunction :: StackIndex -> LuaE e Bool
- isfunction :: StackIndex -> LuaE e Bool
- isinteger :: StackIndex -> LuaE e Bool
- islightuserdata :: StackIndex -> LuaE e Bool
- isnil :: StackIndex -> LuaE e Bool
- isnone :: StackIndex -> LuaE e Bool
- isnoneornil :: StackIndex -> LuaE e Bool
- isnumber :: StackIndex -> LuaE e Bool
- isstring :: StackIndex -> LuaE e Bool
- istable :: StackIndex -> LuaE e Bool
- isthread :: StackIndex -> LuaE e Bool
- isuserdata :: StackIndex -> LuaE e Bool
- lessthan :: LuaError e => StackIndex -> StackIndex -> LuaE e Bool
- ltype :: StackIndex -> LuaE e Type
- newtable :: LuaE e ()
- newuserdatauv :: Int -> Int -> LuaE e (Ptr ())
- openlibs :: LuaE e ()
- openbase :: LuaError e => LuaE e ()
- opendebug :: LuaError e => LuaE e ()
- openio :: LuaError e => LuaE e ()
- openmath :: LuaError e => LuaE e ()
- openos :: LuaError e => LuaE e ()
- openpackage :: LuaError e => LuaE e ()
- openstring :: LuaError e => LuaE e ()
- opentable :: LuaError e => LuaE e ()
- pop :: Int -> LuaE e ()
- pushboolean :: Bool -> LuaE e ()
- pushcclosure :: CFunction -> NumArgs -> LuaE e ()
- pushcfunction :: CFunction -> LuaE e ()
- pushglobaltable :: LuaE e ()
- pushinteger :: Integer -> LuaE e ()
- pushlightuserdata :: Ptr a -> LuaE e ()
- pushnil :: LuaE e ()
- pushnumber :: Number -> LuaE e ()
- pushstring :: ByteString -> LuaE e ()
- pushthread :: LuaE e Bool
- pushvalue :: StackIndex -> LuaE e ()
- rawequal :: StackIndex -> StackIndex -> LuaE e Bool
- rawget :: LuaError e => StackIndex -> LuaE e Type
- rawgeti :: LuaError e => StackIndex -> Integer -> LuaE e Type
- rawlen :: StackIndex -> LuaE e Int
- rawset :: LuaError e => StackIndex -> LuaE e ()
- rawseti :: LuaError e => StackIndex -> Integer -> LuaE e ()
- register :: LuaError e => Name -> CFunction -> LuaE e ()
- remove :: StackIndex -> LuaE e ()
- replace :: StackIndex -> LuaE e ()
- setfield :: LuaError e => StackIndex -> Name -> LuaE e ()
- setglobal :: LuaError e => Name -> LuaE e ()
- setmetatable :: StackIndex -> LuaE e ()
- settable :: LuaError e => StackIndex -> LuaE e ()
- settop :: StackIndex -> LuaE e ()
- setiuservalue :: StackIndex -> Int -> LuaE e Bool
- setwarnf :: WarnFunction -> Ptr () -> LuaE e ()
- status :: LuaE e Status
- toboolean :: StackIndex -> LuaE e Bool
- tocfunction :: StackIndex -> LuaE e (Maybe CFunction)
- tointeger :: StackIndex -> LuaE e (Maybe Integer)
- tonumber :: StackIndex -> LuaE e (Maybe Number)
- topointer :: StackIndex -> LuaE e (Ptr ())
- tostring :: StackIndex -> LuaE e (Maybe ByteString)
- tothread :: StackIndex -> LuaE e (Maybe State)
- touserdata :: StackIndex -> LuaE e (Maybe (Ptr a))
- typename :: Type -> LuaE e ByteString
- upvalueindex :: StackIndex -> StackIndex
- pushPreCFunction :: PreCFunction -> LuaE e ()
- pushHaskellFunction :: LuaError e => HaskellFunction e -> LuaE e ()
- checkstack' :: LuaError e => Int -> String -> LuaE e ()
- dostring :: ByteString -> LuaE e Status
- dofile :: Maybe FilePath -> LuaE e Status
- getmetafield :: StackIndex -> Name -> LuaE e Type
- getmetatable' :: Name -> LuaE e Type
- getref :: LuaError e => StackIndex -> Reference -> LuaE e Type
- getsubtable :: LuaError e => StackIndex -> Name -> LuaE e Bool
- loadbuffer :: ByteString -> Name -> LuaE e Status
- loadfile :: Maybe FilePath -> LuaE e Status
- loadstring :: ByteString -> LuaE e Status
- newmetatable :: Name -> LuaE e Bool
- newstate :: IO State
- ref :: StackIndex -> LuaE e Reference
- requiref :: LuaError e => Name -> CFunction -> Bool -> LuaE e ()
- tostring' :: LuaError e => StackIndex -> LuaE e ByteString
- traceback :: State -> Maybe ByteString -> Int -> LuaE e ()
- unref :: StackIndex -> Reference -> LuaE e ()
- where' :: Int -> LuaE e ()
- loaded :: Name
- preload :: Name
- data GCManagedState
- run :: LuaE e a -> IO a
- runEither :: Exception e => LuaE e a -> IO (Either e a)
- newGCManagedState :: IO GCManagedState
- closeGCManagedState :: GCManagedState -> IO ()
- withGCManagedState :: GCManagedState -> LuaE e a -> IO a
- pcallTrace :: NumArgs -> NumResults -> LuaE e Status
- callTrace :: LuaError e => NumArgs -> NumResults -> LuaE e ()
- dofileTrace :: Maybe FilePath -> LuaE e Status
- dostringTrace :: ByteString -> LuaE e Status
- requirehs :: LuaError e => Name -> (Name -> LuaE e ()) -> LuaE e ()
- preloadhs :: LuaError e => Name -> LuaE e NumResults -> LuaE e ()
- setwarnf' :: LuaError e => (ByteString -> LuaE e ()) -> LuaE e ()
- module HsLua.Marshalling
- module HsLua.ObjectOrientation
- module HsLua.Packaging
- module HsLua.Class.Exposable
- module HsLua.Class.Invokable
- module HsLua.Class.Peekable
- class Pushable a where
- module HsLua.Aeson
- getglobal' :: LuaError e => Name -> LuaE e ()
- setglobal' :: LuaError e => Name -> LuaE e ()
- module HsLua.Class.Util
Core functionality
Constructors
| Lua | |
Fields
| |
Instances
data RelationalOperator #
Instances
| Show RelationalOperator | |
Defined in HsLua.Core.Types | |
| Eq RelationalOperator | |
Defined in HsLua.Core.Types Methods (==) :: RelationalOperator -> RelationalOperator -> Bool Source # (/=) :: RelationalOperator -> RelationalOperator -> Bool Source # | |
| Ord RelationalOperator | |
Defined in HsLua.Core.Types Methods compare :: RelationalOperator -> RelationalOperator -> Ordering Source # (<) :: RelationalOperator -> RelationalOperator -> Bool Source # (<=) :: RelationalOperator -> RelationalOperator -> Bool Source # (>) :: RelationalOperator -> RelationalOperator -> Bool Source # (>=) :: RelationalOperator -> RelationalOperator -> Bool Source # max :: RelationalOperator -> RelationalOperator -> RelationalOperator Source # min :: RelationalOperator -> RelationalOperator -> RelationalOperator Source # | |
Instances
| Bounded Integer | |
| Enum Integer | |
Defined in Lua.Types Methods succ :: Integer -> Integer Source # pred :: Integer -> Integer Source # toEnum :: Int -> Integer Source # fromEnum :: Integer -> Int Source # enumFrom :: Integer -> [Integer] Source # enumFromThen :: Integer -> Integer -> [Integer] Source # enumFromTo :: Integer -> Integer -> [Integer] Source # enumFromThenTo :: Integer -> Integer -> Integer -> [Integer] Source # | |
| Num Integer | |
Defined in Lua.Types | |
| Read Integer | |
| Integral Integer | |
Defined in Lua.Types Methods quot :: Integer -> Integer -> Integer Source # rem :: Integer -> Integer -> Integer Source # div :: Integer -> Integer -> Integer Source # mod :: Integer -> Integer -> Integer Source # quotRem :: Integer -> Integer -> (Integer, Integer) Source # | |
| Real Integer | |
| Show Integer | |
| Eq Integer | |
| Ord Integer | |
| Peekable Integer | |
| Pushable Integer | |
Constructors
| TypeNone | |
| TypeNil | |
| TypeBoolean | |
| TypeLightUserdata | |
| TypeNumber | |
| TypeString | |
| TypeTable | |
| TypeFunction | |
| TypeUserdata | |
| TypeThread |
compare :: LuaError e => StackIndex -> StackIndex -> RelationalOperator -> LuaE e Bool #
error :: LuaE e NumResults #
rotate :: StackIndex -> Int -> LuaE e () #
Instances
Constructors
| Exception | |
Fields | |
Instances
| Exception Exception | |
Defined in HsLua.Core.Error Methods toException :: Exception -> SomeException Source # fromException :: SomeException -> Maybe Exception Source # displayException :: Exception -> String Source # backtraceDesired :: Exception -> Bool Source # | |
| Show Exception | |
| Eq Exception | |
| LuaError Exception | |
Defined in HsLua.Core.Error Methods popException :: LuaE Exception Exception # pushException :: Exception -> LuaE Exception () # luaException :: String -> Exception # | |
insert :: StackIndex -> LuaE e () #
liftIO :: MonadIO m => IO a -> m a Source #
Lift a computation from the IO monad.
This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations
(i.e. IO is the base monad for the stack).
Example
import Control.Monad.Trans.State -- from the "transformers" library printState :: Show s => StateT s IO () printState = do state <- get liftIO $ print state
Had we omitted , we would have ended up with this error:liftIO
• Couldn't match type ‘IO’ with ‘StateT s IO’ Expected type: StateT s IO () Actual type: IO ()
The important part here is the mismatch between StateT s IO () and .IO ()
Luckily, we know of a function that takes an and returns an IO a(m a): ,
enabling us to run the program and see the expected results:liftIO
> evalStateT printState "hello" "hello" > evalStateT printState 3 3
copy :: StackIndex -> StackIndex -> LuaE e () #
pcall :: NumArgs -> NumResults -> Maybe StackIndex -> LuaE e Status #
type CFunction = FunPtr PreCFunction #
Instances
newtype NumResults #
Constructors
| NumResults | |
Fields | |
Instances
Constructors
| NumArgs | |
Fields
| |
Instances
| Num NumArgs | |
Defined in Lua.Types | |
| Show NumArgs | |
| Eq NumArgs | |
| Ord NumArgs | |
newtype StackIndex #
Constructors
| StackIndex | |
Fields | |
Instances
type PreCFunction = State -> IO NumResults #
fromReference :: Reference -> CInt #
toReference :: CInt -> Reference #
nthTop :: CInt -> StackIndex #
nthBottom :: CInt -> StackIndex #
nth :: CInt -> StackIndex #
top :: StackIndex #
Constructors
| Name | |
Fields | |
Constructors
| GCStop | |
| GCRestart | |
| GCCollect | |
| GCCount | |
| GCCountb | |
| GCStep CInt | |
| GCInc CInt CInt CInt | |
| GCGen CInt CInt | |
| GCIsRunning |
Instances
| Show GCControl | |
| Eq GCControl | |
| Ord GCControl | |
Defined in HsLua.Core.Types | |
type HaskellFunction e = LuaE e NumResults #
newtype LuaEnvironment #
Constructors
| LuaEnvironment | |
Fields
| |
Instances
| MonadReader LuaEnvironment (LuaE e) | |
Defined in HsLua.Core.Types Methods ask :: LuaE e LuaEnvironment Source # local :: (LuaEnvironment -> LuaEnvironment) -> LuaE e a -> LuaE e a Source # reader :: (LuaEnvironment -> a) -> LuaE e a Source # | |
unsafeRunWith :: State -> LuaE e a -> IO a #
multret :: NumResults #
newhsuserdatauv :: a -> Int -> LuaE e () #
newudmetatable :: Name -> LuaE e Bool #
fromuserdata :: forall a e. StackIndex -> Name -> LuaE e (Maybe a) #
putuserdata :: StackIndex -> Name -> a -> LuaE e Bool #
getupvalue :: StackIndex -> Int -> LuaE e (Maybe Name) #
setupvalue :: StackIndex -> Int -> LuaE e (Maybe Name) #
class Exception e => LuaError e where #
Instances
| LuaError Exception | |
Defined in HsLua.Core.Error Methods popException :: LuaE Exception Exception # pushException :: Exception -> LuaE Exception () # luaException :: String -> Exception # | |
throwErrorAsException :: LuaError e => LuaE e a #
throwTypeMismatchError :: LuaError e => ByteString -> StackIndex -> LuaE e a #
changeErrorType :: forall old new a. LuaE old a -> LuaE new a #
popErrorMessage :: State -> IO ByteString #
pushTypeMismatchError :: ByteString -> StackIndex -> LuaE e () #
absindex :: StackIndex -> LuaE e StackIndex #
checkstack :: Int -> LuaE e Bool #
createtable :: Int -> Int -> LuaE e () #
equal :: LuaError e => StackIndex -> StackIndex -> LuaE e Bool #
getmetatable :: StackIndex -> LuaE e Bool #
gettop :: LuaE e StackIndex #
getiuservalue :: StackIndex -> Int -> LuaE e Type #
isboolean :: StackIndex -> LuaE e Bool #
iscfunction :: StackIndex -> LuaE e Bool #
isfunction :: StackIndex -> LuaE e Bool #
isinteger :: StackIndex -> LuaE e Bool #
islightuserdata :: StackIndex -> LuaE e Bool #
isnil :: StackIndex -> LuaE e Bool #
isnone :: StackIndex -> LuaE e Bool #
isnoneornil :: StackIndex -> LuaE e Bool #
isnumber :: StackIndex -> LuaE e Bool #
isstring :: StackIndex -> LuaE e Bool #
istable :: StackIndex -> LuaE e Bool #
isthread :: StackIndex -> LuaE e Bool #
isuserdata :: StackIndex -> LuaE e Bool #
lessthan :: LuaError e => StackIndex -> StackIndex -> LuaE e Bool #
ltype :: StackIndex -> LuaE e Type #
openpackage :: LuaError e => LuaE e () #
openstring :: LuaError e => LuaE e () #
pushboolean :: Bool -> LuaE e () #
pushcclosure :: CFunction -> NumArgs -> LuaE e () #
pushcfunction :: CFunction -> LuaE e () #
pushglobaltable :: LuaE e () #
pushinteger :: Integer -> LuaE e () #
pushlightuserdata :: Ptr a -> LuaE e () #
pushnumber :: Number -> LuaE e () #
pushstring :: ByteString -> LuaE e () #
pushthread :: LuaE e Bool #
pushvalue :: StackIndex -> LuaE e () #
rawequal :: StackIndex -> StackIndex -> LuaE e Bool #
rawlen :: StackIndex -> LuaE e Int #
rawset :: LuaError e => StackIndex -> LuaE e () #
remove :: StackIndex -> LuaE e () #
replace :: StackIndex -> LuaE e () #
setmetatable :: StackIndex -> LuaE e () #
settable :: LuaError e => StackIndex -> LuaE e () #
settop :: StackIndex -> LuaE e () #
setiuservalue :: StackIndex -> Int -> LuaE e Bool #
toboolean :: StackIndex -> LuaE e Bool #
tocfunction :: StackIndex -> LuaE e (Maybe CFunction) #
topointer :: StackIndex -> LuaE e (Ptr ()) #
tostring :: StackIndex -> LuaE e (Maybe ByteString) #
touserdata :: StackIndex -> LuaE e (Maybe (Ptr a)) #
typename :: Type -> LuaE e ByteString #
upvalueindex :: StackIndex -> StackIndex #
pushPreCFunction :: PreCFunction -> LuaE e () #
pushHaskellFunction :: LuaError e => HaskellFunction e -> LuaE e () #
dostring :: ByteString -> LuaE e Status #
getmetafield :: StackIndex -> Name -> LuaE e Type #
getmetatable' :: Name -> LuaE e Type #
getsubtable :: LuaError e => StackIndex -> Name -> LuaE e Bool #
loadbuffer :: ByteString -> Name -> LuaE e Status #
loadstring :: ByteString -> LuaE e Status #
newmetatable :: Name -> LuaE e Bool #
ref :: StackIndex -> LuaE e Reference #
tostring' :: LuaError e => StackIndex -> LuaE e ByteString #
unref :: StackIndex -> Reference -> LuaE e () #
data GCManagedState #
closeGCManagedState :: GCManagedState -> IO () #
withGCManagedState :: GCManagedState -> LuaE e a -> IO a #
pcallTrace :: NumArgs -> NumResults -> LuaE e Status #
dostringTrace :: ByteString -> LuaE e Status #
Marshalling
module HsLua.Marshalling
Module, data, and function packaging
module HsLua.ObjectOrientation
module HsLua.Packaging
Type classes
module HsLua.Class.Exposable
module HsLua.Class.Invokable
module HsLua.Class.Peekable
class Pushable a where Source #
A value that can be pushed to the Lua stack.
Methods
push :: LuaError e => a -> LuaE e () Source #
Pushes a value onto Lua stack, casting it into meaningfully nearest Lua type.
Instances
Marshal to and from JSON-like structures
module HsLua.Aeson
Utility functions
getglobal' :: LuaError e => Name -> LuaE e () Source #
Like getglobal, but knows about packages and nested tables. E.g.
getglobal' "math.sin"
will return the function sin in package math.
setglobal' :: LuaError e => Name -> LuaE e () 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.
module HsLua.Class.Util