-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | A Lua language interpreter embedding in Haskell
--   
--   The Scripting.Lua module is a wrapper of Lua language interpreter as
--   described in www.lua.org.
--   
--   This package contains full Lua interpreter version 5.1.4. If you want
--   to link it with system-wide Lua installation, use system-lua flag.
@package hslua
@version 0.3.8


-- | A Haskell wrapper library for a scripting language Lua. See
--   <tt>http://www.lua.org/</tt> for more details.
--   
--   This module is intended to be imported <tt>qualified</tt>, eg.
--   
--   <pre>
--   import qualified Scripting.Lua as Lua
--   </pre>
--   
--   This way we use Haskell module hierarchy to make Lua names shorter.
--   Haskell functions are named after Lua functions, but the <tt>lua_</tt>
--   or <tt>luaL_</tt> prefix.
--   
--   Lua types are mapped to Haskell types as in the following table:
--   
--   <pre>
--   int (stack index)        Int
--   lua_Integer              LuaInteger
--   lua_Number               LuaNumber
--   int (bool result)        Bool
--   const char * (string)    String
--   void *                   Ptr ()
--   lua_State *              LuaState
--   </pre>
--   
--   Most functions are one-to-one mappings. Rare special cases are clearly
--   marked in this document.
--   
--   Minmal sample embedding:
--   
--   <pre>
--   import qualified Scripting.Lua as Lua
--   </pre>
--   
--   <pre>
--   main = do
--       l &lt;- Lua.newstate
--       Lua.openlibs l
--       Lua.callproc l "print" "Hello from Lua"
--       Lua.close l
--   </pre>
module Scripting.Lua

-- | Wrapper for <tt>lua_State *</tt>. See <tt>lua_State</tt> in Lua
--   Reference Manual.
newtype LuaState
LuaState :: (Ptr ()) -> LuaState

-- | Wrapper for <tt>lua_CFunction</tt>. See <tt>lua_CFunction</tt> in Lua
--   Reference Manual.
type LuaCFunction = LuaState -> IO CInt

-- | Wrapper for <tt>lua_Integer</tt>. See <tt>lua_Integer</tt> in Lua
--   Reference Manual. HsLua uses C <tt>ptrdiff_t</tt> as
--   <tt>lua_Integer</tt>.
type LuaInteger = CPtrdiff

-- | Wrapper for <tt>lua_Number</tt>. See <tt>lua_Number</tt> in Lua
--   Reference Manual. HsLua uses C <tt>double</tt> as
--   <tt>lua_Integer</tt>.
type LuaNumber = CDouble
class LuaImport a
luaimport' :: LuaImport a => Int -> a -> LuaCFunction
luaimportargerror :: LuaImport a => Int -> String -> a -> LuaCFunction

-- | Enumeration used by <tt>gc</tt> 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 <tt>lua_type</tt> in Lua Reference
--   Manual.
data LTYPE
TNONE :: LTYPE
TNIL :: LTYPE
TBOOLEAN :: LTYPE
TLIGHTUSERDATA :: LTYPE
TNUMBER :: LTYPE
TSTRING :: LTYPE
TTABLE :: LTYPE
TFUNCTION :: LTYPE
TUSERDATA :: LTYPE
TTHREAD :: LTYPE

-- | See <tt>LUA_MULTRET</tt> in Lua Reference Manual.
multret :: Int

-- | See <tt>LUA_REGISTRYINDEX</tt> in Lua Reference Manual.
registryindex :: Int

-- | See <tt>LUA_ENVIRONINDEX</tt> in Lua Reference Manual.
environindex :: Int

-- | See <tt>LUA_GLOBALSINDEX</tt> in Lua Reference Manual.
globalsindex :: Int

-- | See <tt>lua_atpanic</tt> in Lua Reference Manual.
atpanic :: LuaState -> FunPtr LuaCFunction -> IO (FunPtr LuaCFunction)

-- | See <tt>lua_call</tt> and <tt>lua_call</tt> in Lua Reference Manual.
--   This is a wrapper over <tt>lua_pcall</tt>, as <tt>lua_call</tt> is
--   unsafe in controlled environment like Haskell VM.
call :: LuaState -> Int -> Int -> IO Int

-- | See <tt>lua_checkstack</tt> in Lua Reference Manual.
checkstack :: LuaState -> Int -> IO Bool

-- | See <tt>lua_close</tt> in Lua Reference Manual.
close :: LuaState -> IO ()

