hslua-core-2.2.1: Bindings to Lua, an embeddable scripting language
Copyright© 2007–2012 Gracjan Polak;
© 2012–2016 Ömer Sinan Ağacan;
© 2017-2022 Albert Krewinkel
LicenseMIT
MaintainerAlbert Krewinkel <tarleb+hslua@zeitkraut.de>
Stabilitybeta
Portabilitynon-portable (depends on GHC)
Safe HaskellSafe-Inferred
LanguageHaskell2010

HsLua.Core.Types

Description

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

This module has mostly been moved to Types and currently re-exports that module. This module might be removed in the future.

Synopsis

Documentation

newtype LuaE e a Source #

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

Instances details
MonadReader LuaEnvironment (LuaE e) Source # 
Instance details

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

LuaError e => MonadFail (LuaE e) 
Instance details

Defined in HsLua.Core.Error

Methods

fail :: String -> LuaE e a

MonadIO (LuaE e) Source # 
Instance details

Defined in HsLua.Core.Types

Methods

liftIO :: IO a -> LuaE e a #

LuaError e => Alternative (LuaE e) 
Instance details

Defined in HsLua.Core.Error

Methods

empty :: LuaE e a

(<|>) :: LuaE e a -> LuaE e a -> LuaE e a

some :: LuaE e a -> LuaE e [a]

many :: LuaE e a -> LuaE e [a]

Applicative (LuaE e) Source # 
Instance details

Defined in HsLua.Core.Types

Methods

pure :: a -> LuaE e a

(<*>) :: LuaE e (a -> b) -> LuaE e a -> LuaE e b

liftA2 :: (a -> b -> c) -> LuaE e a -> LuaE e b -> LuaE e c

(*>) :: LuaE e a -> LuaE e b -> LuaE e b

(<*) :: LuaE e a -> LuaE e b -> LuaE e a

Functor (LuaE e) Source # 
Instance details

Defined in HsLua.Core.Types

Methods

fmap :: (a -> b) -> LuaE e a -> LuaE e b

(<$) :: a -> LuaE e b -> LuaE e a

Monad (LuaE e) Source # 
Instance details

Defined in HsLua.Core.Types

Methods

(>>=) :: LuaE e a -> (a -> LuaE e b) -> LuaE e b

(>>) :: LuaE e a -> LuaE e b -> LuaE e b

return :: a -> LuaE e a

MonadCatch (LuaE e) Source # 
Instance details

Defined in HsLua.Core.Types

Methods

catch :: Exception e0 => LuaE e a -> (e0 -> LuaE e a) -> LuaE e a

MonadMask (LuaE e) Source # 
Instance details

Defined in HsLua.Core.Types

Methods

mask :: ((forall a. LuaE e a -> LuaE e a) -> LuaE e b) -> LuaE e b

uninterruptibleMask :: ((forall a. LuaE e a -> LuaE e a) -> LuaE e b) -> LuaE e b

generalBracket :: LuaE e a -> (a -> ExitCase b -> LuaE e c) -> (a -> LuaE e b) -> LuaE e (b, c)

MonadThrow (LuaE e) Source # 
Instance details

Defined in HsLua.Core.Types

Methods

throwM :: Exception e0 => e0 -> LuaE e a

newtype LuaEnvironment Source #

Environment in which Lua computations are evaluated.

Constructors

LuaEnvironment 

Fields

Instances

Instances details
MonadReader LuaEnvironment (LuaE e) Source # 
Instance details

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

newtype State Source #

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

Instances details
Generic State 
Instance details

Defined in Lua.Types

Associated Types

type Rep State :: Type -> Type

Methods

from :: State -> Rep State x

to :: Rep State x -> State

Eq State 
Instance details

Defined in Lua.Types

Methods

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

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

type Rep State 
Instance details

Defined in Lua.Types

type Rep State = D1 ('MetaData "State" "Lua.Types" "lua-2.2.1-KRmEomuYCwNASKOuLK7fDI" '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)) Source #

The reader function used by 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) -> 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.

