{-# LINE 1 "src/Foreign/Lua/Raw/Types.hsc" #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Foreign.Lua.Raw.Types
( State (..)
, Reader
, GCCONTROL (..)
, Type (..)
, TypeCode (..)
, fromType
, toType
, CFunction
, LuaBool (..)
, false
, true
, fromLuaBool
, toLuaBool
, Integer (..)
, Number (..)
, StackIndex (..)
, NumArgs (..)
, NumResults (..)
, RelationalOperator (..)
, fromRelationalOperator
, Status (..)
, StatusCode (..)
, toStatus
) where
import Prelude hiding (Integer, EQ, LT)
import Data.Int (Int64)
{-# LINE 48 "src/Foreign/Lua/Raw/Types.hsc" #-}
import Foreign.C (CChar, CInt, CSize)
import Foreign.Ptr (FunPtr, Ptr)
import Foreign.Storable (Storable)
import GHC.Generics (Generic)
newtype State = State (Ptr ()) deriving (Eq, Generic)
type CFunction = FunPtr (State -> IO NumResults)
type Reader = FunPtr (State -> Ptr () -> Ptr CSize -> IO (Ptr CChar))
newtype Integer = Integer Int64
{-# LINE 99 "src/Foreign/Lua/Raw/Types.hsc" #-}
deriving (Bounded, Enum, Eq, Integral, Num, Ord, Real, Show)
newtype Number = Number Double
{-# LINE 108 "src/Foreign/Lua/Raw/Types.hsc" #-}
deriving (Eq, Floating, Fractional, Num, Ord, Real, RealFloat, RealFrac, Show)
newtype LuaBool = LuaBool CInt
deriving (Eq, Storable, Show)
true :: LuaBool
true = LuaBool 1
false :: LuaBool
false = LuaBool 0
fromLuaBool :: LuaBool -> Bool
fromLuaBool (LuaBool 0) = False
fromLuaBool _ = True
{-# INLINABLE fromLuaBool #-}
toLuaBool :: Bool -> LuaBool
toLuaBool True = true
toLuaBool False = false
{-# INLINABLE toLuaBool #-}
data Type
= TypeNone
| TypeNil
| TypeBoolean
| TypeLightUserdata
| TypeNumber
| TypeString
| TypeTable
| TypeFunction
| TypeUserdata
| TypeThread
deriving (Bounded, Eq, Ord, Show)
newtype TypeCode = TypeCode { fromTypeCode :: CInt }
deriving (Eq, Ord, Show)
instance Enum Type where
fromEnum = fromIntegral . fromTypeCode . fromType
toEnum = toType . TypeCode . fromIntegral
fromType :: Type -> TypeCode
fromType tp = TypeCode $ case tp of
TypeNone -> -1
{-# LINE 172 "src/Foreign/Lua/Raw/Types.hsc" #-}
TypeNil -> 0
{-# LINE 173 "src/Foreign/Lua/Raw/Types.hsc" #-}
TypeBoolean -> 1
{-# LINE 174 "src/Foreign/Lua/Raw/Types.hsc" #-}
TypeLightUserdata -> 2
{-# LINE 175 "src/Foreign/Lua/Raw/Types.hsc" #-}
TypeNumber -> 3
{-# LINE 176 "src/Foreign/Lua/Raw/Types.hsc" #-}
TypeString -> 4
{-# LINE 177 "src/Foreign/Lua/Raw/Types.hsc" #-}
TypeTable -> 5
{-# LINE 178 "src/Foreign/Lua/Raw/Types.hsc" #-}
TypeFunction -> 6
{-# LINE 179 "src/Foreign/Lua/Raw/Types.hsc" #-}
TypeUserdata -> 7
{-# LINE 180 "src/Foreign/Lua/Raw/Types.hsc" #-}
TypeThread -> 8
{-# LINE 181 "src/Foreign/Lua/Raw/Types.hsc" #-}
toType :: TypeCode -> Type
toType (TypeCode c) = case c of
-1 -> TypeNone
{-# LINE 186 "src/Foreign/Lua/Raw/Types.hsc" #-}
0 -> TypeNil
{-# LINE 187 "src/Foreign/Lua/Raw/Types.hsc" #-}
1 -> TypeBoolean
{-# LINE 188 "src/Foreign/Lua/Raw/Types.hsc" #-}
2 -> TypeLightUserdata
{-# LINE 189 "src/Foreign/Lua/Raw/Types.hsc" #-}
3 -> TypeNumber
{-# LINE 190 "src/Foreign/Lua/Raw/Types.hsc" #-}
4 -> TypeString
{-# LINE 191 "src/Foreign/Lua/Raw/Types.hsc" #-}
5 -> TypeTable
{-# LINE 192 "src/Foreign/Lua/Raw/Types.hsc" #-}
6 -> TypeFunction
{-# LINE 193 "src/Foreign/Lua/Raw/Types.hsc" #-}
7 -> TypeUserdata
{-# LINE 194 "src/Foreign/Lua/Raw/Types.hsc" #-}
8 -> TypeThread
{-# LINE 195 "src/Foreign/Lua/Raw/Types.hsc" #-}
_ -> error ("No Type corresponding to " ++ show c)
data RelationalOperator
= EQ
| LT
| LE
deriving (Eq, Ord, Show)
fromRelationalOperator :: RelationalOperator -> CInt
fromRelationalOperator EQ = 0
{-# LINE 211 "src/Foreign/Lua/Raw/Types.hsc" #-}
fromRelationalOperator LT = 1
{-# LINE 212 "src/Foreign/Lua/Raw/Types.hsc" #-}
fromRelationalOperator LE = 2
{-# LINE 213 "src/Foreign/Lua/Raw/Types.hsc" #-}
{-# INLINABLE fromRelationalOperator #-}
data Status
= OK
| Yield
| ErrRun
| ErrSyntax
| ErrMem
| ErrErr
| ErrGcmm
| ErrFile
deriving (Eq, Show)
toStatus :: StatusCode -> Status
toStatus (StatusCode c) = case c of
0 -> OK
{-# LINE 236 "src/Foreign/Lua/Raw/Types.hsc" #-}
1 -> Yield
{-# LINE 237 "src/Foreign/Lua/Raw/Types.hsc" #-}
2 -> ErrRun
{-# LINE 238 "src/Foreign/Lua/Raw/Types.hsc" #-}
3 -> ErrSyntax
{-# LINE 239 "src/Foreign/Lua/Raw/Types.hsc" #-}
4 -> ErrMem
{-# LINE 240 "src/Foreign/Lua/Raw/Types.hsc" #-}
5 -> ErrGcmm
{-# LINE 241 "src/Foreign/Lua/Raw/Types.hsc" #-}
6 -> ErrErr
{-# LINE 242 "src/Foreign/Lua/Raw/Types.hsc" #-}
7 -> ErrFile
{-# LINE 243 "src/Foreign/Lua/Raw/Types.hsc" #-}
n -> error $ "Cannot convert (" ++ show n ++ ") to Status"
{-# INLINABLE toStatus #-}
newtype StatusCode = StatusCode CInt deriving (Eq, Storable)
data GCCONTROL
= GCSTOP
| GCRESTART
| GCCOLLECT
| GCCOUNT
| GCCOUNTB
| GCSTEP
| GCSETPAUSE
| GCSETSTEPMUL
deriving (Enum, Eq, Ord, Show)
newtype StackIndex = StackIndex { fromStackIndex :: CInt }
deriving (Enum, Eq, Num, Ord, Show)
newtype NumArgs = NumArgs { fromNumArgs :: CInt }
deriving (Eq, Num, Ord, Show)
newtype NumResults = NumResults { fromNumResults :: CInt }
deriving (Eq, Num, Ord, Show)