aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2018-10-15 07:53:07 +0200
committerAlbert Krewinkel <albert@zeitkraut.de>2018-10-15 07:56:35 +0200
commit594d36437be36cdd6b508a47d678e871cc181613 (patch)
tree6651f2e9e2ba269d0ca344ecce922b87c20df2e5 /src
parent49d0f58f248493768f0941f452daf66dfeacc1c5 (diff)
downloadpandoc-594d36437be36cdd6b508a47d678e871cc181613.tar.gz
Lua filters: rename ReaderOptions fields, use snake_case
Snake case is used in most variable names, using camelCase for these fields was an oversight. A metatable is added to ensure that the old field names remain functional.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Lua/StackInstances.hs33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Lua/StackInstances.hs b/src/Text/Pandoc/Lua/StackInstances.hs
index 25e81bb64..2d7b9c583 100644
--- a/src/Text/Pandoc/Lua/StackInstances.hs
+++ b/src/Text/Pandoc/Lua/StackInstances.hs
@@ -359,9 +359,32 @@ instance Pushable ReaderOptions where
LuaUtil.addField "extensions" extensions
LuaUtil.addField "standalone" standalone
LuaUtil.addField "columns" columns
- LuaUtil.addField "tabStop" tabStop
- LuaUtil.addField "indentedCodeClasses" indentedCodeClasses
+ LuaUtil.addField "tab_stop" tabStop
+ LuaUtil.addField "indented_code_classes" indentedCodeClasses
LuaUtil.addField "abbreviations" abbreviations
- LuaUtil.addField "defaultImageExtension" defaultImageExtension
- LuaUtil.addField "trackChanges" trackChanges
- LuaUtil.addField "stripComments" stripComments
+ LuaUtil.addField "default_image_extension" defaultImageExtension
+ LuaUtil.addField "track_changes" trackChanges
+ LuaUtil.addField "strip_comments" stripComments
+
+ -- add metatable
+ let indexReaderOptions :: AnyValue -> AnyValue -> Lua Lua.NumResults
+ indexReaderOptions _tbl (AnyValue key) = do
+ Lua.ltype key >>= \case
+ Lua.TypeString -> Lua.peek key >>= \case
+ "defaultImageExtension" -> Lua.push defaultImageExtension
+ "indentedCodeClasses" -> Lua.push indentedCodeClasses
+ "stripComments" -> Lua.push stripComments
+ "tabStop" -> Lua.push tabStop
+ "trackChanges" -> Lua.push trackChanges
+ _ -> Lua.pushnil
+ _ -> Lua.pushnil
+ return 1
+ Lua.newtable
+ LuaUtil.addFunction "__index" indexReaderOptions
+ Lua.setmetatable (Lua.nthFromTop 2)
+
+-- | Dummy type to allow values of arbitrary Lua type.
+newtype AnyValue = AnyValue StackIndex
+
+instance Peekable AnyValue where
+ peek = return . AnyValue