state :: LuaE e State Source #

Get the Lua state of this Lua computation.

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.

data GCControl Source #

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 stepsize Kbytes.

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 (LUA_GCGEN or LUA_GCINC). Parameters: pause, stepmul, and stepsize.

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 (LUA_GCGEN or LUA_GCINC).

GCIsRunning

returns a boolean that tells whether the collector is running (i.e., not stopped).

Instances

Instances details
Show GCControl Source # 
Instance details

Defined in HsLua.Core.Types

Methods

showsPrec :: Int -> GCControl -> ShowS

show :: GCControl -> String

showList :: [GCControl] -> ShowS

Eq GCControl Source # 
Instance details

Defined in HsLua.Core.Types

Methods

(==) :: GCControl -> GCControl -> Bool

(/=) :: GCControl -> GCControl -> Bool

Ord GCControl Source # 
Instance details

Defined in HsLua.Core.Types

Methods

compare :: GCControl -> GCControl -> Ordering

(<) :: GCControl -> GCControl -> Bool

(<=) :: GCControl -> GCControl -> Bool

(>) :: GCControl -> GCControl -> Bool

(>=) :: GCControl -> GCControl -> Bool

max :: GCControl -> GCControl -> GCControl

min :: GCControl -> GCControl -> GCControl

toGCcode :: GCControl -> GCCode Source #

Converts a GCControl command to its corresponding code.

toGCdata :: GCControl -> (CInt, CInt, CInt) Source #

Returns the data value associated with a GCControl command.

data Type Source #

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

Instances details
Bounded Type Source # 
Instance details

Defined in HsLua.Core.Types

Enum Type Source # 
Instance details

Defined in HsLua.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]

Show Type Source # 
Instance details

Defined in HsLua.Core.Types

Methods

showsPrec :: Int -> Type -> ShowS

show :: Type -> String

showList :: [Type] -> ShowS

Eq Type Source # 
Instance details

Defined in HsLua.Core.Types

Methods

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

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

Ord Type Source # 
Instance details

Defined in HsLua.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

fromType :: Type -> TypeCode Source #

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

toType :: TypeCode -> Type Source #

Convert numerical code to Lua Type.

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

type CFunction = FunPtr PreCFunction Source #

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

type PreCFunction = State -> IO NumResults Source #

Type of Haskell functions that can be turned into C functions.

This is the same as a dereferenced CFunction.

type HaskellFunction e = LuaE e NumResults Source #

Haskell function that can be called from Lua. The HsLua equivallent of a PreCFunction.

newtype LuaBool Source #

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

Constructors

LuaBool CInt 

Instances

Instances details
Storable LuaBool 
Instance details

Defined in Lua.Types

Methods

sizeOf :: LuaBool -> Int

alignment :: LuaBool -> Int

peekElemOff :: Ptr LuaBool -> Int -> IO LuaBool

pokeElemOff :: Ptr LuaBool -> Int -> LuaBool -> IO ()

peekByteOff :: Ptr b -> Int -> IO LuaBool

pokeByteOff :: Ptr b -> Int -> LuaBool -> IO ()

peek :: Ptr LuaBool -> IO LuaBool

poke :: Ptr LuaBool -> LuaBool -> IO ()

Show LuaBool 
Instance details

Defined in Lua.Types

Methods

showsPrec :: Int -> LuaBool -> ShowS

show :: LuaBool -> String

showList :: [LuaBool] -> ShowS

Eq LuaBool 
Instance details

Defined in Lua.Types

Methods

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

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

fromLuaBool :: LuaBool -> Bool Source #

Convert a LuaBool to a Haskell Bool.

toLuaBool :: Bool -> LuaBool Source #

Convert a Haskell Bool to a LuaBool.

newtype Integer Source #

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

Instances details
Bounded Integer 
Instance details

Defined in Lua.Types

Enum Integer 
Instance details

Defined in Lua.Types

Num Integer 
Instance details

Defined in Lua.Types

Read Integer 
Instance details

Defined in Lua.Types

Methods

