-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Bindings to Lua, an embeddable scripting language -- -- HsLua provides bindings, wrappers, types, and helper functions to -- bridge Haskell and Lua. -- -- This package contains a full Lua interpreter version 5.3.6. If you -- want to link it with a system-wide Lua installation, use the -- system-lua flag. -- -- Example programs are available in a separate repository. @package hslua @version 1.3.0.1 -- | The core Lua types, including mappings of Lua types to Haskell. module Foreign.Lua.Raw.Types -- | 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. newtype State State :: Ptr () -> State -- | 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. type Reader = FunPtr (State -> Ptr () -> Ptr CSize -> IO (Ptr CChar)) -- | Enumeration used by gc function. data GCCONTROL GCSTOP :: GCCONTROL GCRESTART :: GCCONTROL GCCOLLECT :: GCCONTROL GCCOUNT :: GCCONTROL GCCOUNTB :: GCCONTROL GCSTEP :: GCCONTROL GCSETPAUSE :: GCCONTROL GCSETSTEPMUL :: GCCONTROL -- | Enumeration used as type tag. See lua_type. data Type -- | non-valid stack index TypeNone :: Type -- | type of lua's nil value TypeNil :: Type -- | type of lua booleans TypeBoolean :: Type -- | type of light userdata TypeLightUserdata :: Type -- | type of lua numbers. See Number TypeNumber :: Type -- | type of lua string values TypeString :: Type -- | type of lua tables TypeTable :: Type -- | type of functions, either normal or CFunction TypeFunction :: Type -- | type of full user data TypeUserdata :: Type -- | type of lua threads TypeThread :: Type -- | Integer code used to encode the type of a lua value. newtype TypeCode TypeCode :: CInt -> TypeCode [fromTypeCode] :: TypeCode -> CInt -- | Convert a lua Type to a type code which can be passed to the C API. fromType :: Type -> TypeCode -- | Convert numerical code to lua type. toType :: TypeCode -> Type -- | 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. type CFunction = FunPtr (State -> IO NumResults) -- | Boolean value returned by a Lua C API function. This is a -- CInt and interpreted as False iff the -- value is 0, True otherwise. newtype LuaBool LuaBool :: CInt -> LuaBool -- | Lua representation of the value interpreted as false. false :: LuaBool -- | Generic Lua representation of a value interpreted as being true. true :: LuaBool -- | Convert a LuaBool to a Haskell Bool. fromLuaBool :: LuaBool -> Bool -- | Convert a Haskell Bool to a LuaBool. toLuaBool :: Bool -> LuaBool -- | 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. newtype Integer Integer :: Int64 -> Integer -- | 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. newtype Number Number :: Double -> Number -- | A stack index newtype StackIndex StackIndex :: CInt -> StackIndex [fromStackIndex] :: StackIndex -> CInt -- | The number of arguments consumed curing a function call. newtype NumArgs NumArgs :: CInt -> NumArgs [fromNumArgs] :: NumArgs -> CInt -- | The number of results returned by a function call. newtype NumResults NumResults :: CInt -> NumResults [fromNumResults] :: NumResults -> CInt -- | Lua comparison operations. data RelationalOperator -- | Correponds to lua's equality (==) operator. EQ :: RelationalOperator -- | Correponds to lua's strictly-lesser-than (<) operator LT :: RelationalOperator -- | Correponds to lua's lesser-or-equal (<=) operator LE :: RelationalOperator -- | Convert relation operator to its C representation. fromRelationalOperator :: RelationalOperator -> CInt -- | Lua status values. data Status -- | success OK :: Status -- | yielding / suspended coroutine Yield :: Status -- | a runtime rror ErrRun :: Status -- | syntax error during precompilation ErrSyntax :: Status -- | memory allocation (out-of-memory) error. ErrMem :: Status -- | error while running the message handler. ErrErr :: Status -- | error while running a __gc metamethod. ErrGcmm :: Status -- | opening or reading a file failed. ErrFile :: Status -- | Integer code used to signal the status of a thread or computation. See -- Status. newtype StatusCode StatusCode :: CInt -> StatusCode -- | Convert C integer constant to Status. toStatus :: StatusCode -> Status instance GHC.Generics.Generic Foreign.Lua.Raw.Types.State instance GHC.Classes.Eq Foreign.Lua.Raw.Types.State instance GHC.Show.Show Foreign.Lua.Raw.Types.Integer instance GHC.Real.Real Foreign.Lua.Raw.Types.Integer instance GHC.Classes.Ord Foreign.Lua.Raw.Types.Integer instance GHC.Num.Num Foreign.Lua.Raw.Types.Integer instance GHC.Real.Integral Foreign.Lua.Raw.Types.Integer instance GHC.Classes.Eq Foreign.Lua.Raw.Types.Integer instance GHC.Enum.Enum Foreign.Lua.Raw.Types.Integer instance GHC.Enum.Bounded Foreign.Lua.Raw.Types.Integer instance GHC.Show.Show Foreign.Lua.Raw.Types.Number instance GHC.Real.RealFrac Foreign.Lua.Raw.Types.Number instance GHC.Float.RealFloat Foreign.Lua.Raw.Types.Number instance GHC.Real.Real Foreign.Lua.Raw.Types.Number instance GHC.Classes.Ord Foreign.Lua.Raw.Types.Number instance GHC.Num.Num Foreign.Lua.Raw.Types.Number instance GHC.Real.Fractional Foreign.Lua.Raw.Types.Number instance GHC.Float.Floating Foreign.Lua.Raw.Types.Number instance GHC.Classes.Eq Foreign.Lua.Raw.Types.Number instance GHC.Show.Show Foreign.Lua.Raw.Types.LuaBool instance Foreign.Storable.Storable Foreign.Lua.Raw.Types.LuaBool instance GHC.Classes.Eq Foreign.Lua.Raw.Types.LuaBool instance GHC.Show.Show Foreign.Lua.Raw.Types.Type instance GHC.Classes.Ord Foreign.Lua.Raw.Types.Type instance GHC.Classes.Eq Foreign.Lua.Raw.Types.Type instance GHC.Enum.Bounded Foreign.Lua.Raw.Types.Type instance GHC.Show.Show Foreign.Lua.Raw.Types.TypeCode instance GHC.Classes.Ord Foreign.Lua.Raw.Types.TypeCode instance GHC.Classes.Eq Foreign.Lua.Raw.Types.TypeCode instance GHC.Show.Show Foreign.Lua.Raw.Types.RelationalOperator instance GHC.Classes.Ord Foreign.Lua.Raw.Types.RelationalOperator instance GHC.Classes.Eq Foreign.Lua.Raw.Types.RelationalOperator instance GHC.Show.Show Foreign.Lua.Raw.Types.Status instance GHC.Classes.Eq Foreign.Lua.Raw.Types.Status instance Foreign.Storable.Storable Foreign.Lua.Raw.Types.StatusCode instance GHC.Classes.Eq Foreign.Lua.Raw.Types.StatusCode instance GHC.Show.Show Foreign.Lua.Raw.Types.GCCONTROL instance GHC.Classes.Ord Foreign.Lua.Raw.Types.GCCONTROL instance GHC.Classes.Eq Foreign.Lua.Raw.Types.GCCONTROL instance GHC.Enum.Enum Foreign.Lua.Raw.Types.GCCONTROL instance GHC.Show.Show Foreign.Lua.Raw.Types.StackIndex instance GHC.Classes.Ord Foreign.Lua.Raw.Types.StackIndex instance GHC.Num.Num Foreign.Lua.Raw.Types.StackIndex instance GHC.Classes.Eq Foreign.Lua.Raw.Types.StackIndex instance GHC.Enum.Enum Foreign.Lua.Raw.Types.StackIndex instance GHC.Show.Show Foreign.Lua.Raw.Types.NumArgs instance GHC.Classes.Ord Foreign.Lua.Raw.Types.NumArgs instance GHC.Num.Num Foreign.Lua.Raw.Types.NumArgs instance GHC.Classes.Eq Foreign.Lua.Raw.Types.NumArgs instance GHC.Show.Show Foreign.Lua.Raw.Types.NumResults instance GHC.Classes.Ord Foreign.Lua.Raw.Types.NumResults instance GHC.Num.Num Foreign.Lua.Raw.Types.NumResults instance GHC.Classes.Eq Foreign.Lua.Raw.Types.NumResults instance GHC.Enum.Enum Foreign.Lua.Raw.Types.Type -- | Haskell bindings to Lua C API functions. module Foreign.Lua.Raw.Functions -- | See lua_close lua_close :: State -> IO () -- | See lua_absindex lua_absindex :: State -> StackIndex -> IO StackIndex -- | See lua_gettop lua_gettop :: State -> IO StackIndex -- | See lua_settop lua_settop :: State -> StackIndex -> IO () -- | See lua_pushvalue lua_pushvalue :: State -> StackIndex -> IO () -- | See lua_pop lua_pop :: State -> StackIndex -> IO () -- | See lua_copy lua_copy :: State -> StackIndex -> StackIndex -> IO () -- | See lua_remove lua_remove :: State -> StackIndex -> IO () -- | See lua_insert lua_insert :: State -> StackIndex -> IO () -- | See lua_replace lua_replace :: State -> StackIndex -> IO () -- | See lua_checkstack lua_checkstack :: State -> CInt -> IO LuaBool -- | See lua_isnumber lua_isnumber :: State -> StackIndex -> IO LuaBool -- | See lua_isinteger lua_isinteger :: State -> StackIndex -> IO LuaBool -- | See lua_isstring lua_isstring :: State -> StackIndex -> IO LuaBool -- | See lua_iscfunction lua_iscfunction :: State -> StackIndex -> IO LuaBool -- | See lua_isuserdata lua_isuserdata :: State -> StackIndex -> IO LuaBool -- | See lua_type lua_type :: State -> StackIndex -> IO TypeCode -- | See lua_typename lua_typename :: State -> TypeCode -> IO CString -- | Wrapper around -- @lua_compare@ which catches any -- longjmps. hslua_compare :: State -> StackIndex -> StackIndex -> CInt -> Ptr StatusCode -> IO LuaBool -- | See lua_rawequal lua_rawequal :: State -> StackIndex -> StackIndex -> IO LuaBool -- | See lua_toboolean lua_toboolean :: State -> StackIndex -> IO LuaBool -- | See lua_tocfunction lua_tocfunction :: State -> StackIndex -> IO CFunction -- | See lua_tointegerx lua_tointegerx :: State -> StackIndex -> Ptr LuaBool -> IO Integer -- | See lua_tonumberx lua_tonumberx :: State -> StackIndex -> Ptr LuaBool -> IO Number -- | See lua_tolstring lua_tolstring :: State -> StackIndex -> Ptr CSize -> IO (Ptr CChar) -- | See lua_topointer lua_topointer :: State -> StackIndex -> IO (Ptr ()) -- | See lua_tothread lua_tothread :: State -> StackIndex -> IO State -- | See lua_touserdata lua_touserdata :: State -> StackIndex -> IO (Ptr a) -- | See lua_rawlen lua_rawlen :: State -> StackIndex -> IO CSize -- | See lua_pushnil lua_pushnil :: State -> IO () -- | See lua_pushnumber lua_pushnumber :: State -> Number -> IO () -- | See lua_pushinteger lua_pushinteger :: State -> Integer -> IO () -- | See lua_pushlstring lua_pushlstring :: State -> Ptr CChar -> CSize -> IO () -- | See lua_pushcclosure lua_pushcclosure :: State -> CFunction -> NumArgs -> IO () -- | See lua_pushboolean lua_pushboolean :: State -> LuaBool -> IO () -- | See lua_pushlightuserdata lua_pushlightuserdata :: State -> Ptr a -> IO () -- | See lua_pushthread lua_pushthread :: State -> IO CInt -- | Wrapper around -- @lua_gettable@ which catches any -- longjmps. hslua_gettable :: State -> StackIndex -> Ptr StatusCode -> IO () -- | See lua_rawget lua_rawget :: State -> StackIndex -> IO () -- | See lua_rawgeti lua_rawgeti :: State -> StackIndex -> Integer -> IO () -- | See lua_createtable lua_createtable :: State -> CInt -> CInt -> IO () -- | See lua_newuserdata lua_newuserdata :: State -> CSize -> IO (Ptr ()) -- | See lua_getmetatable lua_getmetatable :: State -> StackIndex -> IO LuaBool -- | Wrapper around -- @lua_getglobal@ which catches any -- longjmps. hslua_getglobal :: State -> CString -> CSize -> Ptr StatusCode -> IO () -- | Wrapper around -- @lua_settable@ which catches any -- longjmps. hslua_settable :: State -> StackIndex -> Ptr StatusCode -> IO () -- | See lua_rawset lua_rawset :: State -> StackIndex -> IO () -- | See lua_rawseti lua_rawseti :: State -> StackIndex -> Integer -> IO () -- | See lua_setmetatable lua_setmetatable :: State -> StackIndex -> IO () -- | Wrapper around -- @lua_setglobal@ which catches any -- longjmps. hslua_setglobal :: State -> CString -> CSize -> Ptr StatusCode -> IO () -- | See lua_pcall lua_pcall :: State -> NumArgs -> NumResults -> StackIndex -> IO StatusCode -- | See lua_load lua_load :: State -> Reader -> Ptr () -> CString -> CString -> IO StatusCode -- | See lua_status lua_status :: State -> IO StatusCode -- | See lua_gc lua_gc :: State -> CInt -> CInt -> IO CInt -- | Replacement for -- @lua_error@; it uses the HsLua error -- signaling convention instead of raw hslua_error :: State -> IO NumResults -- | Wrapper around -- @lua_next@ which catches any -- longjmps. hslua_next :: State -> StackIndex -> Ptr StatusCode -> IO LuaBool -- | Wrapper around -- @lua_concat@ which catches any -- longjmps. hslua_concat :: State -> NumArgs -> Ptr StatusCode -> IO () -- | See -- lua_pushglobaltable lua_pushglobaltable :: State -> IO () -- | See luaL_openlibs luaL_openlibs :: State -> IO () -- | Point to function opening the base library. lua_open_base_ptr :: CFunction -- | Point to function opening the table library. lua_open_table_ptr :: CFunction -- | Point to function opening the io library. lua_open_io_ptr :: CFunction -- | Point to function opening the os library. lua_open_os_ptr :: CFunction -- | Point to function opening the string library. lua_open_string_ptr :: CFunction -- | Point to function opening the math library. lua_open_math_ptr :: CFunction -- | Point to function opening the debug library. lua_open_debug_ptr :: CFunction -- | Point to function opening the package library. lua_open_package_ptr :: CFunction -- | Haskell bindings to Lua C API functions. -- -- This module was moved to Functions. It now merely -- exists for backwards compatibility and will be removed in the future. module Foreign.Lua.Core.RawBindings -- | Lua constants module Foreign.Lua.Raw.Constants -- | Alias for C constant LUA_MULTRET. See lua_call. multret :: NumResults -- | Alias for C constant LUA_REGISTRYINDEX. See Lua -- registry. registryindex :: StackIndex -- | Value signaling that no reference was created. refnil :: Int -- | Value signaling that no reference was found. noref :: Int -- | Lua constants. This module was moved to Constants. It -- now merely exists for backwards compatibility and will be removed in -- the future. module Foreign.Lua.Core.Constants -- | Alias for C constant LUA_MULTRET. See lua_call. multret :: NumResults -- | Alias for C constant LUA_REGISTRYINDEX. See Lua -- registry. registryindex :: StackIndex -- | Value signaling that no reference was created. refnil :: Int -- | Value signaling that no reference was found. noref :: Int -- | Raw bindings to function call helpers. module Foreign.Lua.Raw.Call -- | Type of raw Haskell functions that can be made into -- CFunctions. type HsFunction = State -> IO NumResults -- | Pushes a new C function created from an HsFunction. hslua_newhsfunction :: State -> StablePtr a -> IO () hslua_pushhsfunction :: State -> HsFunction -> IO () -- | Raw bindings to functions and constants of the auxiliary library. module Foreign.Lua.Raw.Auxiliary hsluaL_newstate :: IO State hsluaL_tolstring :: State -> StackIndex -> Ptr CSize -> IO (Ptr CChar) luaL_getmetafield :: State -> StackIndex -> CString -> IO TypeCode luaL_getmetatable :: State -> CString -> IO TypeCode luaL_loadbuffer :: State -> Ptr CChar -> CSize -> CString -> IO StatusCode luaL_newmetatable :: State -> CString -> IO LuaBool luaL_ref :: State -> StackIndex -> IO CInt -- | See luaL_testudata luaL_testudata :: State -> StackIndex -> CString -> IO (Ptr ()) luaL_traceback :: State -> State -> CString -> CInt -> IO () luaL_unref :: State -> StackIndex -> CInt -> IO () -- | Key, in the registry, for table of loaded modules. loadedTableRegistryField :: String -- | Key, in the registry, for table of preloaded loaders. preloadTableRegistryField :: String -- | Reference to a stored value. data Reference -- | Reference to a stored value Reference :: CInt -> Reference -- | Reference to a nil value RefNil :: Reference -- | Convert a reference to its C representation. fromReference :: Reference -> CInt -- | Create a reference from its C representation. toReference :: CInt -> Reference instance GHC.Show.Show Foreign.Lua.Raw.Auxiliary.Reference instance GHC.Classes.Eq Foreign.Lua.Raw.Auxiliary.Reference -- | Lua exceptions and exception handling. module Foreign.Lua.Raw.Error -- | Retrieve and pop the top object as an error message. This is very -- similar to tostring', but ensures that we don't recurse if getting the -- message failed. errorMessage :: State -> IO ByteString -- | 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. module Foreign.Lua.Core.Types -- | 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. newtype Lua a Lua :: ReaderT LuaEnvironment IO a -> Lua a [unLua] :: Lua a -> ReaderT LuaEnvironment IO a -- | Environment in which Lua computations are evaluated. data LuaEnvironment LuaEnvironment :: ErrorConversion -> State -> LuaEnvironment -- | Functions for error and exception handling and conversion [luaEnvErrorConversion] :: LuaEnvironment -> ErrorConversion -- | Lua interpreter state [luaEnvState] :: LuaEnvironment -> State -- | Define the ways in which exceptions and errors are handled. data ErrorConversion ErrorConversion :: (forall a. State -> IO a) -> (forall a. String -> Lua a -> Lua a) -> (forall a. Lua a -> Lua a -> Lua a) -> (Lua NumResults -> Lua NumResults) -> ErrorConversion -- | Translate Lua errors to Haskell exceptions [errorToException] :: ErrorConversion -> forall a. State -> IO a -- | Add information on the current context to an exception. [addContextToException] :: ErrorConversion -> forall a. String -> Lua a -> Lua a -- | Runs the second computation only if the first fails; returns the -- result of the first successful computation, if any. [alternative] :: ErrorConversion -> forall a. Lua a -> Lua a -> Lua a -- | Translate Haskell exceptions to Lua errors [exceptionToError] :: ErrorConversion -> Lua NumResults -> Lua NumResults -- | Get the error-to-exception function. errorConversion :: Lua ErrorConversion -- | 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. newtype State State :: Ptr () -> State -- | 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. type Reader = FunPtr (State -> Ptr () -> Ptr CSize -> IO (Ptr CChar)) -- | Turn a function of typ Lua.State -> IO a into a monadic -- Lua operation. liftLua :: (State -> IO a) -> Lua a -- | Turn a function of typ Lua.State -> a -> IO b into a -- monadic Lua operation. liftLua1 :: (State -> a -> IO b) -> a -> Lua b -- | Get the Lua state of this Lua computation. state :: Lua State -- | Run Lua computation with the given Lua state and error-to-exception -- converter. Any resulting exceptions are left unhandled. runWithConverter :: ErrorConversion -> State -> Lua a -> IO a -- | Run the given operation, but crash if any Haskell exceptions occur. unsafeRunWith :: State -> Lua a -> IO a -- | Unsafe ErrorConversion; no proper error handling is -- attempted, any error leads to a crash. unsafeErrorConversion :: ErrorConversion -- | Enumeration used by gc function. data GCCONTROL GCSTOP :: GCCONTROL GCRESTART :: GCCONTROL GCCOLLECT :: GCCONTROL GCCOUNT :: GCCONTROL GCCOUNTB :: GCCONTROL GCSTEP :: GCCONTROL GCSETPAUSE :: GCCONTROL GCSETSTEPMUL :: GCCONTROL -- | Enumeration used as type tag. See lua_type. data Type -- | non-valid stack index TypeNone :: Type -- | type of lua's nil value TypeNil :: Type -- | type of lua booleans TypeBoolean :: Type -- | type of light userdata TypeLightUserdata :: Type -- | type of lua numbers. See Number TypeNumber :: Type -- | type of lua string values TypeString :: Type -- | type of lua tables TypeTable :: Type -- | type of functions, either normal or CFunction TypeFunction :: Type -- | type of full user data TypeUserdata :: Type -- | type of lua threads TypeThread :: Type -- | Integer code used to encode the type of a lua value. newtype TypeCode TypeCode :: CInt -> TypeCode [fromTypeCode] :: TypeCode -> CInt -- | Convert a lua Type to a type code which can be passed to the C API. fromType :: Type -> TypeCode -- | Convert numerical code to lua type. toType :: TypeCode -> Type -- | Lift a computation from the IO monad. liftIO :: MonadIO m => IO a -> m a -- | 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. type CFunction = FunPtr (State -> IO NumResults) -- | Boolean value returned by a Lua C API function. This is a -- CInt and interpreted as False iff the -- value is 0, True otherwise. newtype LuaBool LuaBool :: CInt -> LuaBool -- | Lua representation of the value interpreted as false. false :: LuaBool -- | Generic Lua representation of a value interpreted as being true. true :: LuaBool -- | Convert a LuaBool to a Haskell Bool. fromLuaBool :: LuaBool -> Bool -- | Convert a Haskell Bool to a LuaBool. toLuaBool :: Bool -> LuaBool -- | 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. newtype Integer Integer :: Int64 -> Integer -- | 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. newtype Number Number :: Double -> Number -- | A stack index newtype StackIndex StackIndex :: CInt -> StackIndex [fromStackIndex] :: StackIndex -> CInt -- | Stack index of the nth element from the top of the stack. nth :: CInt -> StackIndex -- | Stack index of the nth element from the bottom of the stack. nthFromBottom :: CInt -> StackIndex -- | Stack index of the nth element from the top of the stack. nthFromTop :: CInt -> StackIndex -- | Top of the stack stackTop :: StackIndex -- | Bottom of the stack stackBottom :: StackIndex -- | Top of the stack top :: StackIndex -- | The number of arguments consumed curing a function call. newtype NumArgs NumArgs :: CInt -> NumArgs [fromNumArgs] :: NumArgs -> CInt -- | The number of results returned by a function call. newtype NumResults NumResults :: CInt -> NumResults [fromNumResults] :: NumResults -> CInt -- | Lua comparison operations. data RelationalOperator -- | Correponds to lua's equality (==) operator. EQ :: RelationalOperator -- | Correponds to lua's strictly-lesser-than (<) operator LT :: RelationalOperator -- | Correponds to lua's lesser-or-equal (<=) operator LE :: RelationalOperator -- | Convert relation operator to its C representation. fromRelationalOperator :: RelationalOperator -> CInt -- | Lua status values. data Status -- | success OK :: Status -- | yielding / suspended coroutine Yield :: Status -- | a runtime rror ErrRun :: Status -- | syntax error during precompilation ErrSyntax :: Status -- | memory allocation (out-of-memory) error. ErrMem :: Status -- | error while running the message handler. ErrErr :: Status -- | error while running a __gc metamethod. ErrGcmm :: Status -- | opening or reading a file failed. ErrFile :: Status -- | Integer code used to signal the status of a thread or computation. See -- Status. newtype StatusCode StatusCode :: CInt -> StatusCode -- | Convert C integer constant to Status. toStatus :: StatusCode -> Status -- | Reference to a stored value. data Reference -- | Reference to a stored value Reference :: CInt -> Reference -- | Reference to a nil value RefNil :: Reference -- | Convert a reference to its C representation. fromReference :: Reference -> CInt -- | Create a reference from its C representation. toReference :: CInt -> Reference instance Control.Monad.Catch.MonadThrow Foreign.Lua.Core.Types.Lua instance Control.Monad.Reader.Class.MonadReader Foreign.Lua.Core.Types.LuaEnvironment Foreign.Lua.Core.Types.Lua instance Control.Monad.Catch.MonadMask Foreign.Lua.Core.Types.Lua instance Control.Monad.IO.Class.MonadIO Foreign.Lua.Core.Types.Lua instance Control.Monad.Catch.MonadCatch Foreign.Lua.Core.Types.Lua instance GHC.Base.Monad Foreign.Lua.Core.Types.Lua instance GHC.Base.Functor Foreign.Lua.Core.Types.Lua instance GHC.Base.Applicative Foreign.Lua.Core.Types.Lua -- | Bindings to HsLua-specific functions used to push Haskell values as -- userdata. module Foreign.Lua.Raw.Userdata -- | Retrieves a Haskell object from userdata at the given index. The -- userdata must have the given name. hslua_fromuserdata :: State -> StackIndex -> CString -> IO (Maybe a) -- | Creates a new userdata wrapping the given Haskell object. hslua_newhsuserdata :: State -> a -> IO () -- | Creates and registers a new metatable for a userdata-wrapped Haskell -- value; checks whether a metatable of that name has been registered yet -- and uses the registered table if possible. hslua_newudmetatable :: State -> CString -> IO LuaBool -- | Encoding and decoding of String to and from UTF8. module Foreign.Lua.Utf8 -- | Decode ByteString to String using -- UTF-8. Invalid input bytes are replaced with the Unicode replacement -- character U+FFFD. toString :: ByteString -> String -- | Decode ByteString to Text using UTF-8. -- Invalid input bytes are replaced with the Unicode replacement -- character U+FFFD. toText :: ByteString -> Text -- | Encode String to ByteString using -- UTF-8. fromString :: String -> ByteString -- | Encode Text to ByteString using UTF-8. fromText :: Text -> ByteString -- | Lua exceptions and exception handling. module Foreign.Lua.Core.Error -- | Exceptions raised by Lua-related operations. newtype Exception Exception :: String -> Exception [exceptionMessage] :: Exception -> String -- | Catch a Lua Exception. catchException :: Lua a -> (Exception -> Lua a) -> Lua a -- | Raise a Lua Exception containing the given error -- message. throwException :: String -> Lua a -- | Catch Lua Exception, alter the message and rethrow. withExceptionMessage :: (String -> String) -> Lua a -> Lua a -- | Convert a Lua error into a Haskell exception. The error message is -- expected to be at the top of the stack. throwErrorAsException :: Lua a -- | Alias for throwErrorAsException; will be deprecated in the next -- mayor release. throwTopMessage :: Lua a -- | Convert the object at the top of the stack into a string and throw it -- as a HsLua Exception. -- -- This function serves as the default to convert Lua errors to Haskell -- exceptions. throwTopMessageWithState :: State -> IO a -- | Retrieve and pop the top object as an error message. This is very -- similar to tostring', but ensures that we don't recurse if getting the -- message failed. errorMessage :: State -> IO ByteString -- | Return either the result of a Lua computation or, if an exception was -- thrown, the error. try :: Lua a -> Lua (Either Exception a) -- | Helper function which uses proper error-handling to throw an exception -- with the given message. throwMessage :: String -> Lua a -- | Takes a failable HsLua function and transforms it into a monadic -- Lua operation. Throws an exception if an error occured. liftLuaThrow :: (State -> Ptr StatusCode -> IO a) -> Lua a instance GHC.Classes.Eq Foreign.Lua.Core.Error.Exception instance GHC.Show.Show Foreign.Lua.Core.Error.Exception instance GHC.Exception.Type.Exception Foreign.Lua.Core.Error.Exception instance GHC.Base.Alternative Foreign.Lua.Core.Types.Lua -- | Core Lua API. This module provides thin wrappers around the respective -- functions of the Lua C API. C function which can throw an error are -- wrapped such that the error is converted into an -- Exception. However, memory allocation errors are not -- caught and will cause the host program to terminate. module Foreign.Lua.Core -- | 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. newtype Lua a Lua :: ReaderT LuaEnvironment IO a -> Lua a [unLua] :: Lua a -> ReaderT LuaEnvironment IO a -- | Run Lua computation with the given Lua state and error-to-exception -- converter. Any resulting exceptions are left unhandled. runWithConverter :: ErrorConversion -> State -> Lua a -> IO a -- | Run the given operation, but crash if any Haskell exceptions occur. unsafeRunWith :: State -> Lua a -> IO a -- | Lift a computation from the IO monad. liftIO :: MonadIO m => IO a -> m a -- | Get the Lua state of this Lua computation. state :: Lua State -- | Environment in which Lua computations are evaluated. data LuaEnvironment LuaEnvironment :: ErrorConversion -> State -> LuaEnvironment -- | Functions for error and exception handling and conversion [luaEnvErrorConversion] :: LuaEnvironment -> ErrorConversion -- | Lua interpreter state [luaEnvState] :: LuaEnvironment -> State -- | Define the ways in which exceptions and errors are handled. data ErrorConversion ErrorConversion :: (forall a. State -> IO a) -> (forall a. String -> Lua a -> Lua a) -> (forall a. Lua a -> Lua a -> Lua a) -> (Lua NumResults -> Lua NumResults) -> ErrorConversion -- | Translate Lua errors to Haskell exceptions [errorToException] :: ErrorConversion -> forall a. State -> IO a -- | Add information on the current context to an exception. [addContextToException] :: ErrorConversion -> forall a. String -> Lua a -> Lua a -- | Runs the second computation only if the first fails; returns the -- result of the first successful computation, if any. [alternative] :: ErrorConversion -> forall a. Lua a -> Lua a -> Lua a -- | Translate Haskell exceptions to Lua errors [exceptionToError] :: ErrorConversion -> Lua NumResults -> Lua NumResults -- | Get the error-to-exception function. errorConversion :: Lua ErrorConversion -- | Unsafe ErrorConversion; no proper error handling is -- attempted, any error leads to a crash. unsafeErrorConversion :: ErrorConversion -- | 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. type CFunction = FunPtr (State -> IO NumResults) -- | 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. newtype Integer Integer :: Int64 -> Integer -- | 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. newtype Number Number :: Double -> Number -- | A stack index newtype StackIndex StackIndex :: CInt -> StackIndex [fromStackIndex] :: StackIndex -> CInt -- | Stack index of the nth element from the top of the stack. nth :: CInt -> StackIndex -- | Stack index of the nth element from the bottom of the stack. nthFromBottom :: CInt -> StackIndex -- | Stack index of the nth element from the top of the stack. nthFromTop :: CInt -> StackIndex -- | Top of the stack stackTop :: StackIndex -- | Bottom of the stack stackBottom :: StackIndex -- | Top of the stack top :: StackIndex -- | The number of arguments consumed curing a function call. newtype NumArgs NumArgs :: CInt -> NumArgs [fromNumArgs] :: NumArgs -> CInt -- | The number of results returned by a function call. newtype NumResults NumResults :: CInt -> NumResults [fromNumResults] :: NumResults -> CInt -- | Alias for C constant LUA_MULTRET. See lua_call. multret :: NumResults -- | Alias for C constant LUA_REGISTRYINDEX. See Lua -- registry. registryindex :: StackIndex -- | Returns the pseudo-index that represents the i-th upvalue of -- the running function (see §4.4 of the Lua 5.3 reference -- manual). -- -- See also: lua_upvalueindex. upvalueindex :: StackIndex -> StackIndex -- | 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. newtype State State :: Ptr () -> State -- | Creates a new Lua state. It calls lua_newstate with an -- allocator based on the standard C realloc function and then -- sets a panic function (see §4.6 of the Lua 5.3 Reference -- Manual) that prints an error message to the standard error output in -- case of fatal errors. -- -- See also: luaL_newstate. newstate :: IO State -- | Destroys all objects in the given Lua state (calling the corresponding -- garbage-collection metamethods, if any) and frees all dynamic memory -- used by this state. On several platforms, you may not need to call -- this function, because all resources are naturally released when the -- host program ends. On the other hand, long-running programs that -- create multiple states, such as daemons or web servers, will probably -- need to close states as soon as they are not needed. -- -- This is a wrapper function of lua_close. close :: State -> IO () -- | Converts the acceptable index idx into an equivalent absolute -- index (that is, one that does not depend on the stack top). absindex :: StackIndex -> Lua StackIndex -- | Returns the index of the top element in the stack. Because indices -- start at 1, this result is equal to the number of elements in the -- stack (and so 0 means an empty stack). -- -- See also: lua_gettop. gettop :: Lua StackIndex -- | Accepts any index, or 0, and sets the stack top to this index. If the -- new top is larger than the old one, then the new elements are filled -- with nil. If index is 0, then all stack elements are removed. -- -- See also: lua_settop. settop :: StackIndex -> Lua () -- | Pushes a copy of the element at the given index onto the stack. -- -- See lua_pushvalue. pushvalue :: StackIndex -> Lua () -- | Copies the element at index fromidx into the valid index -- toidx, replacing the value at that position. Values at other -- positions are not affected. -- -- See also lua_copy in the lua manual. copy :: StackIndex -> StackIndex -> Lua () -- | Moves the top element into the given valid index, shifting up the -- elements above this index to open space. This function cannot be -- called with a pseudo-index, because a pseudo-index is not an actual -- stack position. -- -- See also: lua_insert. insert :: StackIndex -> Lua () -- | Pops n elements from the stack. -- -- See also: lua_pop. pop :: StackIndex -> Lua () -- | Removes the element at the given valid index, shifting down the -- elements above this index to fill the gap. This function cannot be -- called with a pseudo-index, because a pseudo-index is not an actual -- stack position. -- -- See lua_remove. remove :: StackIndex -> Lua () -- | Moves the top element into the given valid index without shifting any -- element (therefore replacing the value at that given index), and then -- pops the top element. -- -- See lua_replace. replace :: StackIndex -> Lua () -- | Ensures that the stack has space for at least n extra slots -- (that is, that you can safely push up to n values into it). -- It returns false if it cannot fulfill the request, either because it -- would cause the stack to be larger than a fixed maximum size -- (typically at least several thousand elements) or because it cannot -- allocate memory for the extra space. This function never shrinks the -- stack; if the stack already has space for the extra slots, it is left -- unchanged. -- -- This is a wrapper function of lua_checkstack. checkstack :: Int -> Lua Bool -- | Enumeration used as type tag. See lua_type. data Type -- | non-valid stack index TypeNone :: Type -- | type of lua's nil value TypeNil :: Type -- | type of lua booleans TypeBoolean :: Type -- | type of light userdata TypeLightUserdata :: Type -- | type of lua numbers. See Number TypeNumber :: Type -- | type of lua string values TypeString :: Type -- | type of lua tables TypeTable :: Type -- | type of functions, either normal or CFunction TypeFunction :: Type -- | type of full user data TypeUserdata :: Type -- | type of lua threads TypeThread :: Type -- | Integer code used to encode the type of a lua value. newtype TypeCode TypeCode :: CInt -> TypeCode [fromTypeCode] :: TypeCode -> CInt -- | Convert a lua Type to a type code which can be passed to the C API. fromType :: Type -> TypeCode -- | Convert numerical code to lua type. toType :: TypeCode -> Type -- | Returns the type of the value in the given valid index, or -- TypeNone for a non-valid (but acceptable) index. -- -- See lua_type. ltype :: StackIndex -> Lua Type -- | Returns the name of the type encoded by the value tp, which -- must be one the values returned by ltype. -- -- See also: lua_typename. typename :: Type -> Lua String -- | Returns True if the value at the given index is a boolean, -- and False otherwise. -- -- See also: lua_isboolean. isboolean :: StackIndex -> Lua Bool -- | Returns True if the value at the given index is a C function, -- and False otherwise. -- -- See also: lua_iscfunction. iscfunction :: StackIndex -> Lua Bool -- | Returns True if the value at the given index is a function -- (either C or Lua), and False otherwise. -- -- See also: lua_isfunction. isfunction :: StackIndex -> Lua Bool -- | Returns True if the value at the given index is an integer -- (that is, the value is a number and is represented as an integer), and -- False otherwise. isinteger :: StackIndex -> Lua Bool -- | Returns True if the value at the given index is a light -- userdata, and False otherwise. -- -- See also: -- <https://www.lua.org/manual/5.3/manual.html#lua_islightuserdata -- lua_islightuserdata>. islightuserdata :: StackIndex -> Lua Bool -- | Returns True if the value at the given index is nil, -- and False otherwise. -- -- See also: lua_isnil. isnil :: StackIndex -> Lua Bool -- | Returns True if the given index is not valid, and -- False otherwise. -- -- See also: lua_isnone. isnone :: StackIndex -> Lua Bool -- | Returns True if the given index is not valid or if the value -- at the given index is nil, and False otherwise. -- -- See also: lua_isnoneornil. isnoneornil :: StackIndex -> Lua Bool -- | Returns True if the value at the given index is a number or a -- string convertible to a number, and False otherwise. -- -- See also: lua_isnumber. isnumber :: StackIndex -> Lua Bool -- | Returns True if the value at the given index is a string or a -- number (which is always convertible to a string), and False -- otherwise. -- -- See also: lua_isstring. isstring :: StackIndex -> Lua Bool -- | Returns True if the value at the given index is a table, and -- False otherwise. -- -- See also: lua_istable. istable :: StackIndex -> Lua Bool -- | Returns True if the value at the given index is a thread, and -- False otherwise. -- -- See also: lua_isthread. isthread :: StackIndex -> Lua Bool -- | Returns True if the value at the given index is a userdata -- (either full or light), and False otherwise. -- -- See also: lua_isuserdata. isuserdata :: StackIndex -> Lua Bool -- | Converts the Lua value at the given index to a haskell boolean value. -- Like all tests in Lua, toboolean returns True for -- any Lua value different from false and nil; -- otherwise it returns False. (If you want to accept only -- actual boolean values, use isboolean to test the -- value's type.) -- -- See also: lua_toboolean. toboolean :: StackIndex -> Lua Bool -- | Converts a value at the given index to a C function. That value must -- be a C function; otherwise, returns Nothing. -- -- See also: lua_tocfunction. tocfunction :: StackIndex -> Lua (Maybe CFunction) -- | Converts the Lua value at the given acceptable index to the signed -- integral type Integer. The Lua value must be an integer, a -- number or a string convertible to an integer (see §3.4.3 of the -- Lua 5.3 Reference Manual); otherwise, tointeger returns -- Nothing. -- -- If the number is not an integer, it is truncated in some non-specified -- way. -- -- See also: lua_tointeger. tointeger :: StackIndex -> Lua (Maybe Integer) -- | Converts the Lua value at the given index to the C type lua_Number. -- The Lua value must be a number or a string convertible to a number; -- otherwise, tonumber returns Nothing. -- -- See lua_tonumber. tonumber :: StackIndex -> Lua (Maybe Number) -- | Converts the value at the given index to a generic C pointer (void*). -- The value can be a userdata, a table, a thread, or a function; -- otherwise, lua_topointer returns nullPtr. Different objects -- will give different pointers. There is no way to convert the pointer -- back to its original value. -- -- Typically this function is used only for hashing and debug -- information. -- -- See also: lua_topointer. topointer :: StackIndex -> Lua (Ptr ()) -- | Converts the Lua value at the given index to a -- ByteString. The Lua value must be a string or a -- number; otherwise, the function returns Nothing. If -- the value is a number, then tostring also changes the -- actual value in the stack to a string. (This change confuses -- next when tostring is applied to keys -- during a table traversal.) -- -- See lua_tolstring. tostring :: StackIndex -> Lua (Maybe ByteString) -- | Converts the value at the given index to a Lua thread (represented as -- lua_State*). This value must be a thread; otherwise, the function -- returns Nothing. -- -- See also: lua_tothread. tothread :: StackIndex -> Lua (Maybe State) -- | If the value at the given index is a full userdata, returns its block -- address. If the value is a light userdata, returns its pointer. -- Otherwise, returns Nothing.. -- -- See also: lua_touserdata. touserdata :: StackIndex -> Lua (Maybe (Ptr a)) -- | Returns the raw "length" of the value at the given index: for strings, -- this is the string length; for tables, this is the result of the -- length operator (#) with no metamethods; for userdata, this -- is the size of the block of memory allocated for the userdata; for -- other values, it is 0. -- -- See also: lua_rawlen. rawlen :: StackIndex -> Lua Int -- | Lua comparison operations. data RelationalOperator -- | Correponds to lua's equality (==) operator. EQ :: RelationalOperator -- | Correponds to lua's strictly-lesser-than (<) operator LT :: RelationalOperator -- | Correponds to lua's lesser-or-equal (<=) operator LE :: RelationalOperator -- | Convert relation operator to its C representation. fromRelationalOperator :: RelationalOperator -> CInt -- | Compares two Lua values. Returns True if the value at index -- idx1 satisfies op when compared with the value at -- index idx2, following the semantics of the corresponding Lua -- operator (that is, it may call metamethods). Otherwise returns -- False. Also returns False if any of the indices is -- not valid. -- -- The value of op must be of type RelationalOperator: -- -- EQ: compares for equality (==) LT: compares for less than (<) LE: -- compares for less or equal (<=) -- -- This is a wrapper function of lua_compare. compare :: StackIndex -> StackIndex -> RelationalOperator -> Lua Bool -- | Returns True if the two values in acceptable indices index1 -- and index2 are equal, following the semantics of the Lua == -- operator (that is, may call metamethods). Otherwise returns -- False. Also returns False if any of the indices is -- non valid. Uses compare internally. equal :: StackIndex -> StackIndex -> Lua Bool -- | Tests whether the object under the first index is smaller than that -- under the second. Uses compare internally. lessthan :: StackIndex -> StackIndex -> Lua Bool -- | Returns True if the two values in indices idx1 and -- idx2 are primitively equal (that is, without calling the -- __eq metamethod). Otherwise returns False. Also -- returns False if any of the indices are not valid. -- -- See also: lua_rawequal. rawequal :: StackIndex -> StackIndex -> Lua Bool -- | Pushes a boolean value with the given value onto the stack. -- -- See also: lua_pushboolean. pushboolean :: Bool -> Lua () -- | Pushes a C function onto the stack. This function receives a pointer -- to a C function and pushes onto the stack a Lua value of type function -- that, when called, invokes the corresponding C function. -- -- Any function to be callable by Lua must follow the correct protocol to -- receive its parameters and return its results (see -- CFunction) -- -- See also: lua_pushcfunction. pushcfunction :: CFunction -> Lua () -- | Pushes a new C closure onto the stack. -- -- When a C function is created, it is possible to associate some values -- with it, thus creating a C closure (see §3.4); these values are -- then accessible to the function whenever it is called. To associate -- values with a C function, first these values should be pushed onto the -- stack (when there are multiple values, the first value is pushed -- first). Then lua_pushcclosure is called to create and push the C -- function onto the stack, with the argument n telling how many -- values should be associated with the function. lua_pushcclosure also -- pops these values from the stack. -- -- The maximum value for n is 255. -- -- See also: lua_pushcclosure. pushcclosure :: CFunction -> NumArgs -> Lua () -- | Pushes an integer with with the given value onto the stack. -- -- See also: lua_pushinteger. pushinteger :: Integer -> Lua () -- | Pushes a light userdata onto the stack. -- -- Userdata represent C values in Lua. A light userdata represents a -- pointer, a Ptr () (i.e., void* in C lingo). It is a -- value (like a number): you do not create it, it has no individual -- metatable, and it is not collected (as it was never created). A light -- userdata is equal to "any" light userdata with the same C address. -- -- See also: lua_pushlightuserdata. pushlightuserdata :: Ptr a -> Lua () -- | Pushes a nil value onto the stack. -- -- See lua_pushnil. pushnil :: Lua () -- | Pushes a float with the given value onto the stack. -- -- See lua_pushnumber. pushnumber :: Number -> Lua () -- | Pushes the zero-terminated string pointed to by s onto the stack. Lua -- makes (or reuses) an internal copy of the given string, so the memory -- at s can be freed or reused immediately after the function returns. -- -- See also: -- <https://www.lua.org/manual/5.3/manual.html#lua_pushstring -- lua_pushstring>. pushstring :: ByteString -> Lua () -- | Pushes the current thread onto the stack. Returns True if -- this thread is the main thread of its state, False otherwise. -- -- See also: lua_pushthread. pushthread :: Lua Bool -- | Pushes onto the stack the value of the global name. -- -- Errors on the Lua side are caught and rethrown as -- Exception. -- -- Wrapper of lua_getglobal. getglobal :: String -> Lua () -- | Pushes onto the stack the value t[k], where t is the -- value at the given index and k is the value at the top of the -- stack. -- -- This function pops the key from the stack, pushing the resulting value -- in its place. As in Lua, this function may trigger a metamethod for -- the "index" event (see §2.4 of lua's manual). -- -- Errors on the Lua side are caught and rethrown as -- Exception. -- -- See also: lua_gettable. gettable :: StackIndex -> Lua () -- | Pushes onto the stack the value t[k], where t is the -- value at the given stack index. As in Lua, this function may trigger a -- metamethod for the "index" event (see §2.4 of lua's manual). -- -- Errors on the Lua side are caught and rethrown as -- Exception. -- -- See also: lua_getfield. getfield :: StackIndex -> String -> Lua () -- | Similar to gettable, but does a raw access (i.e., -- without metamethods). -- -- See also: lua_rawget. rawget :: StackIndex -> Lua () -- | Pushes onto the stack the value t[n], where t is the -- table at the given index. The access is raw, that is, it does not -- invoke the __index metamethod. -- -- See also: lua_rawgeti. rawgeti :: StackIndex -> Integer -> Lua () -- | Creates a new empty table and pushes it onto the stack. Parameter narr -- is a hint for how many elements the table will have as a sequence; -- parameter nrec is a hint for how many other elements the table will -- have. Lua may use these hints to preallocate memory for the new table. -- This preallocation is useful for performance when you know in advance -- how many elements the table will have. Otherwise you can use the -- function lua_newtable. -- -- This is a wrapper for function lua_createtable. createtable :: Int -> Int -> Lua () -- | Creates a new empty table and pushes it onto the stack. It is -- equivalent to createtable 0 0. -- -- See also: lua_newtable. newtable :: Lua () -- | This function allocates a new block of memory with the given size, -- pushes onto the stack a new full userdata with the block address, and -- returns this address. The host program can freely use this memory. -- -- See also: lua_newuserdata. newuserdata :: Int -> Lua (Ptr ()) -- | If the value at the given index has a metatable, the function pushes -- that metatable onto the stack and returns True. Otherwise, -- the function returns False and pushes nothing on the stack. -- -- See also: lua_getmetatable. getmetatable :: StackIndex -> Lua Bool -- | Pops a value from the stack and sets it as the new value of global -- name. -- -- Errors on the Lua side are caught and rethrown as a -- Exception. -- -- See also: lua_setglobal. setglobal :: String -> Lua () -- | Does the equivalent to t[k] = v, where t is the -- value at the given index, v is the value at the top of the -- stack, and k is the value just below the top. -- -- This function pops both the key and the value from the stack. As in -- Lua, this function may trigger a metamethod for the "newindex" event -- (see §2.4 of the Lua 5.3 Reference Manual). -- -- Errors on the Lua side are caught and rethrown as a -- Exception. -- -- See also: lua_settable. settable :: StackIndex -> Lua () -- | Does the equivalent to t[k] = v, where t is the -- value at the given index and v is the value at the top of the -- stack. -- -- This function pops the value from the stack. As in Lua, this function -- may trigger a metamethod for the "newindex" event (see §2.4 of -- the Lua 5.3 Reference Manual). -- -- Errors on the Lua side are caught and rethrown as a -- Exception. -- -- See also: lua_setfield. setfield :: StackIndex -> String -> Lua () -- | Similar to settable, but does a raw assignment (i.e., -- without metamethods). -- -- See also: lua_rawset. rawset :: StackIndex -> Lua () -- | Does the equivalent of t[i] = v, where t is the -- table at the given index and v is the value at the top of the -- stack. -- -- This function pops the value from the stack. The assignment is raw, -- that is, it does not invoke the __newindex metamethod. -- -- See also: lua_rawseti. rawseti :: StackIndex -> Integer -> Lua () -- | Pops a table from the stack and sets it as the new metatable for the -- value at the given index. -- -- See also: -- <https://www.lua.org/manual/5.3/manual.html#lua_setmetatable -- lua_setmetatable>. setmetatable :: StackIndex -> Lua () -- | Calls a function. -- -- To call a function you must use the following protocol: first, the -- function to be called is pushed onto the stack; then, the arguments to -- the function are pushed in direct order; that is, the first argument -- is pushed first. Finally you call call; nargs is the -- number of arguments that you pushed onto the stack. All arguments and -- the function value are popped from the stack when the function is -- called. The function results are pushed onto the stack when the -- function returns. The number of results is adjusted to -- nresults, unless nresults is multret. In -- this case, all results from the function are pushed. Lua takes care -- that the returned values fit into the stack space. The function -- results are pushed onto the stack in direct order (the first result is -- pushed first), so that after the call the last result is on the top of -- the stack. -- -- Any error inside the called function cause a Exception -- to be thrown. -- -- The following example shows how the host program can do the equivalent -- to this Lua code: -- --
--   a = f("how", t.x, 14)
--   
-- -- Here it is in Haskell (assuming the OverloadedStrings language -- extension): -- --
--   getglobal "f"         -- function to be called
--   pushstring  "how"     -- 1st argument
--   getglobal "t"         -- table to be indexed
--   getfield (-1) "x"     -- push result of t.x (2nd arg)
--   remove (-2)           -- remove 't' from the stack
--   pushinteger 14        -- 3rd argument
--   call 3 1              -- call 'f' with 3 arguments and 1 result
--   setglobal "a"         -- set global 'a'
--   
-- -- Note that the code above is "balanced": at its end, the stack is back -- to its original configuration. This is considered good programming -- practice. -- -- See lua_call. call :: NumArgs -> NumResults -> Lua () -- | Calls a function in protected mode. -- -- Both nargs and nresults have the same meaning as in -- call. If there are no errors during the call, -- pcall behaves exactly like call. However, if -- there is any error, pcall catches it, pushes a single value -- on the stack (the error message), and returns the error code. Like -- call, pcall always removes the function and -- its arguments from the stack. -- -- If msgh is Nothing, then the error object returned -- on the stack is exactly the original error object. Otherwise, when -- msgh is Just idx, the stack index idx is -- the location of a message handler. (This index cannot be a -- pseudo-index.) In case of runtime errors, this function will be called -- with the error object and its return value will be the object returned -- on the stack by pcall. -- -- Typically, the message handler is used to add more debug information -- to the error object, such as a stack traceback. Such information -- cannot be gathered after the return of pcall, since by -- then the stack has unwound. -- -- See lua_pcall. pcall :: NumArgs -> NumResults -> Maybe StackIndex -> Lua Status -- | Loads a Lua chunk (without running it). If there are no errors, -- load pushes the compiled chunk as a Lua function on -- top of the stack. Otherwise, it pushes an error message. -- -- The return values of load are: -- -- -- -- This function only loads a chunk; it does not run it. -- -- load automatically detects whether the chunk is text or -- binary, and loads it accordingly (see program luac). -- -- The load function uses a user-supplied reader function -- to read the chunk (see Reader). The data argument is -- an opaque value passed to the reader function. -- -- The chunkname argument gives a name to the chunk, which is -- used for error messages and in debug information (see §4.9). -- Note that the chunkname is used as a C string, so it may not -- contain null-bytes. load :: Reader -> Ptr () -> ByteString -> Lua Status -- | Loads a ByteString as a Lua chunk. -- -- This function returns the same results as load. -- name is the chunk name, used for debug information and error -- messages. Note that name is used as a C string, so it may not -- contain null-bytes. -- -- See luaL_loadbuffer. loadbuffer :: ByteString -> String -> Lua Status -- | Loads a file as a Lua chunk. This function uses lua_load (see -- load) to load the chunk in the file named filename. -- The first line in the file is ignored if it starts with a #. -- -- The string mode works as in function load. -- -- This function returns the same results as load, but it -- has an extra error code ErrFile for file-related -- errors (e.g., it cannot open or read the file). -- -- As load, this function only loads the chunk; it does -- not run it. -- -- Note that the file is opened by Haskell, not Lua. -- -- See luaL_loadfile. loadfile :: FilePath -> Lua Status -- | Loads a string as a Lua chunk. This function uses lua_load to -- load the chunk in the given ByteString. The given string may not -- contain any NUL characters. -- -- This function returns the same results as lua_load (see -- load). -- -- Also as load, this function only loads the chunk; it -- does not run it. -- -- See luaL_loadstring. loadstring :: ByteString -> Lua Status -- | Lua status values. data Status -- | success OK :: Status -- | yielding / suspended coroutine Yield :: Status -- | a runtime rror ErrRun :: Status -- | syntax error during precompilation ErrSyntax :: Status -- | memory allocation (out-of-memory) error. ErrMem :: Status -- | error while running the message handler. ErrErr :: Status -- | error while running a __gc metamethod. ErrGcmm :: Status -- | opening or reading a file failed. ErrFile :: Status -- | Convert C integer constant to Status. toStatus :: StatusCode -> Status -- | Returns the status of this Lua thread. -- -- The status can be OK for a normal thread, an error value if the -- thread finished the execution of a lua_resume with an error, -- or Yield if the thread is suspended. -- -- You can only call functions in threads with status OK. You can -- resume threads with status OK (to start a new coroutine) or -- Yield (to resume a coroutine). -- -- See also: lua_status. status :: Lua Status -- | Enumeration used by gc function. data GCCONTROL GCSTOP :: GCCONTROL GCRESTART :: GCCONTROL GCCOLLECT :: GCCONTROL GCCOUNT :: GCCONTROL GCCOUNTB :: GCCONTROL GCSTEP :: GCCONTROL GCSETPAUSE :: GCCONTROL GCSETSTEPMUL :: GCCONTROL -- | Controls the garbage collector. -- -- This function performs several tasks, according to the value of the -- parameter what: -- -- -- -- See lua_gc. gc :: GCCONTROL -> Int -> Lua Int -- | Pops a key from the stack, and pushes a key–value pair from the table -- at the given index (the "next" pair after the given key). If there are -- no more elements in the table, then next returns -- False (and pushes nothing). -- -- Errors on the Lua side are caught and rethrown as a -- Exception. -- -- See also: lua_next. next :: StackIndex -> Lua Bool -- | This is a convenience function to implement error propagation -- convention described in Error handling in hslua. hslua doesn't -- implement the lua_error function from Lua C API because it's -- never safe to use. (see Error handling in hslua for details) error :: Lua NumResults -- | Concatenates the n values at the top of the stack, pops them, -- and leaves the result at the top. If n is 1, the result is -- the single value on the stack (that is, the function does nothing); if -- n is 0, the result is the empty string. Concatenation is -- performed following the usual semantics of Lua (see §3.4.6 of -- the lua manual). -- -- This is a wrapper function of lua_concat. concat :: NumArgs -> Lua () -- | Pushes the global environment onto the stack. -- -- Wraps -- <https://www.lua.org/manual/5.3/manual.html#lua_pushglobaltable -- lua_pushglobaltable>. pushglobaltable :: Lua () -- | Sets the C function f as the new value of global -- name. -- -- See lua_register. register :: String -> CFunction -> Lua () -- | Pushes Lua's base library onto the stack. -- -- See luaopen_base. openbase :: Lua () -- | Pushes Lua's debug library onto the stack. -- -- See also: luaopen_debug. opendebug :: Lua () -- | Pushes Lua's io library onto the stack. -- -- See also: luaopen_io. openio :: Lua () -- | Opens all standard Lua libraries into the current state and sets each -- library name as a global value. -- -- See also: luaL_openlibs. openlibs :: Lua () -- | Pushes Lua's math library onto the stack. -- -- See also: luaopen_math. openmath :: Lua () -- | Pushes Lua's package library onto the stack. -- -- See also: luaopen_package. openpackage :: Lua () -- | Pushes Lua's os library onto the stack. -- -- See also: luaopen_os. openos :: Lua () -- | Pushes Lua's string library onto the stack. -- -- See also: luaopen_string. openstring :: Lua () -- | Pushes Lua's table library onto the stack. -- -- See also: luaopen_table. opentable :: Lua () -- | Loads and runs the given string. -- -- Returns OK on success, or an error if either loading of the -- string or calling of the thunk failed. dostring :: ByteString -> Lua Status -- | Loads and runs the given file. Note that the filepath is interpreted -- by Haskell, not Lua. The resulting chunk is named using the UTF8 -- encoded filepath. dofile :: FilePath -> Lua Status -- | Pushes onto the stack the field e from the metatable of the -- object at index obj and returns the type of the pushed value. -- If the object does not have a metatable, or if the metatable does not -- have this field, pushes nothing and returns TypeNil. getmetafield :: StackIndex -> String -> Lua Type -- | Pushes onto the stack the metatable associated with name -- tname in the registry (see newmetatable) -- (nil if there is no metatable associated with that name). -- Returns the type of the pushed value. getmetatable' :: String -> Lua Type -- | Ensures that the value t[fname], where t is the -- value at index idx, is a table, and pushes that table onto -- the stack. Returns True if it finds a previous table there and False -- if it creates a new table. getsubtable :: StackIndex -> String -> Lua Bool -- | If the registry already has the key tname, returns False. -- Otherwise, creates a new table to be used as a metatable for userdata, -- adds to this new table the pair __name = tname, adds to the -- registry the pair [tname] = new table, and returns -- True. (The entry __name is used by some -- error-reporting functions.) -- -- In both cases pushes onto the stack the final value associated with -- tname in the registry. -- -- The value of tname is used as a C string and hence must not -- contain null bytes. -- -- See also: luaL_newmetatable. newmetatable :: String -> Lua Bool -- | Converts any Lua value at the given index to a -- ByteString in a reasonable format. The resulting -- string is pushed onto the stack and also returned by the function. -- -- If the value has a metatable with a __tostring field, then -- tolstring' calls the corresponding metamethod with the value -- as argument, and uses the result of the call as its result. tostring' :: StackIndex -> Lua ByteString -- | Creates and pushes a traceback of the stack L1. If a message is given -- it appended at the beginning of the traceback. The level parameter -- tells at which level to start the traceback. traceback :: State -> Maybe String -> Int -> Lua () -- | Reference to a stored value. data Reference -- | Reference to a stored value Reference :: CInt -> Reference -- | Reference to a nil value RefNil :: Reference -- | Creates and returns a reference, in the table at index t, for -- the object at the top of the stack (and pops the object). -- -- A reference is a unique integer key. As long as you do not manually -- add integer keys into table t, ref ensures the -- uniqueness of the key it returns. You can retrieve an object referred -- by reference r by calling rawgeti t r. Function -- unref frees a reference and its associated object. -- -- If the object at the top of the stack is nil, ref -- returns the constant refnil. The constant -- noref is guaranteed to be different from any reference -- returned by ref. -- -- See also: luaL_ref. ref :: StackIndex -> Lua Reference -- | Push referenced value from the table at the given index. getref :: StackIndex -> Reference -> Lua () -- | Releases reference ref from the table at index -- idx (see ref). The entry is removed from the -- table, so that the referred object can be collected. The reference -- ref is also freed to be used again. -- -- See also: luaL_unref. unref :: StackIndex -> Reference -> Lua () -- | Convert a reference to its C representation. fromReference :: Reference -> CInt -- | Create a reference from its C representation. toReference :: CInt -> Reference -- | Value signaling that no reference was found. noref :: Int -- | Value signaling that no reference was created. refnil :: Int -- | Key, in the registry, for table of loaded modules. loadedTableRegistryField :: String -- | Key, in the registry, for table of preloaded loaders. preloadTableRegistryField :: String -- | Exceptions raised by Lua-related operations. newtype Exception Exception :: String -> Exception [exceptionMessage] :: Exception -> String -- | Raise a Lua Exception containing the given error -- message. throwException :: String -> Lua a -- | Catch a Lua Exception. catchException :: Lua a -> (Exception -> Lua a) -> Lua a -- | Catch Lua Exception, alter the message and rethrow. withExceptionMessage :: (String -> String) -> Lua a -> Lua a -- | Return either the result of a Lua computation or, if an exception was -- thrown, the error. try :: Lua a -> Lua (Either Exception a) -- | Helper function which uses proper error-handling to throw an exception -- with the given message. throwMessage :: String -> Lua a -- | Retrieve and pop the top object as an error message. This is very -- similar to tostring', but ensures that we don't recurse if getting the -- message failed. errorMessage :: State -> IO ByteString -- | Convert a Lua error into a Haskell exception. The error message is -- expected to be at the top of the stack. throwErrorAsException :: Lua a -- | Alias for throwErrorAsException; will be deprecated in the next -- mayor release. throwTopMessage :: Lua a -- | Convert the object at the top of the stack into a string and throw it -- as a HsLua Exception. -- -- This function serves as the default to convert Lua errors to Haskell -- exceptions. throwTopMessageWithState :: State -> IO a -- | Functions which marshal and push Haskell values onto Lua's stack. module Foreign.Lua.Push -- | Function to push a value to Lua's stack. type Pusher a = a -> Lua () -- | Pushes a Bool as a Lua boolean. pushBool :: Pusher Bool -- | Pushes an Integer to the Lua stack. Values representable as -- Lua integers are pushed as such; bigger integers are represented using -- their string representation. pushIntegral :: (Integral a, Show a) => a -> Lua () -- | Push a floating point number to the Lua stack. Uses a string -- representation for all types which do not match the float properties -- of the Number type. pushRealFloat :: RealFloat a => a -> Lua () -- | Pushes a ByteString as a raw string. pushByteString :: Pusher ByteString -- | Pushes a lazy ByteString as a raw string. pushLazyByteString :: Pusher ByteString -- | Pushes a String as an UTF-8 encoded Lua string. pushString :: String -> Lua () -- | Pushes a Text value as an UTF-8 encoded string. pushText :: Pusher Text -- | Push list as numerically indexed table. pushList :: Pusher a -> [a] -> Lua () -- | Push Map as default key-value Lua table. pushMap :: Pusher a -> Pusher b -> Pusher (Map a b) -- | Push a Set as idiomatic Lua set, i.e., as a table with the set -- elements as keys and true as values. pushSet :: Pusher a -> Pusher (Set a) -- | Sending haskell objects to the lua stack. module Foreign.Lua.Types.Pushable -- | A value that can be pushed to the Lua stack. class Pushable a -- | Pushes a value onto Lua stack, casting it into meaningfully nearest -- Lua type. push :: Pushable a => a -> Lua () -- | Push list as numerically indexed table. pushList :: Pushable a => [a] -> Lua () instance Foreign.Lua.Types.Pushable.Pushable () instance Foreign.Lua.Types.Pushable.Pushable Foreign.Lua.Raw.Types.Integer instance Foreign.Lua.Types.Pushable.Pushable Foreign.Lua.Raw.Types.Number instance Foreign.Lua.Types.Pushable.Pushable Data.ByteString.Internal.ByteString instance Foreign.Lua.Types.Pushable.Pushable GHC.Types.Bool instance Foreign.Lua.Types.Pushable.Pushable Foreign.Lua.Raw.Types.CFunction instance Foreign.Lua.Types.Pushable.Pushable (GHC.Ptr.Ptr a) instance Foreign.Lua.Types.Pushable.Pushable Data.Text.Internal.Text instance Foreign.Lua.Types.Pushable.Pushable Data.ByteString.Lazy.Internal.ByteString instance Foreign.Lua.Types.Pushable.Pushable GHC.Integer.Type.Integer instance Foreign.Lua.Types.Pushable.Pushable GHC.Types.Int instance Foreign.Lua.Types.Pushable.Pushable GHC.Types.Float instance Foreign.Lua.Types.Pushable.Pushable GHC.Types.Double instance Foreign.Lua.Types.Pushable.Pushable [GHC.Types.Char] instance Foreign.Lua.Types.Pushable.Pushable a => Foreign.Lua.Types.Pushable.Pushable [a] instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b) => Foreign.Lua.Types.Pushable.Pushable (Data.Map.Internal.Map a b) instance Foreign.Lua.Types.Pushable.Pushable a => Foreign.Lua.Types.Pushable.Pushable (Data.Set.Internal.Set a) instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b) => Foreign.Lua.Types.Pushable.Pushable (a, b) instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b, Foreign.Lua.Types.Pushable.Pushable c) => Foreign.Lua.Types.Pushable.Pushable (a, b, c) instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b, Foreign.Lua.Types.Pushable.Pushable c, Foreign.Lua.Types.Pushable.Pushable d) => Foreign.Lua.Types.Pushable.Pushable (a, b, c, d) instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b, Foreign.Lua.Types.Pushable.Pushable c, Foreign.Lua.Types.Pushable.Pushable d, Foreign.Lua.Types.Pushable.Pushable e) => Foreign.Lua.Types.Pushable.Pushable (a, b, c, d, e) instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b, Foreign.Lua.Types.Pushable.Pushable c, Foreign.Lua.Types.Pushable.Pushable d, Foreign.Lua.Types.Pushable.Pushable e, Foreign.Lua.Types.Pushable.Pushable f) => Foreign.Lua.Types.Pushable.Pushable (a, b, c, d, e, f) instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b, Foreign.Lua.Types.Pushable.Pushable c, Foreign.Lua.Types.Pushable.Pushable d, Foreign.Lua.Types.Pushable.Pushable e, Foreign.Lua.Types.Pushable.Pushable f, Foreign.Lua.Types.Pushable.Pushable g) => Foreign.Lua.Types.Pushable.Pushable (a, b, c, d, e, f, g) instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.Types.Pushable.Pushable b, Foreign.Lua.Types.Pushable.Pushable c, Foreign.Lua.Types.Pushable.Pushable d, Foreign.Lua.Types.Pushable.Pushable e, Foreign.Lua.Types.Pushable.Pushable f, Foreign.Lua.Types.Pushable.Pushable g, Foreign.Lua.Types.Pushable.Pushable h) => Foreign.Lua.Types.Pushable.Pushable (a, b, c, d, e, f, g, h) -- | Functions which unmarshal and retrieve Haskell values from Lua's -- stack. module Foreign.Lua.Peek -- | Function to retrieve a value from Lua's stack. type Peeker a = StackIndex -> Lua (Either PeekError a) -- | List of errors which occurred while retrieving a value from the stack. newtype PeekError PeekError :: NonEmpty Text -> PeekError [fromPeekError] :: PeekError -> NonEmpty Text -- | Create a peek error from an error message. errorMsg :: Text -> PeekError -- | Force creation of a result, throwing an exception if that's not -- possible. force :: Either PeekError a -> Lua a formatPeekError :: PeekError -> String -- | Add a message to the peek traceback stack. pushMsg :: Text -> PeekError -> PeekError -- | Convert an old peek funtion to a Peeker. toPeeker :: (StackIndex -> Lua a) -> Peeker a -- | Retrieves a Bool as a Lua boolean. peekBool :: Peeker Bool -- | Retrieves an Integral value from the Lua stack. peekIntegral :: (Integral a, Read a) => Peeker a -- | Retrieve a RealFloat (e.g., Float or Double) from -- the stack. peekRealFloat :: (RealFloat a, Read a) => Peeker a -- | Retrieves a ByteString as a raw string. peekByteString :: Peeker ByteString -- | Retrieves a lazy ByteString as a raw string. peekLazyByteString :: Peeker ByteString -- | Retrieves a String from an UTF-8 encoded Lua string. peekString :: Peeker String -- | Retrieves a Text value as an UTF-8 encoded string. peekText :: Peeker Text -- | Retrieves a String-like value from an UTF-8 encoded Lua string. -- -- This should not be used to peek ByteString values or other -- values for which construction via fromString can result in loss -- of information. peekStringy :: IsString a => Peeker a -- | Read a table into a list of pairs. peekKeyValuePairs :: Peeker a -> Peeker b -> Peeker [(a, b)] -- | Reads a numerically indexed table t into a list, where the -- length of the list is equal to #t. The operation will -- fail if a numerical field n with 1 ≤ n < #t is -- missing. peekList :: Peeker a -> Peeker [a] -- | Retrieves a key-value Lua table as Map. peekMap :: Ord a => Peeker a -> Peeker b -> Peeker (Map a b) -- | Retrieves a Set from an idiomatic Lua representation. A set in -- Lua is idiomatically represented as a table with the elements as keys. -- Elements with falsy values are omitted. peekSet :: Ord a => Peeker a -> Peeker (Set a) -- | Makes a result optional. Returns Nothing if the Lua value is -- nil; otherwise applies the peeker and returns its result. optional :: Peeker a -> Peeker (Maybe a) instance GHC.Show.Show Foreign.Lua.Peek.PeekError instance GHC.Classes.Eq Foreign.Lua.Peek.PeekError -- | Sending haskell objects to the lua stack. module Foreign.Lua.Types.Peekable -- | A value that can be read from the Lua stack. class Peekable a -- | Check if at index n there is a convertible Lua value and if -- so return it. Throws a Exception otherwise. peek :: Peekable a => StackIndex -> Lua a -- | Read a table into a list of pairs. peekKeyValuePairs :: (Peekable a, Peekable b) => StackIndex -> Lua [(a, b)] -- | Read a table into a list peekList :: Peekable a => StackIndex -> Lua [a] -- | Report the expected and actual type of the value under the given index -- if conversion failed. reportValueOnFailure :: String -> (StackIndex -> Lua (Maybe a)) -> StackIndex -> Lua a instance Foreign.Lua.Types.Peekable.Peekable () instance Foreign.Lua.Types.Peekable.Peekable Foreign.Lua.Raw.Types.Integer instance Foreign.Lua.Types.Peekable.Peekable Foreign.Lua.Raw.Types.Number instance Foreign.Lua.Types.Peekable.Peekable Data.ByteString.Internal.ByteString instance Foreign.Lua.Types.Peekable.Peekable GHC.Types.Bool instance Foreign.Lua.Types.Peekable.Peekable Foreign.Lua.Raw.Types.CFunction instance Foreign.Lua.Types.Peekable.Peekable (GHC.Ptr.Ptr a) instance Foreign.Lua.Types.Peekable.Peekable Foreign.Lua.Raw.Types.State instance Foreign.Lua.Types.Peekable.Peekable Data.Text.Internal.Text instance Foreign.Lua.Types.Peekable.Peekable Data.ByteString.Lazy.Internal.ByteString instance Foreign.Lua.Types.Peekable.Peekable GHC.Integer.Type.Integer instance Foreign.Lua.Types.Peekable.Peekable GHC.Types.Int instance Foreign.Lua.Types.Peekable.Peekable GHC.Types.Float instance Foreign.Lua.Types.Peekable.Peekable GHC.Types.Double instance Foreign.Lua.Types.Peekable.Peekable [GHC.Types.Char] instance Foreign.Lua.Types.Peekable.Peekable a => Foreign.Lua.Types.Peekable.Peekable [a] instance (GHC.Classes.Ord a, Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b) => Foreign.Lua.Types.Peekable.Peekable (Data.Map.Internal.Map a b) instance (GHC.Classes.Ord a, Foreign.Lua.Types.Peekable.Peekable a) => Foreign.Lua.Types.Peekable.Peekable (Data.Set.Internal.Set a) instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b) => Foreign.Lua.Types.Peekable.Peekable (a, b) instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b, Foreign.Lua.Types.Peekable.Peekable c) => Foreign.Lua.Types.Peekable.Peekable (a, b, c) instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b, Foreign.Lua.Types.Peekable.Peekable c, Foreign.Lua.Types.Peekable.Peekable d) => Foreign.Lua.Types.Peekable.Peekable (a, b, c, d) instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b, Foreign.Lua.Types.Peekable.Peekable c, Foreign.Lua.Types.Peekable.Peekable d, Foreign.Lua.Types.Peekable.Peekable e) => Foreign.Lua.Types.Peekable.Peekable (a, b, c, d, e) instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b, Foreign.Lua.Types.Peekable.Peekable c, Foreign.Lua.Types.Peekable.Peekable d, Foreign.Lua.Types.Peekable.Peekable e, Foreign.Lua.Types.Peekable.Peekable f) => Foreign.Lua.Types.Peekable.Peekable (a, b, c, d, e, f) instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b, Foreign.Lua.Types.Peekable.Peekable c, Foreign.Lua.Types.Peekable.Peekable d, Foreign.Lua.Types.Peekable.Peekable e, Foreign.Lua.Types.Peekable.Peekable f, Foreign.Lua.Types.Peekable.Peekable g) => Foreign.Lua.Types.Peekable.Peekable (a, b, c, d, e, f, g) instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.Types.Peekable.Peekable b, Foreign.Lua.Types.Peekable.Peekable c, Foreign.Lua.Types.Peekable.Peekable d, Foreign.Lua.Types.Peekable.Peekable e, Foreign.Lua.Types.Peekable.Peekable f, Foreign.Lua.Types.Peekable.Peekable g, Foreign.Lua.Types.Peekable.Peekable h) => Foreign.Lua.Types.Peekable.Peekable (a, b, c, d, e, f, g, h) -- | Convenience functions to convert Haskell values into Lua userdata. -- -- The main purpose of this module is to allow fast and simple creation -- of instances for Peekable and Pushable. E.g., given -- a data type Person -- --
--   data Person = Person { name :: String, age :: Int }
--      deriving (Eq, Show, Typeable, Data)
--   
-- -- we can simply do -- --
--   instance Lua.Peekable Person where
--       safePeek = safePeekAny
--   
--   instance Lua.Pushable Person where
--       push = pushAny
--   
-- -- The other functions can be used to exert more control over the -- userdata wrapping and unwrapping process. module Foreign.Lua.Userdata -- | Push data by wrapping it into a userdata object. pushAny :: Data a => a -> Lua () -- | Push data by wrapping it into a userdata object, using the object at -- the top of the stack after performing the given operation as -- metatable. pushAnyWithMetatable :: Lua () -> a -> Lua () -- | Retrieve data which has been pushed with pushAny. toAny :: Data a => StackIndex -> Lua (Maybe a) -- | Retrieve data which has been pushed with -- pushAnyWithMetatable, where *name* must is the value -- of the __name field of the metatable. toAnyWithName :: StackIndex -> String -> Lua (Maybe a) -- | Retrieve Haskell data which was pushed to Lua as userdata. peekAny :: Data a => StackIndex -> Lua a -- | Push the metatable used to define the behavior of the given value in -- Lua. The table will be created if it doesn't exist yet. ensureUserdataMetatable :: String -> Lua () -> Lua () -- | Return the default name for userdata to be used when wrapping an -- object as the given type as userdata. The argument is never evaluated. metatableName :: Data a => a -> String -- | Types for working with Lua. module Foreign.Lua.Types -- | Marshaling and documenting Haskell functions. module Foreign.Lua.Call -- | Haskell equivallent to CFunction, i.e., function callable from Lua. data HaskellFunction HaskellFunction :: Lua NumResults -> Maybe FunctionDoc -> HaskellFunction [callFunction] :: HaskellFunction -> Lua NumResults [functionDoc] :: HaskellFunction -> Maybe FunctionDoc -- | Create a HaskellFunction precursor from a pure function. toHsFnPrecursor :: a -> HsFnPrecursor a toHsFnPrecursorWithStartIndex :: StackIndex -> a -> HsFnPrecursor a -- | Partially apply a parameter. applyParameter :: HsFnPrecursor (a -> b) -> Parameter a -> HsFnPrecursor b -- | Like returnResult, but returns only a single result. returnResult :: HsFnPrecursor a -> FunctionResult a -> HaskellFunction -- | Function parameter. data Parameter a Parameter :: Peeker a -> ParameterDoc -> Parameter a [parameterPeeker] :: Parameter a -> Peeker a [parameterDoc] :: Parameter a -> ParameterDoc -- | Result of a call to a Haskell function. data FunctionResult a FunctionResult :: Pusher a -> FunctionResultDoc -> FunctionResult a [fnResultPusher] :: FunctionResult a -> Pusher a [fnResultDoc] :: FunctionResult a -> FunctionResultDoc -- | List of function results in the order in which they are returned in -- Lua. type FunctionResults a = [FunctionResult a] -- | Inline version of applyParameter. (<#>) :: HsFnPrecursor (a -> b) -> Parameter a -> HsFnPrecursor b infixl 8 <#> -- | Inline version of returnResult. (=#>) :: HsFnPrecursor a -> FunctionResults a -> HaskellFunction infixl 8 =#> -- | Inline version of updateFunctionDescription. (#?) :: HaskellFunction -> Text -> HaskellFunction infixl 8 #? -- | Documentation for a Haskell function data FunctionDoc FunctionDoc :: Text -> [ParameterDoc] -> [FunctionResultDoc] -> FunctionDoc [functionDescription] :: FunctionDoc -> Text [parameterDocs] :: FunctionDoc -> [ParameterDoc] [functionResultDocs] :: FunctionDoc -> [FunctionResultDoc] -- | Documentation for function parameters. data ParameterDoc ParameterDoc :: Text -> Text -> Text -> Bool -> ParameterDoc [parameterName] :: ParameterDoc -> Text [parameterType] :: ParameterDoc -> Text [parameterDescription] :: ParameterDoc -> Text [parameterIsOptional] :: ParameterDoc -> Bool -- | Documentation for the result of a function. data FunctionResultDoc FunctionResultDoc :: Text -> Text -> FunctionResultDoc [functionResultType] :: FunctionResultDoc -> Text [functionResultDescription] :: FunctionResultDoc -> Text render :: FunctionDoc -> Text pushHaskellFunction :: HaskellFunction -> Lua () -- | Creates a parameter. parameter :: Peeker a -> Text -> Text -> Text -> Parameter a -- | Creates an optional parameter. optionalParameter :: Peeker a -> Text -> Text -> Text -> Parameter (Maybe a) -- | Creates a function result. functionResult :: Pusher a -> Text -> Text -> FunctionResults a instance GHC.Show.Show Foreign.Lua.Call.ParameterDoc instance GHC.Classes.Ord Foreign.Lua.Call.ParameterDoc instance GHC.Classes.Eq Foreign.Lua.Call.ParameterDoc instance GHC.Show.Show Foreign.Lua.Call.FunctionResultDoc instance GHC.Classes.Ord Foreign.Lua.Call.FunctionResultDoc instance GHC.Classes.Eq Foreign.Lua.Call.FunctionResultDoc instance GHC.Show.Show Foreign.Lua.Call.FunctionDoc instance GHC.Classes.Ord Foreign.Lua.Call.FunctionDoc instance GHC.Classes.Eq Foreign.Lua.Call.FunctionDoc instance GHC.Base.Functor Foreign.Lua.Call.HsFnPrecursor -- | HsLua utility functions. module Foreign.Lua.Util -- | Like getglobal, but knows about packages and nested tables. -- E.g. -- --
--   getglobal' "math.sin"
--   
-- -- will return the function sin in package math. getglobal' :: String -> Lua () -- | Like setglobal, but knows about packages and nested tables. -- E.g. -- --
--   pushstring "0.9.4"
--   setglobal' "mypackage.version"
--   
-- -- All tables and fields, except for the last field, must exist. setglobal' :: String -> Lua () -- | Run Lua computation using the default HsLua state as starting point. -- Exceptions are masked, thus avoiding some issues when using multiple -- threads. All exceptions are passed through; error handling is the -- responsibility of the caller. run :: Lua a -> IO a -- | Run Lua computation using the default HsLua state as starting point. -- Conversion from Lua errors to Haskell exceptions can be controlled -- through ErrorConversion. run' :: ErrorConversion -> Lua a -> IO a -- | Run the given Lua computation; exceptions raised in haskell code are -- caught, but other exceptions (user exceptions raised in haskell, -- unchecked type errors, etc.) are passed through. runEither :: Exception e => Lua a -> IO (Either e a) -- | Raise a Lua error, using the given value as the error object. raiseError :: Pushable a => a -> Lua NumResults -- | Newtype wrapper intended to be used for optional Lua values. Nesting -- this type is strongly discouraged as missing values on inner levels -- are indistinguishable from missing values on an outer level; wrong -- values would be the likely result. newtype Optional a Optional :: Maybe a -> Optional a [fromOptional] :: Optional a -> Maybe a -- | Run Lua computation with the given Lua state and the default -- error-to-exception converter. Exception handling is left to the -- caller. runWith :: State -> Lua a -> IO a -- | Try to convert the value at the given stack index to a Haskell value. -- Returns Left with an error message on failure. -- -- WARNING: this is not save to use with custom error handling! peekEither :: Peekable a => StackIndex -> Lua (Either String a) -- | Get a value by retrieving a String from Lua, then using -- readMaybe to convert the String into a Haskell value. peekRead :: Read a => StackIndex -> Lua a -- | Get, then pop the value at the top of the stack. The pop operation is -- executed even if the retrieval operation failed. popValue :: Peekable a => Lua a instance Foreign.Lua.Types.Peekable.Peekable a => Foreign.Lua.Types.Peekable.Peekable (Foreign.Lua.Util.Optional a) instance Foreign.Lua.Types.Pushable.Pushable a => Foreign.Lua.Types.Pushable.Pushable (Foreign.Lua.Util.Optional a) -- | Call haskell functions from Lua, and vice versa. module Foreign.Lua.FunctionCalling -- | A value that can be read from the Lua stack. class Peekable a -- | Check if at index n there is a convertible Lua value and if -- so return it. Throws a Exception otherwise. peek :: Peekable a => StackIndex -> Lua a -- | Helper class used to make lua functions useable from haskell class LuaCallFunc a callFunc' :: LuaCallFunc a => String -> Lua () -> NumArgs -> a -- | Operations and functions that can be pushed to the Lua stack. This is -- a helper function not intended to be used directly. Use the -- toHaskellFunction wrapper instead. class ToHaskellFunction a -- | Helper function, called by toHaskellFunction toHsFun :: ToHaskellFunction a => StackIndex -> a -> Lua NumResults -- | Haskell function that can be called from Lua. type HaskellFunction = Lua NumResults -- | A value that can be pushed to the Lua stack. class Pushable a -- | Pushes a value onto Lua stack, casting it into meaningfully nearest -- Lua type. push :: Pushable a => a -> Lua () -- | Type of raw Haskell functions that can be made into CFunctions. type PreCFunction = State -> IO NumResults -- | Convert a Haskell function to Lua function. Any Haskell function can -- be converted provided that: -- -- -- -- Any Exception will be converted to a string and -- returned as Lua error. -- -- Important: this does not catch exceptions other than -- Exception; exception handling must be done by the -- converted Haskell function. Failure to do so will cause the program to -- crash. -- -- E.g., the following code could be used to handle an Exception of type -- FooException, if that type is an instance of MonadCatch and -- Pushable: -- --
--   toHaskellFunction (myFun `catchM` (\e -> raiseError (e :: FooException)))
--   
toHaskellFunction :: ToHaskellFunction a => a -> HaskellFunction -- | Call a Lua function. Use as: -- --
--   v <- callfunc "proc" "abc" (1::Int) (5.0::Double)
--   
callFunc :: LuaCallFunc a => String -> a -- | Free function pointer created with newcfunction. freeCFunction :: CFunction -> Lua () -- | Create new foreign Lua function. Function created can be called by the -- Lua engine. Remeber to free the pointer with freecfunction. newCFunction :: ToHaskellFunction a => a -> Lua CFunction -- | Pushes Haskell function as a callable userdata. All values created -- will be garbage collected. Use as: -- --
--   pushHaskellFunction myfun
--   setglobal "myfun"
--   
-- -- Error conditions should be indicated by raising a Lua -- Exception or by returning the result of -- error. pushHaskellFunction :: ToHaskellFunction a => a -> Lua () -- | Converts a pre C function to a Lua function and pushes it to the -- stack. -- -- Pre C functions collect parameters from the stack and return a -- CInt that represents number of return values left on the stack. pushPreCFunction :: PreCFunction -> Lua () -- | Imports a Haskell function and registers it at global name. registerHaskellFunction :: ToHaskellFunction a => String -> a -> Lua () instance Foreign.Lua.Types.Peekable.Peekable a => Foreign.Lua.FunctionCalling.LuaCallFunc (Foreign.Lua.Core.Types.Lua a) instance (Foreign.Lua.Types.Pushable.Pushable a, Foreign.Lua.FunctionCalling.LuaCallFunc b) => Foreign.Lua.FunctionCalling.LuaCallFunc (a -> b) instance Foreign.Lua.FunctionCalling.ToHaskellFunction Foreign.Lua.FunctionCalling.HaskellFunction instance Foreign.Lua.Types.Pushable.Pushable a => Foreign.Lua.FunctionCalling.ToHaskellFunction (Foreign.Lua.Core.Types.Lua a) instance (Foreign.Lua.Types.Peekable.Peekable a, Foreign.Lua.FunctionCalling.ToHaskellFunction b) => Foreign.Lua.FunctionCalling.ToHaskellFunction (a -> b) -- | Utility functions for HsLua modules. module Foreign.Lua.Module -- | Load a module, defined by a Haskell action, under the given name. -- -- Similar to luaL_required: After checking "loaded" table, -- calls pushMod to push a module to the stack, and registers -- the result in package.loaded table. -- -- The pushMod function must push exactly one element to the top -- of the stack. This is not checked, but failure to do so will lead to -- problems. Lua's package module must have been loaded by the -- time this function is invoked. -- -- Leaves a copy of the module on the stack. requirehs :: String -> Lua () -> Lua () -- | Registers a preloading function. Takes an module name and the Lua -- operation which produces the package. preloadhs :: String -> Lua NumResults -> Lua () -- | Add a string-indexed field to the table at the top of the stack. addfield :: Pushable a => String -> a -> Lua () -- | Attach a function to the table at the top of the stack, using the -- given name. addfunction :: ToHaskellFunction a => String -> a -> Lua () -- | Create a new module (i.e., a Lua table). create :: Lua () -- | Named and documented Lua module. data Module Module :: Text -> Text -> [Field] -> [(Text, HaskellFunction)] -> Module [moduleName] :: Module -> Text [moduleDescription] :: Module -> Text [moduleFields] :: Module -> [Field] [moduleFunctions] :: Module -> [(Text, HaskellFunction)] -- | Self-documenting module field data Field Field :: Text -> Text -> Lua () -> Field [fieldName] :: Field -> Text [fieldDescription] :: Field -> Text [fieldPushValue] :: Field -> Lua () -- | Registers a Module; leaves a copy of the module table on the -- stack. registerModule :: Module -> Lua () -- | Preload self-documenting module. preloadModule :: Module -> Lua () pushModule :: Module -> Lua () -- | Renders module documentation as Markdown. render :: Module -> Text -- | Bindings, functions, and utilities enabling the integration of a Lua -- interpreter into a haskell project. -- -- Basic access to the Lua API is provided by -- 'Foreign.Lua.Core'. module Foreign.Lua -- | A value that can be read from the Lua stack. class Peekable a -- | Check if at index n there is a convertible Lua value and if -- so return it. Throws a Exception otherwise. peek :: Peekable a => StackIndex -> Lua a -- | Try to convert the value at the given stack index to a Haskell value. -- Returns Left with an error message on failure. -- -- WARNING: this is not save to use with custom error handling! peekEither :: Peekable a => StackIndex -> Lua (Either String a) -- | Read a table into a list peekList :: Peekable a => StackIndex -> Lua [a] -- | Read a table into a list of pairs. peekKeyValuePairs :: (Peekable a, Peekable b) => StackIndex -> Lua [(a, b)] -- | Get a value by retrieving a String from Lua, then using -- readMaybe to convert the String into a Haskell value. peekRead :: Read a => StackIndex -> Lua a -- | Retrieve Haskell data which was pushed to Lua as userdata. peekAny :: Data a => StackIndex -> Lua a -- | A value that can be pushed to the Lua stack. class Pushable a -- | Pushes a value onto Lua stack, casting it into meaningfully nearest -- Lua type. push :: Pushable a => a -> Lua () -- | Push list as numerically indexed table. pushList :: Pushable a => [a] -> Lua () -- | Push data by wrapping it into a userdata object. pushAny :: Data a => a -> Lua () -- | Type of raw Haskell functions that can be made into CFunctions. type PreCFunction = State -> IO NumResults -- | Haskell function that can be called from Lua. type HaskellFunction = Lua NumResults -- | Operations and functions that can be pushed to the Lua stack. This is -- a helper function not intended to be used directly. Use the -- toHaskellFunction wrapper instead. class ToHaskellFunction a -- | Helper function, called by toHaskellFunction toHsFun :: ToHaskellFunction a => StackIndex -> a -> Lua NumResults -- | Convert a Haskell function to Lua function. Any Haskell function can -- be converted provided that: -- -- -- -- Any Exception will be converted to a string and -- returned as Lua error. -- -- Important: this does not catch exceptions other than -- Exception; exception handling must be done by the -- converted Haskell function. Failure to do so will cause the program to -- crash. -- -- E.g., the following code could be used to handle an Exception of type -- FooException, if that type is an instance of MonadCatch and -- Pushable: -- --
--   toHaskellFunction (myFun `catchM` (\e -> raiseError (e :: FooException)))
--   
toHaskellFunction :: ToHaskellFunction a => a -> HaskellFunction -- | Call a Lua function. Use as: -- --
--   v <- callfunc "proc" "abc" (1::Int) (5.0::Double)
--   
callFunc :: LuaCallFunc a => String -> a -- | Create new foreign Lua function. Function created can be called by the -- Lua engine. Remeber to free the pointer with freecfunction. newCFunction :: ToHaskellFunction a => a -> Lua CFunction -- | Free function pointer created with newcfunction. freeCFunction :: CFunction -> Lua () -- | Pushes Haskell function as a callable userdata. All values created -- will be garbage collected. Use as: -- --
--   pushHaskellFunction myfun
--   setglobal "myfun"
--   
-- -- Error conditions should be indicated by raising a Lua -- Exception or by returning the result of -- error. pushHaskellFunction :: ToHaskellFunction a => a -> Lua () -- | Imports a Haskell function and registers it at global name. registerHaskellFunction :: ToHaskellFunction a => String -> a -> Lua () -- | Run Lua computation using the default HsLua state as starting point. -- Exceptions are masked, thus avoiding some issues when using multiple -- threads. All exceptions are passed through; error handling is the -- responsibility of the caller. run :: Lua a -> IO a -- | Run Lua computation using the default HsLua state as starting point. -- Conversion from Lua errors to Haskell exceptions can be controlled -- through ErrorConversion. run' :: ErrorConversion -> Lua a -> IO a -- | Run the given Lua computation; exceptions raised in haskell code are -- caught, but other exceptions (user exceptions raised in haskell, -- unchecked type errors, etc.) are passed through. runEither :: Exception e => Lua a -> IO (Either e a) -- | Run Lua computation with the given Lua state and the default -- error-to-exception converter. Exception handling is left to the -- caller. runWith :: State -> Lua a -> IO a -- | Like getglobal, but knows about packages and nested tables. -- E.g. -- --
--   getglobal' "math.sin"
--   
-- -- will return the function sin in package math. getglobal' :: String -> Lua () -- | Like setglobal, but knows about packages and nested tables. -- E.g. -- --
--   pushstring "0.9.4"
--   setglobal' "mypackage.version"
--   
-- -- All tables and fields, except for the last field, must exist. setglobal' :: String -> Lua () -- | Raise a Lua error, using the given value as the error object. raiseError :: Pushable a => a -> Lua NumResults -- | Newtype wrapper intended to be used for optional Lua values. Nesting -- this type is strongly discouraged as missing values on inner levels -- are indistinguishable from missing values on an outer level; wrong -- values would be the likely result. newtype Optional a Optional :: Maybe a -> Optional a [fromOptional] :: Optional a -> Maybe a -- | Get, then pop the value at the top of the stack. The pop operation is -- executed even if the retrieval operation failed. popValue :: Peekable a => Lua a -- | Load a module, defined by a Haskell action, under the given name. -- -- Similar to luaL_required: After checking "loaded" table, -- calls pushMod to push a module to the stack, and registers -- the result in package.loaded table. -- -- The pushMod function must push exactly one element to the top -- of the stack. This is not checked, but failure to do so will lead to -- problems. Lua's package module must have been loaded by the -- time this function is invoked. -- -- Leaves a copy of the module on the stack. requirehs :: String -> Lua () -> Lua () -- | Registers a preloading function. Takes an module name and the Lua -- operation which produces the package. preloadhs :: String -> Lua NumResults -> Lua () -- | Create a new module (i.e., a Lua table). create :: Lua () -- | Add a string-indexed field to the table at the top of the stack. addfield :: Pushable a => String -> a -> Lua () -- | Attach a function to the table at the top of the stack, using the -- given name. addfunction :: ToHaskellFunction a => String -> a -> Lua ()