-- | See <tt>lua_concat</tt> in Lua Reference Manual.
concat :: LuaState -> Int -> IO ()

-- | See <tt>lua_cpcall</tt> in Lua Reference Manual.
cpcall :: LuaState -> FunPtr LuaCFunction -> Ptr a -> IO Int

-- | See <tt>lua_createtable</tt> in Lua Reference Manual.
createtable :: LuaState -> Int -> Int -> IO ()
dump :: LuaState -> IO String

-- | See <tt>lua_equal</tt> in Lua Reference Manual.
equal :: LuaState -> Int -> Int -> IO Bool

-- | See <tt>lua_error</tt> in Lua Reference Manual. error :: LuaState
--   -&gt; IO Int error l = liftM fromIntegral (c_lua_error l)
--   
--   See <tt>lua_gc</tt> in Lua Reference Manual.
gc :: LuaState -> GCCONTROL -> Int -> IO Int

-- | See <tt>lua_getfenv</tt> in Lua Reference Manual.
getfenv :: LuaState -> Int -> IO ()

-- | See <tt>lua_getfield</tt> in Lua Reference Manual.
getfield :: LuaState -> Int -> String -> IO ()

-- | See <tt>lua_getglobal</tt> in Lua Reference Manual.
getglobal :: LuaState -> String -> IO ()

-- | See <tt>lua_getmetatable</tt> in Lua Reference Manual.
getmetatable :: LuaState -> Int -> IO Bool

-- | See <tt>lua_gettable</tt> in Lua Reference Manual.
gettable :: LuaState -> Int -> IO ()

-- | See <tt>lua_gettop</tt> in Lua Reference Manual.
gettop :: LuaState -> IO Int

-- | See <tt>lua_getupvalue</tt> in Lua Reference Manual.
getupvalue :: LuaState -> Int -> Int -> IO String

-- | See <tt>lua_insert</tt> in Lua Reference Manual.
insert :: LuaState -> Int -> IO ()

-- | See <tt>lua_isboolean</tt> in Lua Reference Manual.
isboolean :: LuaState -> Int -> IO Bool

-- | See <tt>lua_iscfunction</tt> in Lua Reference Manual.
iscfunction :: LuaState -> Int -> IO Bool

-- | See <tt>lua_isfunction</tt> in Lua Reference Manual.
isfunction :: LuaState -> Int -> IO Bool

-- | See <tt>lua_islightuserdata</tt> in Lua Reference Manual.
islightuserdata :: LuaState -> Int -> IO Bool

-- | See <tt>lua_isnil</tt> in Lua Reference Manual.
isnil :: LuaState -> Int -> IO Bool

-- | See <tt>lua_isnumber</tt> in Lua Reference Manual.
isnumber :: LuaState -> Int -> IO Bool

-- | See <tt>lua_isstring</tt> in Lua Reference Manual.
isstring :: LuaState -> Int -> IO Bool

-- | See <tt>lua_istable</tt> in Lua Reference Manual.
istable :: LuaState -> Int -> IO Bool

-- | See <tt>lua_isthread</tt> in Lua Reference Manual.
isthread :: LuaState -> Int -> IO Bool

-- | See <tt>lua_isuserdata</tt> in Lua Reference Manual.
isuserdata :: LuaState -> Int -> IO Bool

-- | See <tt>lua_lessthan</tt> in Lua Reference Manual.
lessthan :: LuaState -> Int -> Int -> IO Bool

-- | See <tt>lua_newstate</tt> and <tt>luaL_newstate</tt> in Lua Reference
--   Manual.
newstate :: IO LuaState

-- | See <tt>lua_newtable</tt> in Lua Reference Manual.
newtable :: LuaState -> IO ()

-- | See <tt>lua_newthread</tt> in Lua Reference Manual.
newthread :: LuaState -> IO LuaState

-- | See <tt>lua_newuserdata</tt> in Lua Reference Manual.
newuserdata :: LuaState -> Int -> IO (Ptr ())

-- | See <tt>lua_next</tt> in Lua Reference Manual.
next :: LuaState -> Int -> IO Bool

-- | See <tt>lua_objlen</tt> in Lua Reference Manual.
objlen :: LuaState -> Int -> IO Int

-- | See <tt>lua_pcall</tt> in Lua Reference Manual.
pcall :: LuaState -> Int -> Int -> Int -> IO Int

-- | See <tt>lua_pop</tt> in Lua Reference Manual.
pop :: LuaState -> Int -> IO ()