readsPrec :: Int -> ReadS Integer

readList :: ReadS [Integer]

readPrec :: ReadPrec Integer

readListPrec :: ReadPrec [Integer]

Integral Integer 
Instance details

Defined in Lua.Types

Real Integer 
Instance details

Defined in Lua.Types

Methods

toRational :: Integer -> Rational

Show Integer 
Instance details

Defined in Lua.Types

Methods

showsPrec :: Int -> Integer -> ShowS

show :: Integer -> String

showList :: [Integer] -> ShowS

Eq Integer 
Instance details

Defined in Lua.Types

Methods

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

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

Ord Integer 
Instance details

Defined in Lua.Types

Methods

compare :: Integer -> Integer -> Ordering

(<) :: Integer -> Integer -> Bool

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

(>) :: Integer -> Integer -> Bool

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

max :: Integer -> Integer -> Integer

min :: Integer -> Integer -> Integer

newtype Number Source #

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

Instances details
Floating Number 
Instance details

Defined in Lua.Types

RealFloat Number 
Instance details

Defined in Lua.Types

Methods

floatRadix :: Number -> Integer

floatDigits :: Number -> Int

floatRange :: Number -> (Int, Int)

decodeFloat :: Number -> (Integer, Int)

encodeFloat :: Integer -> Int -> Number

exponent :: Number -> Int

significand :: Number -> Number

scaleFloat :: Int -> Number -> Number

isNaN :: Number -> Bool

isInfinite :: Number -> Bool

isDenormalized :: Number -> Bool

isNegativeZero :: Number -> Bool

isIEEE :: Number -> Bool

atan2 :: Number -> Number -> Number

Num Number 
Instance details

Defined in Lua.Types

Read Number 
Instance details

Defined in Lua.Types

Methods

readsPrec :: Int -> ReadS Number

readList :: ReadS [Number]

readPrec :: ReadPrec Number

readListPrec :: ReadPrec [Number]

Fractional Number 
Instance details

Defined in Lua.Types

Methods

(/) :: Number -> Number -> Number

recip :: Number -> Number

fromRational :: Rational -> Number

Real Number 
Instance details

Defined in Lua.Types

Methods

toRational :: Number -> Rational

RealFrac Number 
Instance details

Defined in Lua.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 Lua.Types

Methods

showsPrec :: Int -> Number -> ShowS

show :: Number -> String

showList :: [Number] -> ShowS

Eq Number 
Instance details

Defined in Lua.Types

Methods

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

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

Ord Number 
Instance details

Defined in Lua.Types

Methods

compare :: Number -> Number -> Ordering

(<) :: Number -> Number -> Bool

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

(>) :: Number -> Number -> Bool

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

max :: Number -> Number -> Number

min :: Number -> Number -> Number

newtype StackIndex Source #

A stack index

Constructors

StackIndex 

Fields

Instances

Instances details
Enum StackIndex 
Instance details

Defined in Lua.Types

Num StackIndex 
Instance details

Defined in Lua.Types

Show StackIndex 
Instance details

Defined in Lua.Types

Methods

showsPrec :: Int -> StackIndex -> ShowS

show :: StackIndex -> String

showList :: [StackIndex] -> ShowS

Eq StackIndex 
Instance details

Defined in Lua.Types

Methods

(==) :: StackIndex -> StackIndex -> Bool

(/=) :: StackIndex -> StackIndex -> Bool

Ord StackIndex 
Instance details

Defined in Lua.Types

registryindex :: StackIndex Source #

Pseudo stack index of the Lua registry.

newtype NumArgs Source #

The number of arguments consumed curing a function call.

Constructors

NumArgs 

Fields

Instances

Instances details
Num NumArgs 
Instance details

Defined in Lua.Types

Show NumArgs 
Instance details

Defined in Lua.Types

Methods

showsPrec :: Int -> NumArgs -> ShowS

show :: NumArgs -> String

showList :: [NumArgs] -> ShowS

Eq NumArgs 
Instance details

Defined in Lua.Types

Methods

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

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

