@@ -10,7 +10,8 @@ Portability : ForeignFunctionInterface
1010Provide a lua module containing a selection of useful Text functions.
1111-}
1212module Foreign.Lua.Module.Text
13- ( pushModuleText
13+ ( pushModule
14+ , pushModuleText
1415 , preloadTextModule
1516 )where
1617
@@ -22,38 +23,25 @@ import Foreign.Lua (NumResults, Lua, Peekable, Pushable, ToHaskellFunction)
2223import qualified Foreign.Lua as Lua
2324import qualified Data.Text as T
2425
25- -- | Pushes the @text@ module to the lua stack.
26- pushModuleText :: Lua NumResults
27- pushModuleText = do
26+ -- | Pushes the @text@ module to the Lua stack.
27+ pushModule :: Lua NumResults
28+ pushModule = do
2829 Lua. newtable
29- addFunction " lower" (return . T. toLower :: Text -> Lua Text )
30- addFunction " upper" (return . T. toUpper :: Text -> Lua Text )
31- addFunction " reverse" (return . T. reverse :: Text -> Lua Text )
32- addFunction " len" (return . fromIntegral . T. length :: Text -> Lua Lua. Integer )
33- addFunction " sub" sub
30+ Lua. addfunction " lower" (return . T. toLower :: Text -> Lua Text )
31+ Lua. addfunction " upper" (return . T. toUpper :: Text -> Lua Text )
32+ Lua. addfunction " reverse" (return . T. reverse :: Text -> Lua Text )
33+ Lua. addfunction " len" (return . fromIntegral . T. length :: Text -> Lua Lua. Integer )
34+ Lua. addfunction " sub" sub
3435 return 1
3536
37+ -- | Legacy alias for '@pushModule@'.
38+ pushModuleText :: Lua NumResults
39+ pushModuleText = pushModule
40+
3641-- | Add the text module under the given name to the table of preloaded
3742-- packages.
3843preloadTextModule :: String -> Lua ()
39- preloadTextModule = flip addPackagePreloader pushModuleText
40-
41- -- | Registers a preloading function. Takes an module name and the Lua operation
42- -- which produces the package.
43- addPackagePreloader :: String -> Lua NumResults -> Lua ()
44- addPackagePreloader name modulePusher = do
45- Lua. getfield Lua. registryindex Lua. preloadTableRegistryField
46- Lua. pushHaskellFunction modulePusher
47- Lua. setfield (- 2 ) name
48- Lua. pop 1
49-
50- -- | Attach a function to the table at the top of the stack, using the given
51- -- name.
52- addFunction :: ToHaskellFunction a => String -> a -> Lua ()
53- addFunction name fn = do
54- Lua. push name
55- Lua. pushHaskellFunction fn
56- Lua. rawset (- 3 )
44+ preloadTextModule = flip Lua. preloadhs pushModule
5745
5846-- | Returns a substring, using Lua's string indexing rules.
5947sub :: Text -> Lua. Integer -> Lua. Optional Lua. Integer -> Lua Text
0 commit comments