-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A Lua language interpreter embedding in Haskell -- -- The Foreign.Lua module is a wrapper of Lua language interpreter as -- described on lua.org. -- -- This package contains a full Lua interpreter version 5.3.4. 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 0.9.4 -- | The core Lua types, including mappings of Lua types to Haskell. module Foreign.Lua.Api.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 LuaState LuaState :: (Ptr ()) -> LuaState -- | 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 (LuaState -> 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 LuaInteger LuaInteger :: Int64 -> LuaInteger -- | 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 LuaNumber LuaNumber :: Double -> LuaNumber -- | 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 -- | Convert a LuaBool to a Haskell Bool. fromLuaBool :: LuaBool -> Bool -- | Convert a Haskell Bool to a LuaBool. toLuaBool :: Bool -> LuaBool -- | 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 LuaNumber 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 -- | 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 -- | Convert C integer constant to LuaStatus. toStatus :: StatusCode -> Status -- | Integer code used to signal the status of a thread or computation. See -- Status. newtype StatusCode StatusCode :: CInt -> StatusCode -- | Value or an error, using the convention that value below zero indicate -- an error. Values greater than zero are used verbatim. The phantom type -- is currently used for documentation only and has no effect. type Failable a = CInt -- | Enumeration used by gc function. data GCCONTROL GCSTOP :: GCCONTROL GCRESTART :: GCCONTROL GCCOLLECT :: GCCONTROL GCCOUNT :: GCCONTROL GCCOUNTB :: GCCONTROL GCSTEP :: GCCONTROL GCSETPAUSE :: GCCONTROL GCSETSTEPMUL :: GCCONTROL -- | A stack index newtype StackIndex StackIndex :: CInt -> StackIndex [fromStackIndex] :: StackIndex -> CInt -- | Stack index of the nth element from the top of the stack. nthFromTop :: CInt -> StackIndex -- | Stack index of the nth element from the bottom of the stack. nthFromBottom :: CInt -> StackIndex -- | Top of the stack stackTop :: StackIndex -- | Bottom of the stack stackBottom :: StackIndex -- | The number of arguments expected a function. 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 instance GHC.Show.Show Foreign.Lua.Api.Types.NumResults instance GHC.Classes.Ord Foreign.Lua.Api.Types.NumResults instance GHC.Num.Num Foreign.Lua.Api.Types.NumResults instance GHC.Classes.Eq Foreign.Lua.Api.Types.NumResults instance GHC.Show.Show Foreign.Lua.Api.Types.NumArgs instance GHC.Classes.Ord Foreign.Lua.Api.Types.NumArgs instance GHC.Num.Num Foreign.Lua.Api.Types.NumArgs instance GHC.Classes.Eq Foreign.Lua.Api.Types.NumArgs instance GHC.Show.Show Foreign.Lua.Api.Types.StackIndex instance GHC.Classes.Ord Foreign.Lua.Api.Types.StackIndex instance GHC.Num.Num Foreign.Lua.Api.Types.StackIndex instance GHC.Classes.Eq Foreign.Lua.Api.Types.StackIndex instance GHC.Enum.Enum Foreign.Lua.Api.Types.StackIndex instance GHC.Show.Show Foreign.Lua.Api.Types.GCCONTROL instance GHC.Classes.Ord Foreign.Lua.Api.Types.GCCONTROL instance GHC.Classes.Eq Foreign.Lua.Api.Types.GCCONTROL instance GHC.Enum.Enum Foreign.Lua.Api.Types.GCCONTROL instance GHC.Classes.Eq Foreign.Lua.Api.Types.StatusCode instance GHC.Show.Show Foreign.Lua.Api.Types.Status instance GHC.Classes.Eq Foreign.Lua.Api.Types.Status instance GHC.Show.Show Foreign.Lua.Api.Types.RelationalOperator instance GHC.Classes.Ord Foreign.Lua.Api.Types.RelationalOperator instance GHC.Classes.Eq Foreign.Lua.Api.Types.RelationalOperator instance GHC.Show.Show Foreign.Lua.Api.Types.TypeCode instance GHC.Classes.Ord Foreign.Lua.Api.Types.TypeCode instance GHC.Classes.Eq Foreign.Lua.Api.Types.TypeCode instance GHC.Show.Show Foreign.Lua.Api.Types.Type instance GHC.Classes.Ord Foreign.Lua.Api.Types.Type instance GHC.Classes.Eq Foreign.Lua.Api.Types.Type instance GHC.Enum.Bounded Foreign.Lua.Api.Types.Type instance Foreign.Storable.Storable Foreign.Lua.Api.Types.LuaBool instance GHC.Classes.Eq Foreign.Lua.Api.Types.LuaBool instance GHC.Show.Show Foreign.Lua.Api.Types.LuaNumber instance GHC.Real.RealFrac Foreign.Lua.Api.Types.LuaNumber instance GHC.Float.RealFloat Foreign.Lua.Api.Types.LuaNumber instance GHC.Real.Real Foreign.Lua.Api.Types.LuaNumber instance GHC.Classes.Ord Foreign.Lua.Api.Types.LuaNumber instance GHC.Num.Num Foreign.Lua.Api.Types.LuaNumber instance GHC.Real.Fractional Foreign.Lua.Api.Types.LuaNumber instance GHC.Float.Floating Foreign.Lua.Api.Types.LuaNumber instance GHC.Classes.Eq Foreign.Lua.Api.Types.LuaNumber instance GHC.Show.Show Foreign.Lua.Api.Types.LuaInteger instance GHC.Real.Real Foreign.Lua.Api.Types.LuaInteger instance GHC.Classes.Ord Foreign.Lua.Api.Types.LuaInteger instance GHC.Num.Num Foreign.Lua.Api.Types.LuaInteger instance GHC.Real.Integral Foreign.Lua.Api.Types.LuaInteger instance GHC.Classes.Eq Foreign.Lua.Api.Types.LuaInteger instance GHC.Enum.Enum Foreign.Lua.Api.Types.LuaInteger instance GHC.Classes.Eq Foreign.Lua.Api.Types.LuaState instance GHC.Enum.Enum Foreign.Lua.Api.Types.Type -- | Haskell bindings to lua C API functions. module Foreign.Lua.Api.RawBindings -- | See lua_close lua_close :: LuaState -> IO () -- | See lua_absindex lua_absindex :: LuaState -> StackIndex -> IO StackIndex -- | See lua_gettop lua_gettop :: LuaState -> IO StackIndex -- | See lua_settop lua_settop :: LuaState -> StackIndex -> IO () -- | See lua_pushvalue lua_pushvalue :: LuaState -> StackIndex -> IO () -- | See lua_rotate lua_rotate :: LuaState -> StackIndex -> CInt -> IO () -- | See lua_copy lua_copy :: LuaState -> StackIndex -> StackIndex -> IO () -- | See lua_checkstack lua_checkstack :: LuaState -> StackIndex -> IO LuaBool -- | See lua_isnumber lua_isnumber :: LuaState -> StackIndex -> IO LuaBool -- | See lua_isstring lua_isstring :: LuaState -> StackIndex -> IO LuaBool -- | See lua_iscfunction lua_iscfunction :: LuaState -> StackIndex -> IO LuaBool -- | See lua_isuserdata lua_isuserdata :: LuaState -> StackIndex -> IO LuaBool -- | See lua_type lua_type :: LuaState -> StackIndex -> IO TypeCode -- | See lua_typename lua_typename :: LuaState -> TypeCode -> IO (Ptr CChar) -- | Wrapper around -- @lua_compare@ which catches any -- longjmps. hslua_compare :: LuaState -> StackIndex -> StackIndex -> CInt -> IO (Failable LuaBool) -- | See lua_rawequal lua_rawequal :: LuaState -> StackIndex -> StackIndex -> IO LuaBool -- | See lua_toboolean lua_toboolean :: LuaState -> StackIndex -> IO StackIndex -- | See lua_tocfunction lua_tocfunction :: LuaState -> StackIndex -> IO CFunction -- | See lua_tointegerx lua_tointegerx :: LuaState -> StackIndex -> Ptr LuaBool -> IO LuaInteger -- | See lua_tonumberx lua_tonumberx :: LuaState -> StackIndex -> Ptr LuaBool -> IO LuaNumber -- | See lua_tolstring lua_tolstring :: LuaState -> StackIndex -> Ptr CSize -> IO (Ptr CChar) -- | See lua_topointer lua_topointer :: LuaState -> StackIndex -> IO (Ptr ()) -- | See lua_tothread lua_tothread :: LuaState -> StackIndex -> IO LuaState -- | See lua_touserdata lua_touserdata :: LuaState -> StackIndex -> IO (Ptr a) -- | See lua_rawlen lua_rawlen :: LuaState -> StackIndex -> IO CSize -- | See lua_pushnil lua_pushnil :: LuaState -> IO () -- | See lua_pushnumber lua_pushnumber :: LuaState -> LuaNumber -> IO () -- | See lua_pushinteger lua_pushinteger :: LuaState -> LuaInteger -> IO () -- | See lua_pushlstring lua_pushlstring :: LuaState -> Ptr CChar -> CSize -> IO () -- | See lua_pushcclosure lua_pushcclosure :: LuaState -> CFunction -> NumArgs -> IO () -- | See lua_pushboolean lua_pushboolean :: LuaState -> LuaBool -> IO () -- | See lua_pushlightuserdata lua_pushlightuserdata :: LuaState -> Ptr a -> IO () -- | See lua_pushthread lua_pushthread :: LuaState -> IO CInt -- | Wrapper around -- @lua_gettable@ which catches any -- longjmps. hslua_gettable :: LuaState -> StackIndex -> IO CInt -- | Wrapper around -- @lua_getfield@ which catches any -- longjmps. hslua_getfield :: LuaState -> StackIndex -> Ptr CChar -> IO CInt -- | See lua_rawget lua_rawget :: LuaState -> StackIndex -> IO () -- | See lua_rawgeti lua_rawgeti :: LuaState -> StackIndex -> CInt -> IO () -- | See lua_createtable lua_createtable :: LuaState -> CInt -> CInt -> IO () -- | See lua_newuserdata lua_newuserdata :: LuaState -> CInt -> IO (Ptr ()) -- | See lua_getmetatable lua_getmetatable :: LuaState -> StackIndex -> IO CInt -- | Wrapper around -- @lua_getglobal@ which catches any -- longjmps. hslua_getglobal :: LuaState -> Ptr CChar -> IO CInt -- | Wrapper around -- @lua_settable@ which catches any -- longjmps. hslua_settable :: LuaState -> StackIndex -> IO CInt -- | Wrapper around -- @lua_setfield@ which catches any -- longjmps. hslua_setfield :: LuaState -> StackIndex -> Ptr CChar -> IO CInt -- | See lua_rawset lua_rawset :: LuaState -> StackIndex -> IO () -- | See lua_rawseti lua_rawseti :: LuaState -> StackIndex -> CInt -> IO () -- | See lua_setmetatable lua_setmetatable :: LuaState -> StackIndex -> IO () -- | Wrapper around -- @lua_setglobal@ which catches any -- longjmps. hslua_setglobal :: LuaState -> Ptr CChar -> IO CInt -- | See lua_pcallk lua_pcallk :: LuaState -> NumArgs -> NumResults -> StackIndex -> CInt -> Ptr () -> IO StatusCode -- | See lua_status lua_status :: LuaState -> IO StatusCode -- | See lua_gc lua_gc :: LuaState -> CInt -> CInt -> IO CInt -- | Wrapper around -- @lua_next@ which catches any -- longjmps. hslua_next :: LuaState -> StackIndex -> IO (Failable LuaBool) -- | Wrapper around -- @lua_concat@ which catches any -- longjmps. hslua_concat :: LuaState -> NumArgs -> IO (Failable LuaBool) -- | See luaL_openlibs luaL_openlibs :: LuaState -> 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 -- | See luaL_newstate luaL_newstate :: IO LuaState -- | See luaL_newmetatable luaL_newmetatable :: LuaState -> Ptr CChar -> IO LuaBool -- | See luaL_ref luaL_ref :: LuaState -> StackIndex -> IO CInt -- | See luaL_unref luaL_unref :: LuaState -> StackIndex -> CInt -> IO () -- | See luaL_loadfilex luaL_loadfilex :: LuaState -> Ptr CChar -> Ptr CChar -> IO StatusCode -- | See luaL_loadstring luaL_loadstring :: LuaState -> Ptr CChar -> IO StatusCode hslua_call_hs_ptr :: CFunction -- | Lua constants module Foreign.Lua.Api.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 -- | The core Lua types, including mappings of Lua types to Haskell. module Foreign.Lua.Types.Lua -- | Lua computation newtype Lua a Lua :: ReaderT LuaState IO a -> Lua a [unLua] :: Lua a -> ReaderT LuaState IO a -- | Get the lua state of this lua computation. luaState :: Lua LuaState -- | Run lua computation with custom lua state. Errors are left unhandled, -- the caller of this function is responsible to catch lua errors. runLuaWith :: LuaState -> Lua a -> IO a -- | Lift a computation from the IO monad. liftIO :: MonadIO m => forall a. () => IO a -> m a -- | Turn a function of typ LuaState -> IO a into a monadic lua -- operation. liftLua :: (LuaState -> IO a) -> Lua a -- | Turn a function of typ LuaState -> a -> IO b into a -- monadic lua operation. liftLua1 :: (LuaState -> a -> IO b) -> a -> Lua b instance Control.Monad.Catch.MonadThrow Foreign.Lua.Types.Lua.Lua instance Control.Monad.Reader.Class.MonadReader Foreign.Lua.Api.Types.LuaState Foreign.Lua.Types.Lua.Lua instance Control.Monad.Catch.MonadMask Foreign.Lua.Types.Lua.Lua instance Control.Monad.IO.Class.MonadIO Foreign.Lua.Types.Lua.Lua instance Control.Monad.Catch.MonadCatch Foreign.Lua.Types.Lua.Lua instance GHC.Base.Monad Foreign.Lua.Types.Lua.Lua instance GHC.Base.Functor Foreign.Lua.Types.Lua.Lua instance GHC.Base.Applicative Foreign.Lua.Types.Lua.Lua -- | Lua exceptions and exception handling. module Foreign.Lua.Types.Error -- | Exceptions raised by Lua-related operations. data LuaException LuaException :: String -> LuaException -- | Catch a LuaException. catchLuaError :: Lua a -> (LuaException -> Lua a) -> Lua a -- | Raise a LuaException containing the given error -- message. throwLuaError :: String -> Lua a -- | Return either the result of a Lua computation or, if an exception was -- thrown, the error. tryLua :: Lua a -> Lua (Either LuaException a) instance GHC.Classes.Eq Foreign.Lua.Types.Error.LuaException instance GHC.Show.Show Foreign.Lua.Types.Error.LuaException instance GHC.Exception.Exception Foreign.Lua.Types.Error.LuaException instance GHC.Base.Alternative Foreign.Lua.Types.Lua.Lua -- | Monadic functions which operate within the Lua type. -- -- The functions in this module are mostly just thin wrappers around the -- respective C functions. However, C function which can throw an error -- are wrapped such that the error is converted into a -- LuaException. Memory allocation errors, however, are -- not caught and will cause the host program to terminate. module Foreign.Lua.Api -- | 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 (LuaState -> 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. data LuaInteger -- | 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. data LuaNumber -- | A stack index newtype StackIndex StackIndex :: CInt -> StackIndex [fromStackIndex] :: StackIndex -> CInt -- | 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 -- | The number of arguments expected a function. 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 -- | Value signaling that no reference was found. noref :: Int -- | Value signaling that no reference was created. refnil :: Int -- | 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 LuaState LuaState :: (Ptr ()) -> LuaState -- | 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 LuaState -- | 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 :: LuaState -> 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 LuaNumber 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 -- | 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 a light -- userdata, and False otherwise. -- -- See also: -- 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 NULL. -- -- See also: lua_tocfunction. tocfunction :: StackIndex -> Lua CFunction -- | Converts the Lua value at the given acceptable index to the signed -- integral type lua_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 0. -- -- If the number is not an integer, it is truncated in some non-specified -- way. -- -- See also: lua_tointeger. tointeger :: StackIndex -> Lua LuaInteger -- | Like tointeger, but returns Nothing if the -- conversion failed tointegerx :: StackIndex -> Lua (Maybe LuaInteger) -- | 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 0. -- -- See lua_tonumber. tonumber :: StackIndex -> Lua LuaNumber -- | Like tonumber, but returns Nothing if the -- conversion failed tonumberx :: StackIndex -> Lua (Maybe LuaNumber) -- | 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 NULL. 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 ()) -- | See lua_tostring. tostring :: StackIndex -> Lua 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 NULL. -- -- See also: lua_tothread. tothread :: StackIndex -> Lua LuaState -- | 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 NULL. -- -- See also: lua_touserdata. touserdata :: StackIndex -> Lua (Ptr a) -- | Obsolete alias for rawlen. -- | Deprecated: Use rawlen instead. objlen :: StackIndex -> Lua Int -- | 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 -- | Compatibility alias for rawlen -- | Deprecated: Use rawlen instead. strlen :: 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 LuaComparerOp: -- -- OpEQ: compares for equality (==) OpLT: compares for less than (<) -- OpLE: 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 -> Int -> Lua () -- | Pushes an integer with with the given value onto the stack. -- -- See also: lua_pushinteger. pushinteger :: LuaInteger -> 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 :: LuaNumber -> 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: -- 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. Returns -- the type of that value. -- -- 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). -- -- 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). -- -- Returns the type of the pushed value. -- -- 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 -> Int -> 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. -- -- 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). -- -- 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). -- -- 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 -> Int -> Lua () -- | Pops a table from the stack and sets it as the new metatable for the -- value at the given index. -- -- See also: -- 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 -- LuaException 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 -- | See luaL_loadfile. loadfile :: String -> Lua Status -- | See luaL_loadstring. loadstring :: String -> 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 LuaStatus. 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: -- --
-- 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. -- Raised exceptions are passed through; error handling is the -- responsibility of the caller. runLua :: 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. runLuaEither :: Lua a -> IO (Either LuaException a) -- | 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. data OrNil a instance Foreign.Lua.Types.FromLuaStack.FromLuaStack a => Foreign.Lua.Types.FromLuaStack.FromLuaStack (Foreign.Lua.Util.OrNil a) instance Foreign.Lua.Types.ToLuaStack.ToLuaStack a => Foreign.Lua.Types.ToLuaStack.ToLuaStack (Foreign.Lua.Util.OrNil a) -- | Call haskell functions from Lua, and vice versa. module Foreign.Lua.FunctionCalling -- | A value that can be read from the Lua stack. class FromLuaStack a -- | Check if at index n there is a convertible Lua value and if -- so return it. Throws a LuaException otherwise. peek :: FromLuaStack 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 ToLuaStack a -- | Pushes a value onto Lua stack, casting it into meaningfully nearest -- Lua type. push :: ToLuaStack a => a -> Lua () -- | Type of raw haskell functions that can be made into CFunctions. type PreCFunction = LuaState -> IO NumResults -- | Convert a Haskell function to Lua function. Any Haskell function can -- be converted provided that: -- --
-- 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 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" ---- -- You are not allowed to use lua_error anywhere, but use an -- error code of (-1) to the same effect. Push error message as the sole -- return value. pushHaskellFunction :: ToHaskellFunction a => a -> Lua () -- | Imports a Haskell function and registers it at global name. registerHaskellFunction :: ToHaskellFunction a => String -> a -> Lua () instance Foreign.Lua.Types.FromLuaStack.FromLuaStack a => Foreign.Lua.FunctionCalling.LuaCallFunc (Foreign.Lua.Types.Lua.Lua a) instance (Foreign.Lua.Types.ToLuaStack.ToLuaStack 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.ToLuaStack.ToLuaStack a => Foreign.Lua.FunctionCalling.ToHaskellFunction (Foreign.Lua.Types.Lua.Lua a) instance (Foreign.Lua.Types.FromLuaStack.FromLuaStack a, Foreign.Lua.FunctionCalling.ToHaskellFunction b) => Foreign.Lua.FunctionCalling.ToHaskellFunction (a -> b) -- | Bindings, functions, and utilities enabling the integration of a lua -- interpreter into a haskell project. module Foreign.Lua -- | Lua computation newtype Lua a Lua :: ReaderT LuaState IO a -> Lua a [unLua] :: Lua a -> ReaderT LuaState IO a -- | Get the lua state of this lua computation. luaState :: Lua LuaState -- | Run lua computation with custom lua state. Errors are left unhandled, -- the caller of this function is responsible to catch lua errors. runLuaWith :: LuaState -> Lua a -> IO a -- | Lift a computation from the IO monad. liftIO :: MonadIO m => forall a. () => IO a -> m a -- | A value that can be read from the Lua stack. class FromLuaStack a -- | Check if at index n there is a convertible Lua value and if -- so return it. Throws a LuaException otherwise. peek :: FromLuaStack 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. peekEither :: FromLuaStack a => StackIndex -> Lua (Either String a) -- | Read a table into a list toList :: FromLuaStack a => StackIndex -> Lua [a] -- | Read a table into a list of pairs. pairsFromTable :: (FromLuaStack a, FromLuaStack b) => StackIndex -> Lua [(a, b)] -- | A value that can be pushed to the Lua stack. class ToLuaStack a -- | Pushes a value onto Lua stack, casting it into meaningfully nearest -- Lua type. push :: ToLuaStack a => a -> Lua () -- | Push list as numerically indexed table. pushList :: ToLuaStack a => [a] -> Lua () -- | Type of raw haskell functions that can be made into CFunctions. type PreCFunction = LuaState -> 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: -- --
-- 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 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" ---- -- You are not allowed to use lua_error anywhere, but use an -- error code of (-1) to the same effect. Push error message as the sole -- return value. 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. -- Raised exceptions are passed through; error handling is the -- responsibility of the caller. runLua :: 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. runLuaEither :: Lua a -> IO (Either LuaException 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 () -- | Exceptions raised by Lua-related operations. data LuaException LuaException :: String -> LuaException -- | Catch a LuaException. catchLuaError :: Lua a -> (LuaException -> Lua a) -> Lua a -- | Raise a LuaException containing the given error -- message. throwLuaError :: String -> Lua a -- | Return either the result of a Lua computation or, if an exception was -- thrown, the error. tryLua :: Lua a -> Lua (Either LuaException a)