Ord NumArgs 
Instance details

Defined in Lua.Types

Methods

compare :: NumArgs -> NumArgs -> Ordering

(<) :: NumArgs -> NumArgs -> Bool

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

(>) :: NumArgs -> NumArgs -> Bool

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

max :: NumArgs -> NumArgs -> NumArgs

min :: NumArgs -> NumArgs -> NumArgs

newtype NumResults Source #

The number of results returned by a function call.

Constructors

NumResults 

Fields

Instances

Instances details
Num NumResults 
Instance details

Defined in Lua.Types

Show NumResults 
Instance details

Defined in Lua.Types

Methods

showsPrec :: Int -> NumResults -> ShowS

show :: NumResults -> String

showList :: [NumResults] -> ShowS

Eq NumResults 
Instance details

Defined in Lua.Types

Methods

(==) :: NumResults -> NumResults -> Bool

(/=) :: NumResults -> NumResults -> Bool

Ord NumResults 
Instance details

Defined in Lua.Types

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

fromRelationalOperator :: RelationalOperator -> OPCode Source #

Convert relation operator to its C representation.

data Status Source #

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.

ErrFile

opening or reading a file failed.

Instances

Instances details
Show Status Source # 
Instance details

Defined in HsLua.Core.Types

Methods

showsPrec :: Int -> Status -> ShowS

show :: Status -> String

showList :: [Status] -> ShowS

Eq Status Source # 
Instance details

Defined in HsLua.Core.Types

Methods

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

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

toStatus :: StatusCode -> Status Source #

Convert C integer constant to Status.

References

data Reference Source #

Reference to a stored value.

Constructors

Reference CInt

Reference to a stored value

RefNil

Reference to a nil value

Instances

Instances details
Show Reference 
Instance details

Defined in Lua.Auxiliary

Methods

showsPrec :: Int -> Reference -> ShowS

show :: Reference -> String

showList :: [Reference] -> ShowS

Eq Reference 
Instance details

Defined in Lua.Auxiliary

Methods

(==) :: Reference -> Reference -> Bool

(/=) :: Reference -> Reference -> Bool

fromReference :: Reference -> CInt Source #

Convert a reference to its C representation.

toReference :: CInt -> Reference Source #

Create a reference from its C representation.

noref :: Int Source #

Value signaling that no reference was found.

refnil :: Int Source #

Value signaling that no reference was created.

Stack index helpers

nthTop :: CInt -> StackIndex Source #

Stack index of the nth element from the top of the stack.

Since: lua-2.0.0

nthBottom :: CInt -> StackIndex Source #

Stack index of the nth element from the bottom of the stack.

Since: lua-2.0.0

nth :: CInt -> StackIndex Source #

Alias for nthTop.

Since: lua-2.0.0

top :: StackIndex Source #

Index of the topmost stack element.

Since: lua-2.0.0

Table field names

newtype Name Source #

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.

Constructors

Name 

Fields

Instances

Instances details
IsString Name Source # 
Instance details

Defined in HsLua.Core.Types

Methods

fromString :: String -> Name

Semigroup Name Source # 
Instance details

Defined in HsLua.Core.Types

Methods

(<>) :: Name -> Name -> Name

sconcat :: NonEmpty Name -> Name

stimes :: Integral b => b -> Name -> Name

Show Name Source # 
Instance details

Defined in HsLua.Core.Types

Methods

showsPrec :: Int -> Name -> ShowS

show :: Name -> String

showList :: [Name] -> ShowS

Eq Name Source # 
Instance details

Defined in HsLua.Core.Types

Methods

(==) :: Name -> Name -> Bool

(/=) :: Name -> Name -> Bool

Ord Name Source # 
Instance details

Defined in HsLua.Core.Types

Methods

compare :: Name -> Name -> Ordering

(<) :: Name -> Name -> Bool

(<=) :: Name -> Name -> Bool

(>) :: Name -> Name -> Bool

(>=) :: Name -> Name -> Bool

max :: Name -> Name -> Name

min :: Name -> Name -> Name