-- | See <tt>lua_pushboolean</tt> in Lua Reference Manual.
pushboolean :: LuaState -> Bool -> IO ()

-- | See <tt>lua_pushcclosure</tt> in Lua Reference Manual.
pushcclosure :: LuaState -> FunPtr LuaCFunction -> Int -> IO ()

-- | See <tt>lua_pushcfunction</tt> in Lua Reference Manual.
pushcfunction :: LuaState -> FunPtr LuaCFunction -> IO ()

-- | See <tt>lua_pushinteger</tt> in Lua Reference Manual.
pushinteger :: LuaState -> LuaInteger -> IO ()

-- | See <tt>lua_pushlightuserdata</tt> in Lua Reference Manual.
pushlightuserdata :: LuaState -> Ptr a -> IO ()

-- | See <tt>lua_pushnil</tt> in Lua Reference Manual.
pushnil :: LuaState -> IO ()

-- | See <tt>lua_pushnumber</tt> in Lua Reference Manual.
pushnumber :: LuaState -> LuaNumber -> IO ()

-- | See <tt>lua_pushstring</tt> in Lua Reference Manual.
pushstring :: LuaState -> String -> IO ()

-- | See <tt>lua_pushthread</tt> in Lua Reference Manual.
pushthread :: LuaState -> IO Bool

-- | See <tt>lua_pushvalue</tt> in Lua Reference Manual.
pushvalue :: LuaState -> Int -> IO ()

-- | See <tt>lua_rawequal</tt> in Lua Reference Manual.
rawequal :: LuaState -> Int -> Int -> IO Bool

-- | See <tt>lua_rawget</tt> in Lua Reference Manual.
rawget :: LuaState -> Int -> IO ()

-- | See <tt>lua_rawgeti</tt> in Lua Reference Manual.
rawgeti :: LuaState -> Int -> Int -> IO ()

-- | See <tt>lua_rawset</tt> in Lua Reference Manual.
rawset :: LuaState -> Int -> IO ()

-- | See <tt>lua_rawseti</tt> in Lua Reference Manual.
rawseti :: LuaState -> Int -> Int -> IO ()

-- | See <tt>lua_register</tt> in Lua Reference Manual.
register :: LuaState -> String -> FunPtr LuaCFunction -> IO ()

-- | See <tt>lua_remove</tt> in Lua Reference Manual.
remove :: LuaState -> Int -> IO ()

-- | See <tt>lua_replace</tt> in Lua Reference Manual.
replace :: LuaState -> Int -> IO ()

-- | See <tt>lua_resume</tt> in Lua Reference Manual.
resume :: LuaState -> Int -> IO Int

-- | See <tt>lua_setfenv</tt> in Lua Reference Manual.
setfenv :: LuaState -> Int -> IO Int

-- | See <tt>lua_setfield</tt> in Lua Reference Manual.
setfield :: LuaState -> Int -> String -> IO ()

-- | See <tt>lua_setglobal</tt> in Lua Reference Manual.
setglobal :: LuaState -> String -> IO ()

-- | See <tt>lua_setmetatable</tt> in Lua Reference Manual.
setmetatable :: LuaState -> Int -> IO ()

-- | See <tt>lua_settable</tt> in Lua Reference Manual.
settable :: LuaState -> Int -> IO ()

-- | See <tt>lua_settop</tt> in Lua Reference Manual.
settop :: LuaState -> Int -> IO ()

-- | See <tt>lua_setupvalue</tt> in Lua Reference Manual.
setupvalue :: LuaState -> Int -> Int -> IO String

-- | See <tt>lua_status</tt> in Lua Reference Manual.
status :: LuaState -> IO Int

-- | See <tt>lua_toboolean</tt> in Lua Reference Manual.
toboolean :: LuaState -> Int -> IO Bool

-- | See <tt>lua_tocfunction</tt> in Lua Reference Manual.
tocfunction :: LuaState -> Int -> IO (FunPtr LuaCFunction)

-- | See <tt>lua_tointeger</tt> in Lua Reference Manual.
tointeger :: LuaState -> Int -> IO LuaInteger

-- | See <tt>lua_tonumber</tt> in Lua Reference Manual.
tonumber :: LuaState -> Int -> IO CDouble

-- | See <tt>lua_topointer</tt> in Lua Reference Manual.
topointer :: LuaState -> Int -> IO (Ptr ())

