Skip to content

Commit

Permalink
Lua: Remove prefixes from Lua type names
Browse files Browse the repository at this point in the history
Lua type names were inconsistent with regard to the use of prefixes; all
prefixes are removed now, and Lua types now have the same name as the
Haskell types.

The use of app-specific prefixes is suggested by the Lua manual to avoid
collisions. However, this shouldn't be a problem with pandoc, as it
cannot be used as a Lua package.

Closes: #8574
  • Loading branch information
tarleb committed Oct 14, 2024
1 parent 734227a commit d399943
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 13 deletions.
4 changes: 4 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ flags: +embed_data_files
constraints: skylighting-format-blaze-html >= 0.1.1.2,
skylighting-format-context >= 0.1.0.2

source-repository-package
type: git
location: https://github.com/pandoc/pandoc-lua-marshal.git
tag: 2dc58d431bb3e4d55999db03c470fbf32970b3d5
4 changes: 2 additions & 2 deletions pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/Chunks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pushChunk :: LuaError e => Pusher e Chunk
pushChunk = pushUD typeChunk

typeChunk :: LuaError e => DocumentedType e Chunk
typeChunk = deftype "pandoc.Chunk"
typeChunk = deftype "Chunk"
[ operation Tostring $ lambda
### liftPure show
<#> udparam typeChunk "chunk" "chunk to print in native format"
Expand Down Expand Up @@ -103,7 +103,7 @@ pushChunkedDoc = pushUD typeChunkedDoc

-- | Lua type for 'ChunkedDoc' values.
typeChunkedDoc :: LuaError e => DocumentedType e ChunkedDoc
typeChunkedDoc = deftype "pandoc.ChunkedDoc"
typeChunkedDoc = deftype "ChunkedDoc"
[]
[ readonly "chunks"
"list of chunks that make up the document"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Text.Pandoc.Lua.Marshal.LogMessage (pushLogMessage)

-- | Lua type used for the @CommonState@ object.
typeCommonState :: LuaError e => DocumentedType e CommonState
typeCommonState = deftype "pandoc CommonState" []
typeCommonState = deftype "CommonState" []
[ readonly "input_files" "input files passed to pandoc"
(pushPandocList pushString, stInputFiles)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import qualified Data.Aeson as Aeson

-- | Type definition for pandoc log messages.
typeLogMessage :: LuaError e => DocumentedType e LogMessage
typeLogMessage = deftype "pandoc LogMessage"
typeLogMessage = deftype "LogMessage"
[ operation Index $ defun "__tostring"
### liftPure showLogMessage
<#> udparam typeLogMessage "msg" "object"
Expand Down
4 changes: 2 additions & 2 deletions pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/Sources.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Text.Parsec (SourcePos, sourceName)
pushSources :: LuaError e => Pusher e Sources
pushSources (Sources srcs) = do
pushList (pushUD typeSource) srcs
newListMetatable "pandoc Sources" $ do
newListMetatable "Sources" $ do
pushName "__tostring"
pushHaskellFunction $ do
sources <- forcePeek $ peekList (peekUD typeSource) (nthBottom 1)
Expand All @@ -43,7 +43,7 @@ peekSources idx = liftLua (ltype idx) >>= \case

-- | Source object type.
typeSource :: LuaError e => DocumentedType e (SourcePos, Text)
typeSource = deftype "pandoc input source"
typeSource = deftype "Source"
[ operation Tostring $ lambda
### liftPure snd
<#> udparam typeSource "srcs" "Source to print in native format"
Expand Down
2 changes: 1 addition & 1 deletion pandoc-lua-engine/src/Text/Pandoc/Lua/Marshal/Template.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ peekTemplate idx = liftLua (ltype idx) >>= \case

-- | Template object type.
typeTemplate :: LuaError e => DocumentedType e (Template Text)
typeTemplate = deftype "pandoc Template" [] []
typeTemplate = deftype "Template" [] []
2 changes: 1 addition & 1 deletion pandoc-lua-engine/test/lua/module/pandoc-structure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ return {
test('returns a chunked doc', function ()
assert.are_equal(
pandoc.utils.type(structure.split_into_chunks(pandoc.Pandoc{})),
'pandoc.ChunkedDoc'
'ChunkedDoc'
)
end),
},
Expand Down
6 changes: 3 additions & 3 deletions pandoc-lua-engine/test/lua/module/pandoc-template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ return {
test('returns a Template', function ()
assert.are_equal(
pandoc.utils.type(template.compile('$title$')),
'pandoc Template'
'Template'
)
end),
test('returns a Template', function ()
local templ_path = pandoc.path.join{'lua', 'module', 'default.test'}
assert.are_equal(
pandoc.utils.type(template.compile('${ partial() }', templ_path)),
'pandoc Template'
'Template'
)
end),
test('fails if template has non-existing partial', function ()
Expand All @@ -76,7 +76,7 @@ return {
assert.are_equal(type(jats_template), 'string')
assert.are_equal(
pandoc.utils.type(template.compile(jats_template)),
'pandoc Template'
'Template'
)
end),
},
Expand Down
4 changes: 2 additions & 2 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ extra-deps:
- doctemplates-0.11.0.1
- typst-0.6
- hslua-module-doclayout-1.2.0
- pandoc-lua-marshal-0.2.9
- djot-0.1.2.2
- texmath-0.12.8.11
- commonmark-0.2.6.1
- commonmark-pandoc-0.2.2.2

- git: https://github.com/pandoc/pandoc-lua-marshal
commit: 2dc58d431bb3e4d55999db03c470fbf32970b3d5
ghc-options:
"$locals": -fhide-source-paths -Wno-missing-home-modules
resolver: lts-22.33
Expand Down

0 comments on commit d399943

Please sign in to comment.