hslua-1.0.2: Bindings to Lua, an embeddable scripting language

Copyright© 2007–2012 Gracjan Polak
2012–2016 Ömer Sinan Ağacan
2017-2019 Albert Krewinkel
LicenseMIT
MaintainerAlbert Krewinkel <tarleb+hslua@zeitkraut.de>
Stabilitybeta
Portabilitynon-portable (depends on GHC)
Safe HaskellNone
LanguageHaskell2010

Foreign.Lua.Core.Types

Contents

Description

The core Lua types, including mappings of Lua types to Haskell.

Synopsis

Documentation

newtype Lua a #

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 # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

(>>=) :: Lua a -> (a -> Lua b) -> Lua b #

(>>) :: Lua a -> Lua b -> Lua b #

return :: a -> Lua a #

fail :: String -> Lua a #

Functor Lua # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

fmap :: (a -> b) -> Lua a -> Lua b #

(<$) :: a -> Lua b -> Lua a #

Applicative Lua # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

pure :: a -> Lua a #

(<*>) :: Lua (a -> b) -> Lua a -> Lua b #

liftA2 :: (a -> b -> c) -> Lua a -> Lua b -> Lua c #

(*>) :: Lua a -> Lua b -> Lua b #

(<*) :: Lua a -> Lua b -> Lua a #

MonadIO Lua # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

liftIO :: IO a -> Lua a #

Alternative Lua # 
Instance details

Defined in Foreign.Lua.Core.Error

Methods

empty :: Lua a #

(<|>) :: Lua a -> Lua a -> Lua a #

some :: Lua a -> Lua [a] #

many :: Lua a -> Lua [a] #

MonadThrow Lua # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

throwM :: Exception e => e -> Lua a #

MonadCatch Lua # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

catch :: Exception e => Lua a -> (e -> Lua a) -> Lua a #

MonadMask Lua # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

mask :: ((forall a. Lua a -> Lua a) -> Lua b) -> Lua b #

uninterruptibleMask :: ((forall a. Lua a -> Lua a) -> Lua b) -> Lua b #

generalBracket :: Lua a -> (a -> ExitCase b -> Lua c) -> (a -> Lua b) -> Lua (b, c) #

ToHaskellFunction HaskellFunction # 
Instance details

Defined in Foreign.Lua.FunctionCalling

MonadReader State Lua # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

ask :: Lua State #

local :: (State -> State) -> Lua a -> Lua a #

reader :: (State -> a) -> Lua a #

Peekable a => LuaCallFunc (Lua a) # 
Instance details

Defined in Foreign.Lua.FunctionCalling

Methods

callFunc' :: String -> Lua () -> NumArgs -> Lua a #

Pushable a => ToHaskellFunction (Lua a) # 
Instance details

Defined in Foreign.Lua.FunctionCalling

Methods

toHsFun :: StackIndex -> Lua a -> Lua NumResults #

newtype State #

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 # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

(==) :: State -> State -> Bool #

(/=) :: State -> State -> Bool #

Generic State # 
Instance details

Defined in Foreign.Lua.Core.Types

Associated Types

type Rep State :: Type -> Type #

Methods

from :: State -> Rep State x #

to :: Rep State x -> State #

Pushable CFunction # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: CFunction -> Lua () #

Peekable CFunction # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Peekable State # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua State #

MonadReader State Lua # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

ask :: Lua State #

local :: (State -> State) -> Lua a -> Lua a #

reader :: (State -> a) -> Lua a #

type Rep State # 
Instance details

Defined in Foreign.Lua.Core.Types

