| 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.Core.Types
Description
The core Lua types, including mappings of Lua types to Haskell.
This module has mostly been moved to and
currently re-exports that module. This module might be removed in
the future.Types
Synopsis
- newtype LuaE e a = Lua {
- unLua :: ReaderT LuaEnvironment IO a
- newtype LuaEnvironment = LuaEnvironment {
- luaEnvState :: State
- newtype State = State (Ptr ())
- type Reader = FunPtr (State -> Ptr () -> Ptr CSize -> IO (Ptr CChar))
- liftLua :: (State -> IO a) -> LuaE e a
- liftLua1 :: (State -> a -> IO b) -> a -> LuaE e b
- state :: LuaE e State
- runWith :: State -> LuaE e a -> IO a
- unsafeRunWith :: State -> LuaE e a -> IO a
- data GCControl
- toGCcode :: GCControl -> GCCode
- toGCdata :: GCControl -> (CInt, CInt, CInt)
- data Type
- fromType :: Type -> TypeCode
- toType :: TypeCode -> Type
- liftIO :: MonadIO m => IO a -> m a
- type CFunction = FunPtr PreCFunction
- type PreCFunction = State -> IO NumResults
- type HaskellFunction e = LuaE e NumResults
- newtype LuaBool = LuaBool CInt
- fromLuaBool :: LuaBool -> Bool
- toLuaBool :: Bool -> LuaBool
- newtype Integer = Integer Int64
- newtype Number = Number Double
- newtype StackIndex = StackIndex {
- fromStackIndex :: CInt
- registryindex :: StackIndex
- newtype NumArgs = NumArgs {
- fromNumArgs :: CInt
- newtype NumResults = NumResults {
- fromNumResults :: CInt
- multret :: NumResults
- data RelationalOperator
- fromRelationalOperator :: RelationalOperator -> OPCode
- data Status
- toStatus :: StatusCode -> Status
- data Reference
- fromReference :: Reference -> CInt
- toReference :: CInt -> Reference
- noref :: Int
- refnil :: Int
- nthTop :: CInt -> StackIndex
- nthBottom :: CInt -> StackIndex
- nth :: CInt -> StackIndex
- top :: StackIndex
- newtype Name = Name {
- fromName :: ByteString
Documentation
A Lua computation. This is the base type used to run Lua programs
of any kind. The Lua state is handled automatically, but can be
retrieved via .state
Constructors
| Lua | |
Fields
| |
Instances
| MonadReader LuaEnvironment (LuaE e) Source # | |
Defined in HsLua.Core.Types Methods ask :: LuaE e LuaEnvironment local :: (LuaEnvironment -> LuaEnvironment) -> LuaE e a -> LuaE e a reader :: (LuaEnvironment -> a) -> LuaE e a | |
| MonadCatch (LuaE e) Source # | |
Defined in HsLua.Core.Types | |
| MonadMask (LuaE e) Source # | |
Defined in HsLua.Core.Types | |
| MonadThrow (LuaE e) Source # | |
Defined in HsLua.Core.Types | |
| LuaError e => Alternative (LuaE e) | |
| Applicative (LuaE e) Source # | |
| Functor (LuaE e) Source # | |
| Monad (LuaE e) Source # | |
| LuaError e => MonadFail (LuaE e) | |
Defined in HsLua.Core.Error | |
| MonadIO (LuaE e) Source # | |
Defined in HsLua.Core.Types | |
newtype LuaEnvironment Source #
Environment in which Lua computations are evaluated.
Constructors
| LuaEnvironment | |
Fields
| |
Instances
| MonadReader LuaEnvironment (LuaE e) Source # | |
Defined in HsLua.Core.Types Methods ask :: LuaE e LuaEnvironment local :: (LuaEnvironment -> LuaEnvironment) -> LuaE e a -> LuaE e a reader :: (LuaEnvironment -> a) -> LuaE e a | |
Constructors
| State (Ptr ()) |
liftLua :: (State -> IO a) -> LuaE e a Source #
Turn a function of typ Lua.State -> IO a into a monadic Lua
operation.
liftLua1 :: (State -> a -> IO b) -> a -> LuaE e b Source #
Turn a function of typ Lua.State -> a -> IO b into a monadic Lua
operation.
runWith :: State -> LuaE e a -> IO a Source #
Run Lua computation with the given Lua state. Exception handling is left to the caller; resulting exceptions are left unhandled.
unsafeRunWith :: State -> LuaE e a -> IO a Source #
Run the given operation, but crash if any Haskell exceptions occur.
This function is identical to runWith; it exists for backwards
compatibility.
Commands to control the garbage collector.
Constructors
| GCStop | stops the garbage collector. |
| GCRestart | restarts the garbage collector |
| GCCollect | performs a full garbage-collection cycle. |
| GCCount | returns the current amount of memory (in Kbytes) in use by Lua. |
| GCCountb | returns the remainder of dividing the current amount of bytes of memory in use by Lua by 1024. |
| GCStep CInt | performs an incremental step of garbage
collection, corresponding to the allocation of
|
| GCInc CInt CInt CInt | Changes the collector to incremental mode
with the given parameters (see
<https://www.lua.org/manual/5.4/manual.html#2.5.1
§2.5.1>). Returns the previous mode
( |
| GCGen CInt CInt | Changes the collector to generational mode
with the given parameters (see
<https://www.lua.org/manual/5.4/manual.html#2.5.2
§2.5.2>). Returns the previous mode
( |
| GCIsRunning | returns a boolean that tells whether the collector is running (i.e., not stopped). |
toGCdata :: GCControl -> (CInt, CInt, CInt) Source #
Returns the data value associated with a GCControl command.
Enumeration used as type tag. See lua_type.
Constructors
| TypeNone | non-valid stack index |
| TypeNil | type of Lua's |
| TypeBoolean | type of Lua booleans |
| TypeLightUserdata | type of light userdata |
| TypeNumber | type of Lua numbers. See |
| TypeString | type of Lua string values |
| TypeTable | type of Lua tables |
| TypeFunction | type of functions, either normal or |
| TypeUserdata | type of full user data |
| TypeThread | type of Lua threads |
fromType :: Type -> TypeCode Source #
Convert a Lua Type to a type code which can be passed to the C
API.
type CFunction = FunPtr PreCFunction #
type PreCFunction = State -> IO NumResults #
type HaskellFunction e = LuaE e NumResults Source #
Haskell function that can be called from Lua.
The HsLua equivallent of a PreCFunction.
Constructors
| LuaBool CInt |
Instances
| Storable LuaBool # | |
Defined in Lua.Types Methods peekElemOff :: Ptr LuaBool -> Int -> IO LuaBool pokeElemOff :: Ptr LuaBool -> Int -> LuaBool -> IO () peekByteOff :: Ptr b -> Int -> IO LuaBool pokeByteOff :: Ptr b -> Int -> LuaBool -> IO () | |
| Show LuaBool # | |
| Eq LuaBool # | |
fromLuaBool :: LuaBool -> Bool Source #
Convert a to a Haskell LuaBool.Bool
Constructors
| Integer Int64 |
Constructors
| Number Double |
Instances
| Floating Number # | |
| RealFloat Number # | |
Defined in Lua.Types Methods floatRadix :: Number -> Integer floatDigits :: Number -> Int floatRange :: Number -> (Int, Int) decodeFloat :: Number -> (Integer, Int) encodeFloat :: Integer -> Int -> Number significand :: Number -> Number scaleFloat :: Int -> Number -> Number isInfinite :: Number -> Bool isDenormalized :: Number -> Bool isNegativeZero :: Number -> Bool | |
| Num Number # | |
| Read Number # | |
| Fractional Number # | |
| Real Number # | |
Defined in Lua.Types Methods toRational :: Number -> Rational | |
| RealFrac Number # | |
| Show Number # | |
| Eq Number # | |
| Ord Number # | |
newtype StackIndex #
Constructors
| StackIndex | |
Fields
| |
Instances
registryindex :: StackIndex Source #
Pseudo stack index of the Lua registry.
Constructors
| NumArgs | |
Fields
| |
newtype NumResults #
Constructors
| NumResults | |
Fields
| |
Instances
| Num NumResults # | |
Defined in Lua.Types Methods (+) :: NumResults -> NumResults -> NumResults (-) :: NumResults -> NumResults -> NumResults (*) :: NumResults -> NumResults -> NumResults negate :: NumResults -> NumResults abs :: NumResults -> NumResults signum :: NumResults -> NumResults fromInteger :: Integer -> NumResults | |
| Show NumResults # | |
Defined in Lua.Types Methods showsPrec :: Int -> NumResults -> ShowS show :: NumResults -> String showList :: [NumResults] -> ShowS | |
| Eq NumResults # | |
Defined in Lua.Types | |
| Ord NumResults # | |
Defined in Lua.Types Methods compare :: NumResults -> NumResults -> Ordering (<) :: NumResults -> NumResults -> Bool (<=) :: NumResults -> NumResults -> Bool (>) :: NumResults -> NumResults -> Bool (>=) :: NumResults -> NumResults -> Bool max :: NumResults -> NumResults -> NumResults min :: NumResults -> NumResults -> NumResults | |
multret :: NumResults Source #
Option for multiple returns in .pcall
data RelationalOperator Source #
Lua comparison operations.
Constructors
| EQ | Correponds to Lua's equality (==) operator. |
| LT | Correponds to Lua's strictly-lesser-than (<) operator |
| LE | Correponds to Lua's lesser-or-equal (<=) operator |
Instances
| Show RelationalOperator Source # | |
Defined in HsLua.Core.Types Methods showsPrec :: Int -> RelationalOperator -> ShowS show :: RelationalOperator -> String showList :: [RelationalOperator] -> ShowS | |
| Eq RelationalOperator Source # | |
Defined in HsLua.Core.Types Methods (==) :: RelationalOperator -> RelationalOperator -> Bool (/=) :: RelationalOperator -> RelationalOperator -> Bool | |
| Ord RelationalOperator Source # | |
Defined in HsLua.Core.Types Methods compare :: RelationalOperator -> RelationalOperator -> Ordering (<) :: RelationalOperator -> RelationalOperator -> Bool (<=) :: RelationalOperator -> RelationalOperator -> Bool (>) :: RelationalOperator -> RelationalOperator -> Bool (>=) :: RelationalOperator -> RelationalOperator -> Bool max :: RelationalOperator -> RelationalOperator -> RelationalOperator min :: RelationalOperator -> RelationalOperator -> RelationalOperator | |
fromRelationalOperator :: RelationalOperator -> OPCode Source #
Convert relation operator to its C representation.
Lua status values.
References
fromReference :: Reference -> CInt #
toReference :: CInt -> Reference #
Stack index helpers
nthTop :: CInt -> StackIndex #
nthBottom :: CInt -> StackIndex #
nth :: CInt -> StackIndex #
top :: StackIndex #
Table field names
Name of a function, table field, or chunk; the name must be valid UTF-8 and may not contain any nul characters.
Implementation note: this is a newtype instead of a simple type
Name = ByteString alias so we can define a UTF-8 based IsString
instance. Non-ASCII users would have a bad time otherwise.