-- | See <tt>lua_tostring</tt> in Lua Reference Manual.
tostring :: LuaState -> Int -> IO String

-- | See <tt>lua_tothread</tt> in Lua Reference Manual.
tothread :: LuaState -> Int -> IO LuaState

-- | See <tt>lua_touserdata</tt> in Lua Reference Manual.
touserdata :: LuaState -> Int -> IO (Ptr a)

-- | See <tt>lua_type</tt> in Lua Reference Manual.
ltype :: LuaState -> Int -> IO LTYPE

-- | See <tt>lua_typename</tt> in Lua Reference Manual.
typename :: LuaState -> LTYPE -> IO String

-- | See <tt>lua_upvalueindex</tt> in Lua Reference Manual.
upvalueindex :: Int -> Int

-- | See <tt>lua_xmove</tt> in Lua Reference Manual.
xmove :: LuaState -> LuaState -> Int -> IO ()

-- | See <tt>lua_yield</tt> in Lua Reference Manual.
yield :: LuaState -> Int -> IO Int

-- | See <tt>luaL_openlibs</tt> in Lua Reference Manual.
openlibs :: LuaState -> IO ()

-- | See <tt>luaL_loadfile</tt> in Lua Reference Manual.
loadfile :: LuaState -> String -> IO Int

-- | See <tt>luaL_loadstring</tt> in Lua Reference Manual.
loadstring :: LuaState -> String -> String -> IO Int

-- | See <tt>luaL_newmetatable</tt> in Lua Reference Manual.
newmetatable :: LuaState -> String -> IO Int

-- | See <tt>luaL_argerror</tt> in Lua Reference Manual. Contrary to the
--   manual, Haskell function does return with value less than zero.
argerror :: LuaState -> Int -> String -> IO CInt

-- | A value that can be pushed and poped from the Lua stack. All instances
--   are natural, except following:
--   
--   <ul>
--   <li><tt>LuaState</tt> push ignores its argument, pushes current
--   state</li>
--   <li><tt>()</tt> push ignores its argument, just pushes nil</li>
--   <li><tt>Ptr ()</tt> pushes light user data, peek checks for
--   lightuserdata or userdata</li>
--   </ul>
class StackValue a
push :: StackValue a => LuaState -> a -> IO ()
peek :: StackValue a => LuaState -> Int -> IO (Maybe a)
valuetype :: StackValue a => a -> LTYPE

-- | Call a Lua procedure. Use as:
--   
--   <pre>
--   callproc l "proc" "abc" (1::Int) (5.0::Double)
--   </pre>
callproc :: LuaCallProc a => LuaState -> String -> a

-- | Call a Lua function. Use as:
--   
--   <pre>
--   Just v &lt;- callfunc l "proc" "abc" (1::Int) (5.0::Double)
--   </pre>
callfunc :: LuaCallFunc a => LuaState -> String -> a

-- | Like <tt>getglobal</tt>, but knows about packages. e. g.
--   
--   <pre>
--   getglobal l "math.sin"
--   </pre>
--   
--   returns correct result
getglobal2 :: LuaState -> String -> IO ()

-- | Create new foreign Lua function. Function created can be called by Lua
--   engine. Remeber to free the pointer with <tt>freecfunction</tt>.
newcfunction :: LuaImport a => a -> IO (FunPtr LuaCFunction)

-- | Free function pointer created with <tt>newcfunction</tt>.
freecfunction :: FunPtr LuaCFunction -> IO ()

-- | Convert a Haskell function to Lua function. Any Haskell function can
--   be converted provided that:
--   
--   <ul>
--   <li>all arguments are instances of StackValue * return type is IO t,
--   where t is an instance of StackValue</li>
--   </ul>
--   
--   Any Haskell exception will be converted to a string and returned as
--   Lua error.
luaimport :: LuaImport a => a -> LuaCFunction

-- | Pushes Haskell function converted to a Lua function. All values
--   created will be garbage collected. Use as:
--   
--   <pre>
--   Lua.pushhsfunction l myfun
--   Lua.setglobal l "myfun"
--   </pre>
--   
--   You are not allowed to use <tt>lua_error</tt> anywhere, but use an
--   error code of (-1) to the same effect. Push error message as the sole
--   return value.
pushhsfunction :: LuaImport a => LuaState -> a -> IO ()

