hslua-core-2.0.0: Bindings to Lua, an embeddable scripting language
Copyright© 2007–2012 Gracjan Polak;
© 2012–2016 Ömer Sinan Ağacan;
© 2017-2021 Albert Krewinkel
LicenseMIT
MaintainerAlbert Krewinkel <tarleb+hslua@zeitkraut.de>
Stabilitybeta
Portabilitynon-portable (depends on GHC)
Safe HaskellNone
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 

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 #

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 #

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 #

LuaError e => MonadFail (LuaE e) Source # 
Instance details

Defined in HsLua.Core.Error

Methods

fail :: String -> 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 #

MonadIO (LuaE e) Source # 
Instance details

Defined in HsLua.Core.Types

Methods

liftIO :: IO a -> LuaE e a #

LuaError e => Alternative (LuaE e) Source # 
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] #

MonadThrow (LuaE e) Source # 
Instance details

Defined in HsLua.Core.Types

Methods

throwM :: Exception e0 => e0 -> 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) #

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 #

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
Eq State 
Instance details

Defined in Lua.Types

Methods

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

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

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 #

type Rep State 
Instance details

Defined in Lua.Types

type Rep State = D1 ('MetaData "State" "Lua.Types" "lua-2.0.0-HcVFHRFdpa64irxzXOMNZJ" '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 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

performs an incremental step of garbage collection.

GCSetPause CInt

sets data as the new value for the pause of the collector (see <https://www.lua.org/manual/5.3/manual.html#2.5 §2.5> of the Lua reference manual) and returns the previous value of the pause.

GCSetStepMul CInt

sets data as the new value for the step multiplier of the collector (see <https://www.lua.org/manual/5.3/manual.html#2.5 §2.5> of the Lua reference manual) and returns the previous value of the step multiplier.

GCIsRunning

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

Instances

Instances details
Eq GCControl Source # 
Instance details

Defined in HsLua.Core.Types

Ord GCControl Source # 
Instance details

Defined in HsLua.Core.Types

Show GCControl Source # 
Instance details

Defined in HsLua.Core.Types

toGCcode :: GCControl -> GCCode Source #

Converts a GCControl command to its corresponding code.

toGCdata :: GCControl -> 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] #

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 #

Show Type Source # 
Instance details

Defined in HsLua.Core.Types

Methods

showsPrec :: Int -> Type -> ShowS #

show :: Type -> String #

showList :: [Type] -> ShowS #

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 #

Lift a computation from the IO monad.

type CFunction = FunPtr PreCFunction #

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 #

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 #

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
Eq LuaBool 
Instance details

Defined in Lua.Types

Methods

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

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

Show LuaBool 
Instance details

Defined in Lua.Types

Storable LuaBool 
Instance details

Defined in Lua.Types

fromLuaBool :: LuaBool -> Bool Source #

Convert a LuaBool to a Haskell Bool.

toLuaBool :: Bool -> LuaBool Source #

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

Instances details
Bounded Integer 
Instance details

Defined in Lua.Types

Enum Integer 
Instance details

Defined in Lua.Types

Eq Integer 
Instance details

Defined in Lua.Types

Methods

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

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

Integral Integer 
Instance details

Defined in Lua.Types

Num Integer 
Instance details

Defined in Lua.Types

Ord Integer 
Instance details

Defined in Lua.Types

Real Integer 
Instance details

Defined in Lua.Types

Show Integer 
Instance details

Defined in Lua.Types

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

Instances details
Eq Number 
Instance details

Defined in Lua.Types

Methods

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

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

Floating Number 
Instance details

Defined in Lua.Types

Fractional Number 
Instance details

Defined in Lua.Types

Num Number 
Instance details

Defined in Lua.Types

Ord Number 
Instance details

Defined in Lua.Types

Real Number 
Instance details

Defined in Lua.Types

RealFloat Number 
Instance details

Defined in Lua.Types

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

newtype StackIndex #

A stack index

Constructors

StackIndex 

Fields

registryindex :: StackIndex Source #

Pseudo stack index of the Lua registry.

newtype NumArgs #

The number of arguments consumed curing a function call.

Constructors

NumArgs 

Fields

Instances

Instances details
Eq NumArgs 
Instance details

Defined in Lua.Types

Methods

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

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

Num NumArgs 
Instance details

Defined in Lua.Types

Ord NumArgs 
Instance details

Defined in Lua.Types

Show NumArgs 
Instance details

Defined in Lua.Types

newtype NumResults #

The number of results returned by a function call.

Constructors

NumResults 

Fields

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.

ErrGcmm

error while running a __gc metamethod.

ErrFile

opening or reading a file failed.

Instances

Instances details
Eq Status Source # 
Instance details

Defined in HsLua.Core.Types

Methods

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

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

Show Status Source # 
Instance details

Defined in HsLua.Core.Types

toStatus :: StatusCode -> Status Source #

Convert C integer constant to Status.

References

data Reference #

Reference to a stored value.

Constructors

Reference CInt

Reference to a stored value

RefNil

Reference to a nil value

Instances

Instances details
Eq Reference 
Instance details

Defined in Lua.Auxiliary

Show Reference 
Instance details

Defined in Lua.Auxiliary

fromReference :: Reference -> CInt #

Convert a reference to its C representation.

toReference :: CInt -> Reference #

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 #

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

Since: lua-2.0.0

nthBottom :: CInt -> StackIndex #

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

Since: lua-2.0.0

nth :: CInt -> StackIndex #

Alias for nthTop.

Since: lua-2.0.0

top :: StackIndex #

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

Show Name Source # 
Instance details

Defined in HsLua.Core.Types

Methods

showsPrec :: Int -> Name -> ShowS #

show :: Name -> String #

showList :: [Name] -> ShowS #

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 #