type Rep State = D1 (MetaData "State" "Foreign.Lua.Core.Types" "hslua-1.0.2-J8KcscLbc3XLdjj8GNigEL" 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 lua_load. 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 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.

state :: Lua State #

Get the lua state of this lua computation.

runWith :: State -> Lua a -> IO a #

Run lua computation with custom lua state. Errors are left unhandled, the caller of this function is responsible to catch lua errors.

data Type #

Enumeration used as type tag. See lua_type.

Constructors

TypeNone

non-valid stack index

TypeNil

type of lua's nil value

TypeBoolean

type of lua booleans

TypeLightUserdata

type of light userdata

TypeNumber

type of lua numbers. See Number

TypeString

type of lua string values

TypeTable

type of lua tables

TypeFunction

type of functions, either normal or CFunction

TypeUserdata

type of full user data

TypeThread

type of lua threads

Instances
Bounded Type # 
Instance details

Defined in Foreign.Lua.Core.Types

Enum Type # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

succ :: Type -> Type #

pred :: Type -> Type #

toEnum :: Int -> Type #

fromEnum :: Type -> Int #

enumFrom :: Type -> [Type] #

enumFromThen :: Type -> Type -> [Type] #

enumFromTo :: Type -> Type -> [Type] #

enumFromThenTo :: Type -> Type -> Type -> [Type] #

Eq Type # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

(==) :: Type -> Type -> Bool #

(/=) :: Type -> Type -> Bool #

Ord Type # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

compare :: Type -> Type -> Ordering #

(<) :: Type -> Type -> Bool #

(<=) :: Type -> Type -> Bool #

(>) :: Type -> Type -> Bool #

(>=) :: Type -> Type -> Bool #

max :: Type -> Type -> Type #

min :: Type -> Type -> Type #

Show Type # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

showsPrec :: Int -> Type -> ShowS #

show :: Type -> String #

showList :: [Type] -> ShowS #

newtype TypeCode #

Integer code used to encode the type of a lua value.

Constructors

TypeCode 

Fields

Instances
Eq TypeCode # 
Instance details

Defined in Foreign.Lua.Core.Types

Ord TypeCode # 
Instance details

Defined in Foreign.Lua.Core.Types

Show TypeCode # 
Instance details

Defined in Foreign.Lua.Core.Types

fromType :: Type -> TypeCode #

Convert a lua Type to a type code which can be passed to the C API.

toType :: TypeCode -> Type #

Convert numerical code to lua type.

liftIO :: MonadIO m => IO a -> m a #

Lift a computation from the IO monad.

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, gettop 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. 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.

newtype LuaBool #

Boolean value returned by a Lua C API function. This is a CInt and interpreted as False iff the value is 0, True otherwise.

Constructors

LuaBool CInt 
Instances
Eq LuaBool # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

(==) :: LuaBool -> LuaBool -> Bool #

(/=) :: LuaBool -> LuaBool -> Bool #

Show LuaBool # 
Instance details

Defined in Foreign.Lua.Core.Types

Storable LuaBool # 
Instance details

Defined in Foreign.Lua.Core.Types

false :: LuaBool #

Lua representation of the value interpreted as false.

true :: LuaBool #

Generic Lua representation of a value interpreted as being true.

fromLuaBool :: LuaBool -> Bool #

Convert a LuaBool to a Haskell Bool.

toLuaBool :: Bool -> LuaBool #

Convert a Haskell Bool to a LuaBool.

newtype Integer #

The type of integers in Lua.

By default this type is Int64, but that can be changed to different values in lua. (See LUA_INT_TYPE in luaconf.h.)

See lua_Integer.

Constructors

Integer Int64 
Instances
Bounded Integer # 
Instance details

Defined in Foreign.Lua.Core.Types

Enum Integer # 
Instance details

Defined in Foreign.Lua.Core.Types

Eq Integer # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

(==) :: Integer -> Integer -> Bool #

(/=) :: Integer -> Integer -> Bool #

Integral Integer # 
Instance details

Defined in Foreign.Lua.Core.Types

Num Integer # 
Instance details

Defined in Foreign.Lua.Core.Types

Ord Integer # 
Instance details

Defined in Foreign.Lua.Core.Types

Real Integer # 
Instance details

Defined in Foreign.Lua.Core.Types

Show Integer # 
Instance details

Defined in Foreign.Lua.Core.Types

Pushable Integer # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Integer -> Lua () #

Peekable Integer # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua Integer #

newtype Number #

The type of floats in Lua.

By default this type is Double, but that can be changed in Lua to a single float or a long double. (See LUA_FLOAT_TYPE in luaconf.h.)

See lua_Number.

Constructors

Number Double 
Instances
Eq Number # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

(==) :: Number -> Number -> Bool #

(/=) :: Number -> Number -> Bool #

Floating Number # 
Instance details

Defined in Foreign.Lua.Core.Types

Fractional Number # 
Instance details

Defined in Foreign.Lua.Core.Types

Num Number # 
Instance details

Defined in Foreign.Lua.Core.Types

Ord Number # 
Instance details

Defined in Foreign.Lua.Core.Types

Real Number # 
Instance details

Defined in Foreign.Lua.Core.Types

RealFloat Number # 
Instance details

Defined in Foreign.Lua.Core.Types

RealFrac Number # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

properFraction :: Integral b => Number -> (b, Number) #

truncate :: Integral b => Number -> b #

round :: Integral b => Number -> b #

ceiling :: Integral b => Number -> b #

floor :: Integral b => Number -> b #

Show Number # 
Instance details

Defined in Foreign.Lua.Core.Types

Pushable Number # 
Instance details

Defined in Foreign.Lua.Types.Pushable

Methods

push :: Number -> Lua () #

Peekable Number # 
Instance details

Defined in Foreign.Lua.Types.Peekable

Methods

peek :: StackIndex -> Lua Number #

newtype StackIndex #

A stack index

Constructors

StackIndex 

Fields

Instances
Enum StackIndex # 
Instance details

Defined in Foreign.Lua.Core.Types

Eq StackIndex # 
Instance details

Defined in Foreign.Lua.Core.Types

Num StackIndex # 
Instance details

Defined in Foreign.Lua.Core.Types

Ord StackIndex # 
Instance details

Defined in Foreign.Lua.Core.Types

Show StackIndex # 
Instance details

Defined in Foreign.Lua.Core.Types

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

stackBottom :: StackIndex #

Bottom of the stack

newtype NumArgs #

The number of arguments expected a function.

Constructors

NumArgs 

Fields

Instances
Eq NumArgs # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

(==) :: NumArgs -> NumArgs -> Bool #

(/=) :: NumArgs -> NumArgs -> Bool #

Num NumArgs # 
Instance details

Defined in Foreign.Lua.Core.Types

Ord NumArgs # 
Instance details

Defined in Foreign.Lua.Core.Types

Show NumArgs # 
Instance details

Defined in Foreign.Lua.Core.Types

newtype NumResults #

The number of results returned by a function call.

Constructors

NumResults 

Fields

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

fromRelationalOperator :: RelationalOperator -> CInt #

Convert relation operator to its C representation.

data Status #

Lua status values.

Constructors

OK

success

Yield

yielding / suspended coroutine

ErrRun

a runtime rror

ErrSyntax

syntax error during precompilation

ErrMem

memory allocation (out-of-memory) error.

ErrErr

error while running the message handler.

ErrGcmm

error while running a __gc metamethod.

ErrFile

opening or reading a file failed.

Instances
Eq Status # 
Instance details

Defined in Foreign.Lua.Core.Types

Methods

(==) :: Status -> Status -> Bool #

(/=) :: Status -> Status -> Bool #

Show Status # 
Instance details

Defined in Foreign.Lua.Core.Types

newtype StatusCode #

Integer code used to signal the status of a thread or computation. See Status.

Constructors

StatusCode CInt 
Instances
Eq StatusCode # 
Instance details

Defined in Foreign.Lua.Core.Types

toStatus :: StatusCode -> Status #

Convert C integer constant to LuaStatus.

References

data Reference #

Reference to a stored value.

Constructors

Reference CInt

Reference to a stored value

RefNil

Reference to a nil value

Instances
Eq Reference # 
Instance details

Defined in Foreign.Lua.Core.Types

Show Reference # 
Instance details

Defined in Foreign.Lua.Core.Types

fromReference :: Reference -> CInt #

Convert a reference to its C representation.

toReference :: CInt -> Reference #

Create a reference from its C representation.