{-# LANGUAGE CPP #-} {-# LANGUAGE ForeignFunctionInterface #-} {-| Module : Foreign.Lua.Api.SafeBindings Copyright : © 2017 Albert Krewinkel License : MIT Maintainer : Albert Krewinkel Stability : beta Portability : ForeignFunctionInterface Haskell bindings to safe, @longjmp@ catching wrappers of Lua C API functions. Functions in this module follow a custom protocol. If an error happens (i.e., if the lua status is not 0), the status code is returned as a negative number. Results of a successful execution of the wrapped function are returned as non-negative numbers. This is possible because all (supported) lua API functions are either safe and don't need wrapping, or return @void@, @size_t@ or a non-negative @int@. -} module Foreign.Lua.Api.SafeBindings where import Foreign.C import Foreign.Lua.Api.Types import Foreign.Ptr #include "safer-api.h" #if LUA_VERSION_NUM >= 502 -- | Wrapper around which catches any @longjmp@s. foreign import ccall "safer-api.h hslua_compare" hslua_compare :: LuaState -> CInt -> CInt -> CInt -> IO CInt #endif -- | Wrapper around which catches any @longjmp@s. foreign import ccall "safer-api.h hslua_concat" hslua_concat :: LuaState -> CInt -> IO CInt -- | Wrapper around which catches any @longjmp@s. foreign import ccall "safer-api.h hslua_getfield" hslua_getfield :: LuaState -> CInt -> Ptr CChar -> IO CInt -- | Wrapper around which catches any @longjmp@s. foreign import ccall "safer-api.h hslua_getglobal" hslua_getglobal :: LuaState -> Ptr CChar -> IO CInt -- | Wrapper around which catches any @longjmp@s. foreign import ccall "safer-api.h hslua_gettable" hslua_gettable :: LuaState -> CInt -> IO CInt -- | Wrapper around which catches any @longjmp@s. foreign import ccall "safer-api.h hslua_next" hslua_next :: LuaState -> CInt -> IO CInt -- | Wrapper around which catches any @longjmp@s. foreign import ccall "safer-api.h hslua_setfield" hslua_setfield :: LuaState -> CInt -> Ptr CChar -> IO CInt -- | Wrapper around which catches any @longjmp@s. foreign import ccall "safer-api.h hslua_setglobal" hslua_setglobal :: LuaState -> Ptr CChar -> IO CInt -- | Wrapper around which catches any @longjmp@s. foreign import ccall "safer-api.h hslua_settable" hslua_settable :: LuaState -> CInt -> IO CInt