-- | Imports a Haskell function and registers it at global name.
registerhsfunction :: LuaImport a => LuaState -> String -> a -> IO ()
instance Eq LTYPE
instance Show LTYPE
instance Ord LTYPE
instance Eq GCCONTROL
instance Ord GCCONTROL
instance Show GCCONTROL
instance Enum GCCONTROL
instance (StackValue t, LuaCallFunc b) => LuaCallFunc (t -> b)
instance (StackValue t, LuaCallProc b) => LuaCallProc (t -> b)
instance StackValue t => LuaCallFunc (IO t)
instance LuaCallProc (IO t)
instance (StackValue a, LuaImport b) => LuaImport (a -> b)
instance StackValue a => LuaImport (IO a)
instance StackValue ()
instance StackValue LuaState
instance StackValue (Ptr a)
instance StackValue (FunPtr LuaCFunction)
instance StackValue Bool
instance StackValue String
instance StackValue Double
instance StackValue Int
instance StackValue LuaNumber
instance StackValue LuaInteger
instance Enum LTYPE


-- | Reads configuration files written in Lua. See
--   <tt>http://www.lua.org/</tt> for more details.
module Scripting.Lua.ConfigFile

-- | Represents an open configuration file.
data Config

-- | Opens a config file and returns an opaque reference to the file. You
--   must close this reference using <tt>close</tt> when you're done
--   reading the file.
openConfig :: FilePath -> IO Config

-- | Closes a configuration file.
closeConfig :: Config -> IO ()

-- | Returns a boolean value from a configuration file. Returns
--   <tt>False</tt> if the value is not defined in the file. Example:
--   
--   <pre>
--   someVal = true
--   </pre>
getBool :: Config -> String -> IO Bool

-- | Returns a string value from a configuration file. Returns the empty
--   string if the value is not defined in the file. Example:
--   
--   <pre>
--   someVal = "foo"
--   </pre>
getString :: Config -> String -> IO String

-- | Returns an integer value from a configuration file. Example:
--   
--   <pre>
--   someVal = 2
--   </pre>
getInt :: Config -> String -> IO (Maybe Int)

-- | Returns a double value from a configuration file. Example:
--   
--   <pre>
--   someVal = 3.1415926
--   </pre>
getDouble :: Config -> String -> IO (Maybe Double)

-- | Returns a list of strings (i.e. a Lua table in which the keys are
--   integers and the values are strings) from a configuration file.
--   Example:
--   
--   <pre>
--   someVal = { "foo", "bar", "baz" }
--   </pre>
getList :: Config -> String -> IO [String]

-- | Returns a list of lists, i.e. a Lua table of tables. In the outer
--   table, the keys are integers and the values are tables, and in the
--   inner tables, the keys are integers and the values are strings.
--   Example:
--   
--   <pre>
--   someVal = {
--      { "foo one", "foo two", "foo three" },
--      { "bar one", "bar two", "bar three" }
--   }
--   </pre>
getNestedLists :: Config -> String -> IO [[String]]

-- | Returns an association list, i.e. a Lua table in which the keys and
--   values are strings. Example:
--   
--   <pre>
--   someVal = {
--      one = "foo",
--      two = "bar",
--      three = "baz"
--   }
--   </pre>
getAssocList :: Config -> String -> IO [(String, String)]

-- | Returns a list of association lists, i.e. a Lua table of tables. In
--   the outer table, the keys are integers and the values are tables, and
--   in the inner tables, the keys and values are strings. Example:
--   
--   <pre>
--   someVal = {
--      {
--         foo = "aaa",
--         bar = "bbb",
--         baz = "ccc"
--      },
--      {
--         foo = "ddd",
--         bar = "eee",
--         baz = "fff"
--      }
--   }
--   </pre>
getListOfAssocLists :: Config -> String -> IO [[(String, String)]]

-- | Returns an association list of association lists, i.e. a Lua table of
--   tables. In the outer table, the keys are strings and the values are
--   tables, and in the inner tables, the keys and values are strings.
--   Example:
--   
--   <pre>
--   someVal = {
--      something = {
--         foo = "aaa",
--         bar = "bbb",
--         baz = "ccc"
--      },
--      somethingElse = {
--         foo = "ddd",
--         bar = "eee",
--         baz = "fff"
--      }
--   }
--   </pre>
getNestedAssocLists :: Config -> String -> IO [(String, [(String, String)])]

-- | Thrown when an error occurs in reading a configuration file.
data ConfigFileException
instance Typeable ConfigFileException
instance Show ConfigFileException
instance Exception ConfigFileException
