diff options
| author | Alexander Pickering <alex@cogarr.net> | 2020-07-05 17:18:56 -0400 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2020-07-05 17:18:56 -0400 |
| commit | e87b06ee0fe2a588b72a356bbb8378899365d626 (patch) | |
| tree | 0d0acd945a70644835e8958425e6d5e6c10196a6 /src/ext.lua | |
| parent | d2ba262c5307aa14c325ef53d8e4e56a5ece0376 (diff) | |
| download | mdoc-e87b06ee0fe2a588b72a356bbb8378899365d626.tar.gz mdoc-e87b06ee0fe2a588b72a356bbb8378899365d626.tar.bz2 mdoc-e87b06ee0fe2a588b72a356bbb8378899365d626.zip | |
Add rockspec
Add a rockspec and move the files around so that luarocks can
install it correctly
Diffstat (limited to 'src/ext.lua')
| -rw-r--r-- | src/ext.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/ext.lua b/src/ext.lua new file mode 100644 index 0000000..1c05b9f --- /dev/null +++ b/src/ext.lua @@ -0,0 +1,38 @@ +--[[
+Extensions that don't belong anywhere else
+]]
+
+-- Override tostring to display more info about the table
+local old_tostring = tostring
+local numtabs = 0
+local printed_tables = {}
+function tostring(el)
+ if type(el) == "table" and printed_tables[el] == nil then
+ printed_tables[el] = true
+ numtabs = numtabs + 1
+ local strbuilder = {"{"}
+ for k,v in pairs(el) do
+ strbuilder[#strbuilder + 1] = string.format("%s%s : %s", string.rep("\t",numtabs), tostring(k), tostring(v))
+ end
+ printed_tables[el] = nil
+ strbuilder[#strbuilder + 1] = string.rep("\t",numtabs - 1) .. "}"
+ numtabs = numtabs - 1
+ return table.concat(strbuilder,"\n")
+ end
+ return old_tostring(el)
+end
+
+--functions to save my hand
+function assertf(bool,msg,...)
+ if not bool then
+ error(string.format(msg,...),2)
+ end
+end
+
+function errorf(fmt,...)
+ error(string.format(fmt,...),2)
+end
+
+function printf(fmt,...)
+ print(string.format(fmt,...))
+end
|
