{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Test.Tasty.Lua.Module
( pushModule )
where
import Data.ByteString (ByteString)
import Data.FileEmbed
import HsLua.Core
( HaskellFunction, LuaError, NumResults (..), Status (OK)
, dostringTrace, nth, rawset, throwErrorAsException )
import HsLua.Marshalling (pushName)
import Test.Tasty.Lua.Arbitrary
tastyScript :: ByteString
tastyScript :: ByteString
tastyScript = $(embedFile "tasty.lua")
pushModule :: LuaError e => HaskellFunction e
pushModule :: forall e. LuaError e => HaskellFunction e
pushModule = forall e. ByteString -> LuaE e Status
dostringTrace ByteString
tastyScript forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Status
OK -> CInt -> NumResults
NumResults CInt
1 forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ do
forall e. Name -> LuaE e ()
pushName Name
"arbitrary"
forall e. LuaE e ()
pushArbitraryTable
forall e. LuaError e => StackIndex -> LuaE e ()
rawset (CInt -> StackIndex
nth CInt
3)
forall e. LuaError e => LuaE e ()
registerDefaultGenerators
Status
_ -> forall e a. LuaError e => LuaE e a
throwErrorAsException
{-# INLINABLE pushModule #-}