Export pushList which pushes lists to the stack
Having this function can serve as documentation by making the pushed
type more explicit. It also helps to avoid problems with overlapping
instances.
@@ -41,6 +41,7 @@ Sending haskell objects to the lua stack.
-}
module Foreign.Lua.Types.ToLuaStack
( ToLuaStack (..)
+ , pushList
) where
import Control.Monad (zipWithM_)
@@ -94,7 +95,10 @@ instance ToLuaStack [Char] where
push = push . T.pack
instance ToLuaStack a => ToLuaStack [a] where
- push xs = do
+ push = pushList
+
+pushList :: ToLuaStack a => [a] -> Lua ()
+pushList xs = do
let setField i x = push x *> rawseti (-2) i
newtable
zipWithM_ setField [1..] xs
