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 |
Foreign.Lua.Core.Types
Contents
Description
The core Lua types, including mappings of Lua types to Haskell.
Synopsis
- newtype Lua a = Lua {
- unLua :: ReaderT LuaEnvironment IO a
- data LuaEnvironment = LuaEnvironment {}
- data ErrorConversion = ErrorConversion {
- errorToException :: forall a. State -> IO a
- addContextToException :: forall a. String -> Lua a -> Lua a
- alternative :: forall a. Lua a -> Lua a -> Lua a
- exceptionToError :: Lua NumResults -> Lua NumResults
- errorConversion :: Lua ErrorConversion
- newtype State = State (Ptr ())
- type Reader = FunPtr (State -> Ptr () -> Ptr CSize -> IO (Ptr CChar))
- liftLua :: (State -> IO a) -> Lua a
- liftLua1 :: (State -> a -> IO b) -> a -> Lua b
- state :: Lua State
- runWithConverter :: ErrorConversion -> State -> Lua a -> IO a
- unsafeRunWith :: State -> Lua a -> IO a
- unsafeErrorConversion :: ErrorConversion
- data GCCONTROL
- data Type
- newtype TypeCode = TypeCode {
- fromTypeCode :: CInt
- fromType :: Type -> TypeCode
- toType :: TypeCode -> Type
- liftIO :: MonadIO m => IO a -> m a
- type CFunction = FunPtr (State -> IO NumResults)
- newtype LuaBool = LuaBool CInt
- false :: LuaBool
- true :: LuaBool
- fromLuaBool :: LuaBool -> Bool
- toLuaBool :: Bool -> LuaBool
- newtype Integer = Integer Int64
- newtype Number = Number Double
- newtype StackIndex = StackIndex {
- fromStackIndex :: CInt
- nthFromBottom :: CInt -> StackIndex
- nthFromTop :: CInt -> StackIndex
- stackTop :: StackIndex
- stackBottom :: StackIndex
- newtype NumArgs = NumArgs {
- fromNumArgs :: CInt
- newtype NumResults = NumResults {
- fromNumResults :: CInt
- data RelationalOperator
- fromRelationalOperator :: RelationalOperator -> CInt
- data Status
- newtype StatusCode = StatusCode CInt
- toStatus :: StatusCode -> Status
- data Reference
- fromReference :: Reference -> CInt
- toReference :: CInt -> Reference
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
Monad Lua # | |
Functor Lua # | |
Applicative Lua # | |
MonadCatch Lua # | |
Defined in Foreign.Lua.Core.Types | |
MonadMask Lua # | |
MonadThrow Lua # | |
Defined in Foreign.Lua.Core.Types | |
MonadIO Lua # | |
Defined in Foreign.Lua.Core.Types | |
Alternative Lua | |
ToHaskellFunction HaskellFunction # | |
Defined in Foreign.Lua.FunctionCalling Methods toHsFun :: StackIndex -> HaskellFunction -> Lua NumResults # | |
MonadReader LuaEnvironment Lua # | |
Defined in Foreign.Lua.Core.Types Methods ask :: Lua LuaEnvironment local :: (LuaEnvironment -> LuaEnvironment) -> Lua a -> Lua a reader :: (LuaEnvironment -> a) -> Lua a | |
Peekable a => LuaCallFunc (Lua a) # | |
Pushable a => ToHaskellFunction (Lua a) # | |
Defined in Foreign.Lua.FunctionCalling Methods toHsFun :: StackIndex -> Lua a -> Lua NumResults # |
data LuaEnvironment #
Environment in which Lua computations are evaluated.
Constructors
LuaEnvironment | |
Fields
|
Instances
MonadReader LuaEnvironment Lua # | |
Defined in Foreign.Lua.Core.Types Methods ask :: Lua LuaEnvironment local :: (LuaEnvironment -> LuaEnvironment) -> Lua a -> Lua a reader :: (LuaEnvironment -> a) -> Lua a |
data ErrorConversion #
Define the ways in which exceptions and errors are handled.
Constructors
ErrorConversion | |
Fields
|
errorConversion :: Lua ErrorConversion #
Get the error-to-exception function.
An opaque structure that points to a thread and indirectly (through the thread) to the whole state of a Lua interpreter. The Lua library is fully reentrant: it has no global variables. All information about a state is accessible through this structure.
Synonym for lua_State *
. See lua_State.
Constructors
State (Ptr ()) |
Instances
Eq State # | |
Generic State # | |
Pushable CFunction # | |
Defined in Foreign.Lua.Types.Pushable | |
Peekable CFunction # | |
Defined in Foreign.Lua.Types.Peekable Methods peek :: StackIndex -> Lua CFunction # | |
Peekable State # | |
Defined in Foreign.Lua.Types.Peekable Methods peek :: StackIndex -> Lua State # | |
type Rep State # | |
Defined in Foreign.Lua.Core.Types type Rep State = D1 ('MetaData "State" "Foreign.Lua.Core.Types" "hslua-1.1.0-4JmH6d3JbRqDpFMeZ2axlL" 'True) (C1 ('MetaCons "State" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Ptr ())))) |
type Reader = FunPtr (State -> Ptr () -> Ptr CSize -> IO (Ptr CChar)) #
The reader function used by
. Every time it needs another piece
of the chunk, lua_load calls the reader, passing along its data parameter.
The reader must return a pointer to a block of memory with a new piece of the
chunk and set size to the block size. The block must exist until the reader
function is called again. To signal the end of the chunk, the reader must
return lua_load
NULL
or set size to zero. The reader function may return pieces of any
size greater than zero.
See lua_Reader.
liftLua :: (State -> IO a) -> Lua a #
Turn a function of typ Lua.State -> IO a
into a monadic Lua operation.
liftLua1 :: (State -> a -> IO b) -> a -> Lua b #
Turn a function of typ Lua.State -> a -> IO b
into a monadic Lua operation.
runWithConverter :: ErrorConversion -> State -> Lua a -> IO a #
Run Lua computation with the given Lua state and error-to-exception converter. Any resulting exceptions are left unhandled.
unsafeRunWith :: State -> Lua a -> IO a #
Run the given operation, but crash if any Haskell exceptions occur.
unsafeErrorConversion :: ErrorConversion #
Unsafe
; no proper error handling is attempted,
any error leads to a crash.ErrorConversion
Enumeration used by gc
function.
Constructors
GCSTOP | |
GCRESTART | |
GCCOLLECT | |
GCCOUNT | |
GCCOUNTB | |
GCSTEP | |
GCSETPAUSE | |
GCSETSTEPMUL |
Instances
Enum GCCONTROL # | |
Defined in Foreign.Lua.Core.Types | |
Eq GCCONTROL # | |
Ord GCCONTROL # | |
Defined in Foreign.Lua.Core.Types | |
Show GCCONTROL # | |
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 |
Integer code used to encode the type of a lua value.
Constructors
TypeCode | |
Fields
|
type CFunction = FunPtr (State -> IO NumResults) #
Type for C functions.
In order to communicate properly with Lua, a C function must use the
following protocol, which defines the way parameters and results are passed:
a C function receives its arguments from Lua in its stack in direct order
(the first argument is pushed first). So, when the function starts,
returns the number of arguments received by the function. The
first argument (if any) is at index 1 and its last argument is at index
gettop
gettop
. To return values to Lua, a C function just pushes them onto the
stack, in direct order (the first result is pushed first), and returns the
number of results. Any other value in the stack below the results will be
properly discarded by Lua. Like a Lua function, a C function called by Lua
can also return many results.
See lua_CFunction.
Boolean value returned by a Lua C API function. This is a
and
interpreted as CInt
iff the value is False
0
,
otherwise.True
Constructors
LuaBool CInt |
Instances
Eq LuaBool # | |
Show LuaBool # | |
Storable LuaBool # | |
Defined in Foreign.Lua.Core.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 () |
fromLuaBool :: LuaBool -> Bool #
Convert a
to a Haskell LuaBool
.Bool
The type of integers in Lua.
By default this type is
, but that can be changed to different
values in lua. (See Int64
LUA_INT_TYPE
in luaconf.h
.)
See lua_Integer.
Constructors
Integer Int64 |
Instances
Bounded Integer # | |
Defined in Foreign.Lua.Core.Types | |
Enum Integer # | |
Defined in Foreign.Lua.Core.Types | |
Eq Integer # | |
Integral Integer # | |
Defined in Foreign.Lua.Core.Types | |
Num Integer # | |
Ord Integer # | |
Real Integer # | |
Defined in Foreign.Lua.Core.Types Methods toRational :: Integer -> Rational | |
Show Integer # | |
Pushable Integer # | |
Defined in Foreign.Lua.Types.Pushable | |
Peekable Integer # | |
Defined in Foreign.Lua.Types.Peekable Methods peek :: StackIndex -> Lua Integer # |
The type of floats in Lua.
By default this type is
, but that can be changed in Lua to a
single float or a long double. (See Double
LUA_FLOAT_TYPE
in luaconf.h
.)
See lua_Number.
Constructors
Number Double |
Instances
Eq Number # | |
Floating Number # | |
Fractional Number # | |
Defined in Foreign.Lua.Core.Types | |
Num Number # | |
Ord Number # | |
Real Number # | |
Defined in Foreign.Lua.Core.Types Methods toRational :: Number -> Rational | |
RealFloat Number # | |
Defined in Foreign.Lua.Core.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 | |
RealFrac Number # | |
Show Number # | |
Pushable Number # | |
Defined in Foreign.Lua.Types.Pushable | |
Peekable Number # | |
Defined in Foreign.Lua.Types.Peekable Methods peek :: StackIndex -> Lua Number # |
newtype StackIndex #
A stack index
Constructors
StackIndex | |
Fields
|
Instances
nthFromBottom :: CInt -> StackIndex #
Stack index of the nth element from the bottom of the stack.
nthFromTop :: CInt -> StackIndex #
Stack index of the nth element from the top of the stack.
stackTop :: StackIndex #
Top of the stack
Bottom of the stack
The number of arguments expected a function.
Constructors
NumArgs | |
Fields
|
newtype NumResults #
The number of results returned by a function call.
Constructors
NumResults | |
Fields
|
Instances
data RelationalOperator #
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
Eq RelationalOperator # | |
Defined in Foreign.Lua.Core.Types Methods (==) :: RelationalOperator -> RelationalOperator -> Bool (/=) :: RelationalOperator -> RelationalOperator -> Bool | |
Ord RelationalOperator # | |
Defined in Foreign.Lua.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 | |
Show RelationalOperator # | |
Defined in Foreign.Lua.Core.Types Methods showsPrec :: Int -> RelationalOperator -> ShowS show :: RelationalOperator -> String showList :: [RelationalOperator] -> ShowS |
fromRelationalOperator :: RelationalOperator -> CInt #
Convert relation operator to its C representation.
Lua status values.
newtype StatusCode #
Integer code used to signal the status of a thread or computation.
See
.Status
Constructors
StatusCode CInt |
Instances
Eq StatusCode # | |
Defined in Foreign.Lua.Core.Types |
toStatus :: StatusCode -> Status #
Convert C integer constant to
.LuaStatus
References
Reference to a stored value.
fromReference :: Reference -> CInt #
Convert a reference to its C representation.
toReference :: CInt -> Reference #
Create a reference from its C representation.