rufus-lua-win 5.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (459) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +69 -0
  6. data/Rakefile +1 -0
  7. data/lib/rufus/lua/win.rb +18 -0
  8. data/lib/rufus/lua/win/version.rb +7 -0
  9. data/rufus-lua-win.gemspec +23 -0
  10. data/vendor/lua/bin/liblua.dll +0 -0
  11. data/vendor/lua/lib/lua/LuaXml.lua +119 -0
  12. data/vendor/lua/lib/lua/alien.lua +250 -0
  13. data/vendor/lua/lib/lua/alien/core.dll +0 -0
  14. data/vendor/lua/lib/lua/alien/struct.dll +0 -0
  15. data/vendor/lua/lib/lua/base.lua +536 -0
  16. data/vendor/lua/lib/lua/bin.lua +20 -0
  17. data/vendor/lua/lib/lua/bit.dll +0 -0
  18. data/vendor/lua/lib/lua/cdlua.dll +0 -0
  19. data/vendor/lua/lib/lua/cdluacontextplus.dll +0 -0
  20. data/vendor/lua/lib/lua/cdluagl.dll +0 -0
  21. data/vendor/lua/lib/lua/cdluaim.dll +0 -0
  22. data/vendor/lua/lib/lua/cdluapdf.dll +0 -0
  23. data/vendor/lua/lib/lua/copas.lua +543 -0
  24. data/vendor/lua/lib/lua/coxpcall.lua +57 -0
  25. data/vendor/lua/lib/lua/date.lua +745 -0
  26. data/vendor/lua/lib/lua/debug_ext.lua +84 -0
  27. data/vendor/lua/lib/lua/debug_init.lua +2 -0
  28. data/vendor/lua/lib/lua/des56.dll +0 -0
  29. data/vendor/lua/lib/lua/dist/config.lua +109 -0
  30. data/vendor/lua/lib/lua/dist/constraints.lua +271 -0
  31. data/vendor/lua/lib/lua/dist/depends.lua +601 -0
  32. data/vendor/lua/lib/lua/dist/git.lua +307 -0
  33. data/vendor/lua/lib/lua/dist/init.lua +278 -0
  34. data/vendor/lua/lib/lua/dist/manifest.lua +225 -0
  35. data/vendor/lua/lib/lua/dist/package.lua +583 -0
  36. data/vendor/lua/lib/lua/dist/sys.lua +367 -0
  37. data/vendor/lua/lib/lua/dist/utils.lua +130 -0
  38. data/vendor/lua/lib/lua/ex.dll +0 -0
  39. data/vendor/lua/lib/lua/fstable.lua +116 -0
  40. data/vendor/lua/lib/lua/getopt.lua +273 -0
  41. data/vendor/lua/lib/lua/git.lua +5 -0
  42. data/vendor/lua/lib/lua/git/core.dll +0 -0
  43. data/vendor/lua/lib/lua/git/objects.lua +121 -0
  44. data/vendor/lua/lib/lua/git/pack.lua +316 -0
  45. data/vendor/lua/lib/lua/git/protocol.lua +188 -0
  46. data/vendor/lua/lib/lua/git/repo.lua +283 -0
  47. data/vendor/lua/lib/lua/git/util.lua +233 -0
  48. data/vendor/lua/lib/lua/gzio.dll +0 -0
  49. data/vendor/lua/lib/lua/gzip.lua +81 -0
  50. data/vendor/lua/lib/lua/iconv.dll +0 -0
  51. data/vendor/lua/lib/lua/imlua.dll +0 -0
  52. data/vendor/lua/lib/lua/imlua_fftw.dll +0 -0
  53. data/vendor/lua/lib/lua/imlua_jp2.dll +0 -0
  54. data/vendor/lua/lib/lua/imlua_process.dll +0 -0
  55. data/vendor/lua/lib/lua/imlua_process_omp.dll +0 -0
  56. data/vendor/lua/lib/lua/io_ext.lua +115 -0
  57. data/vendor/lua/lib/lua/iuplua.dll +0 -0
  58. data/vendor/lua/lib/lua/iuplua_mglplot.dll +0 -0
  59. data/vendor/lua/lib/lua/iuplua_pplot.dll +0 -0
  60. data/vendor/lua/lib/lua/iupluacd.dll +0 -0
  61. data/vendor/lua/lib/lua/iupluacontrols.dll +0 -0
  62. data/vendor/lua/lib/lua/iupluagl.dll +0 -0
  63. data/vendor/lua/lib/lua/iupluaim.dll +0 -0
  64. data/vendor/lua/lib/lua/iupluaimglib.dll +0 -0
  65. data/vendor/lua/lib/lua/iupluatuio.dll +0 -0
  66. data/vendor/lua/lib/lua/lanes-keeper.lua +302 -0
  67. data/vendor/lua/lib/lua/lanes.lua +591 -0
  68. data/vendor/lua/lib/lua/lanes/core.dll +0 -0
  69. data/vendor/lua/lib/lua/lcs.lua +55 -0
  70. data/vendor/lua/lib/lua/lemock.lua +659 -0
  71. data/vendor/lua/lib/lua/lfs.dll +0 -0
  72. data/vendor/lua/lib/lua/list.lua +375 -0
  73. data/vendor/lua/lib/lua/logging.lua +189 -0
  74. data/vendor/lua/lib/lua/logging/console.lua +22 -0
  75. data/vendor/lua/lib/lua/logging/email.lua +44 -0
  76. data/vendor/lua/lib/lua/logging/file.lua +55 -0
  77. data/vendor/lua/lib/lua/logging/rolling_file.lua +81 -0
  78. data/vendor/lua/lib/lua/logging/socket.lua +35 -0
  79. data/vendor/lua/lib/lua/logging/sql.lua +64 -0
  80. data/vendor/lua/lib/lua/loop/base.lua +68 -0
  81. data/vendor/lua/lib/lua/loop/cached.lua +312 -0
  82. data/vendor/lua/lib/lua/loop/collection/MapWithArrayOfKeys.lua +64 -0
  83. data/vendor/lua/lib/lua/loop/collection/ObjectCache.lua +39 -0
  84. data/vendor/lua/lib/lua/loop/collection/OrderedSet.lua +164 -0
  85. data/vendor/lua/lib/lua/loop/collection/PriorityQueue.lua +86 -0
  86. data/vendor/lua/lib/lua/loop/collection/UnorderedArray.lua +32 -0
  87. data/vendor/lua/lib/lua/loop/collection/UnorderedArraySet.lua +56 -0
  88. data/vendor/lua/lib/lua/loop/compiler/Arguments.lua +108 -0
  89. data/vendor/lua/lib/lua/loop/compiler/Conditional.lua +50 -0
  90. data/vendor/lua/lib/lua/loop/compiler/Expression.lua +215 -0
  91. data/vendor/lua/lib/lua/loop/component/base.lua +221 -0
  92. data/vendor/lua/lib/lua/loop/component/contained.lua +71 -0
  93. data/vendor/lua/lib/lua/loop/component/dynamic.lua +223 -0
  94. data/vendor/lua/lib/lua/loop/component/intercepted.lua +354 -0
  95. data/vendor/lua/lib/lua/loop/component/wrapped.lua +195 -0
  96. data/vendor/lua/lib/lua/loop/debug/Inspector.lua +521 -0
  97. data/vendor/lua/lib/lua/loop/debug/Matcher.lua +192 -0
  98. data/vendor/lua/lib/lua/loop/debug/Verbose.lua +266 -0
  99. data/vendor/lua/lib/lua/loop/debug/Viewer.lua +200 -0
  100. data/vendor/lua/lib/lua/loop/multiple.lua +105 -0
  101. data/vendor/lua/lib/lua/loop/object/Exception.lua +57 -0
  102. data/vendor/lua/lib/lua/loop/object/Publisher.lua +43 -0
  103. data/vendor/lua/lib/lua/loop/object/Wrapper.lua +39 -0
  104. data/vendor/lua/lib/lua/loop/scoped.lua +585 -0
  105. data/vendor/lua/lib/lua/loop/serial/FileStream.lua +48 -0
  106. data/vendor/lua/lib/lua/loop/serial/Serializer.lua +291 -0
  107. data/vendor/lua/lib/lua/loop/serial/SocketStream.lua +51 -0
  108. data/vendor/lua/lib/lua/loop/serial/StringStream.lua +47 -0
  109. data/vendor/lua/lib/lua/loop/simple.lua +75 -0
  110. data/vendor/lua/lib/lua/loop/table.lua +71 -0
  111. data/vendor/lua/lib/lua/loop/thread/CoSocket.lua +416 -0
  112. data/vendor/lua/lib/lua/loop/thread/IOScheduler.lua +170 -0
  113. data/vendor/lua/lib/lua/loop/thread/Scheduler.lua +327 -0
  114. data/vendor/lua/lib/lua/loop/thread/SocketScheduler.lua +88 -0
  115. data/vendor/lua/lib/lua/loop/thread/Timer.lua +54 -0
  116. data/vendor/lua/lib/lua/lpeg.dll +0 -0
  117. data/vendor/lua/lib/lua/ltn12.lua +292 -0
  118. data/vendor/lua/lib/lua/luaXML_lib.dll +0 -0
  119. data/vendor/lua/lib/lua/luacurl.dll +0 -0
  120. data/vendor/lua/lib/lua/luadoc/config.lua +34 -0
  121. data/vendor/lua/lib/lua/luadoc/doclet/debug.lua +46 -0
  122. data/vendor/lua/lib/lua/luadoc/doclet/formatter.lua +84 -0
  123. data/vendor/lua/lib/lua/luadoc/doclet/html.lua +289 -0
  124. data/vendor/lua/lib/lua/luadoc/doclet/html/file.lp +113 -0
  125. data/vendor/lua/lib/lua/luadoc/doclet/html/function.lp +64 -0
  126. data/vendor/lua/lib/lua/luadoc/doclet/html/index.lp +70 -0
  127. data/vendor/lua/lib/lua/luadoc/doclet/html/luadoc.css +286 -0
  128. data/vendor/lua/lib/lua/luadoc/doclet/html/menu.lp +55 -0
  129. data/vendor/lua/lib/lua/luadoc/doclet/html/module.lp +109 -0
  130. data/vendor/lua/lib/lua/luadoc/doclet/html/table.lp +15 -0
  131. data/vendor/lua/lib/lua/luadoc/doclet/raw.lua +12 -0
  132. data/vendor/lua/lib/lua/luadoc/init.lua +58 -0
  133. data/vendor/lua/lib/lua/luadoc/lp.lua +130 -0
  134. data/vendor/lua/lib/lua/luadoc/taglet/standard.lua +495 -0
  135. data/vendor/lua/lib/lua/luadoc/taglet/standard/tags.lua +171 -0
  136. data/vendor/lua/lib/lua/luadoc/util.lua +233 -0
  137. data/vendor/lua/lib/lua/luagl.dll +0 -0
  138. data/vendor/lua/lib/lua/luaglu.dll +0 -0
  139. data/vendor/lua/lib/lua/luaidl.lua +113 -0
  140. data/vendor/lua/lib/lua/luaidl/lex.lua +793 -0
  141. data/vendor/lua/lib/lua/luaidl/pre.lua +149 -0
  142. data/vendor/lua/lib/lua/luaidl/sin.lua +3631 -0
  143. data/vendor/lua/lib/lua/luarocks/add.lua +108 -0
  144. data/vendor/lua/lib/lua/luarocks/admin_remove.lua +87 -0
  145. data/vendor/lua/lib/lua/luarocks/build.lua +330 -0
  146. data/vendor/lua/lib/lua/luarocks/build/builtin.lua +253 -0
  147. data/vendor/lua/lib/lua/luarocks/build/cmake.lua +54 -0
  148. data/vendor/lua/lib/lua/luarocks/build/command.lua +32 -0
  149. data/vendor/lua/lib/lua/luarocks/build/make.lua +92 -0
  150. data/vendor/lua/lib/lua/luarocks/cache.lua +85 -0
  151. data/vendor/lua/lib/lua/luarocks/cfg.lua +449 -0
  152. data/vendor/lua/lib/lua/luarocks/command_line.lua +163 -0
  153. data/vendor/lua/lib/lua/luarocks/deps.lua +654 -0
  154. data/vendor/lua/lib/lua/luarocks/dir.lua +69 -0
  155. data/vendor/lua/lib/lua/luarocks/download.lua +90 -0
  156. data/vendor/lua/lib/lua/luarocks/fetch.lua +321 -0
  157. data/vendor/lua/lib/lua/luarocks/fetch/cvs.lua +44 -0
  158. data/vendor/lua/lib/lua/luarocks/fetch/git.lua +81 -0
  159. data/vendor/lua/lib/lua/luarocks/fetch/git_file.lua +17 -0
  160. data/vendor/lua/lib/lua/luarocks/fetch/hg.lua +54 -0
  161. data/vendor/lua/lib/lua/luarocks/fetch/sscm.lua +42 -0
  162. data/vendor/lua/lib/lua/luarocks/fetch/svn.lua +53 -0
  163. data/vendor/lua/lib/lua/luarocks/fs.lua +40 -0
  164. data/vendor/lua/lib/lua/luarocks/fs/lua.lua +676 -0
  165. data/vendor/lua/lib/lua/luarocks/fs/unix.lua +88 -0
  166. data/vendor/lua/lib/lua/luarocks/fs/unix/tools.lua +325 -0
  167. data/vendor/lua/lib/lua/luarocks/fs/win32.lua +107 -0
  168. data/vendor/lua/lib/lua/luarocks/fs/win32/tools.lua +334 -0
  169. data/vendor/lua/lib/lua/luarocks/help.lua +101 -0
  170. data/vendor/lua/lib/lua/luarocks/index.lua +172 -0
  171. data/vendor/lua/lib/lua/luarocks/install.lua +151 -0
  172. data/vendor/lua/lib/lua/luarocks/list.lua +35 -0
  173. data/vendor/lua/lib/lua/luarocks/loader.lua +228 -0
  174. data/vendor/lua/lib/lua/luarocks/make.lua +71 -0
  175. data/vendor/lua/lib/lua/luarocks/make_manifest.lua +34 -0
  176. data/vendor/lua/lib/lua/luarocks/manif.lua +360 -0
  177. data/vendor/lua/lib/lua/luarocks/manif_core.lua +75 -0
  178. data/vendor/lua/lib/lua/luarocks/new_version.lua +141 -0
  179. data/vendor/lua/lib/lua/luarocks/pack.lua +205 -0
  180. data/vendor/lua/lib/lua/luarocks/path.lua +315 -0
  181. data/vendor/lua/lib/lua/luarocks/persist.lua +173 -0
  182. data/vendor/lua/lib/lua/luarocks/refresh_cache.lua +30 -0
  183. data/vendor/lua/lib/lua/luarocks/remove.lua +135 -0
  184. data/vendor/lua/lib/lua/luarocks/rep.lua +313 -0
  185. data/vendor/lua/lib/lua/luarocks/require.lua +6 -0
  186. data/vendor/lua/lib/lua/luarocks/search.lua +399 -0
  187. data/vendor/lua/lib/lua/luarocks/show.lua +138 -0
  188. data/vendor/lua/lib/lua/luarocks/site_config.lua +23 -0
  189. data/vendor/lua/lib/lua/luarocks/tools/patch.lua +712 -0
  190. data/vendor/lua/lib/lua/luarocks/tools/tar.lua +144 -0
  191. data/vendor/lua/lib/lua/luarocks/tools/zip.lua +245 -0
  192. data/vendor/lua/lib/lua/luarocks/type_check.lua +267 -0
  193. data/vendor/lua/lib/lua/luarocks/unpack.lua +151 -0
  194. data/vendor/lua/lib/lua/luarocks/util.lua +420 -0
  195. data/vendor/lua/lib/lua/luarocks/validate.lua +164 -0
  196. data/vendor/lua/lib/lua/luars232.dll +0 -0
  197. data/vendor/lua/lib/lua/luasql/mysql.dll +0 -0
  198. data/vendor/lua/lib/lua/luasql/postgres.dll +0 -0
  199. data/vendor/lua/lib/lua/luasql/sqlite3.dll +0 -0
  200. data/vendor/lua/lib/lua/luaunit.lua +601 -0
  201. data/vendor/lua/lib/lua/lxp.dll +0 -0
  202. data/vendor/lua/lib/lua/lxp/lom.lua +60 -0
  203. data/vendor/lua/lib/lua/math_ext.lua +27 -0
  204. data/vendor/lua/lib/lua/mbox.lua +53 -0
  205. data/vendor/lua/lib/lua/md5.lua +19 -0
  206. data/vendor/lua/lib/lua/md5/core.dll +0 -0
  207. data/vendor/lua/lib/lua/metalua.lua +0 -0
  208. data/vendor/lua/lib/lua/metalua/ast_to_string.mlua +553 -0
  209. data/vendor/lua/lib/lua/metalua/base.lua +104 -0
  210. data/vendor/lua/lib/lua/metalua/bytecode.lua +0 -0
  211. data/vendor/lua/lib/lua/metalua/clopts.mlua +204 -0
  212. data/vendor/lua/lib/lua/metalua/compiler.lua +3 -0
  213. data/vendor/lua/lib/lua/metalua/dollar.mlua +24 -0
  214. data/vendor/lua/lib/lua/metalua/extension/H-runtime.mlua +216 -0
  215. data/vendor/lua/lib/lua/metalua/extension/H.mlua +22 -0
  216. data/vendor/lua/lib/lua/metalua/extension/anaphoric.mlua +54 -0
  217. data/vendor/lua/lib/lua/metalua/extension/clist.mlua +149 -0
  218. data/vendor/lua/lib/lua/metalua/extension/continue.mlua +53 -0
  219. data/vendor/lua/lib/lua/metalua/extension/localin.mlua +2 -0
  220. data/vendor/lua/lib/lua/metalua/extension/log.mlua +39 -0
  221. data/vendor/lua/lib/lua/metalua/extension/match.mlua +374 -0
  222. data/vendor/lua/lib/lua/metalua/extension/ternary.mlua +10 -0
  223. data/vendor/lua/lib/lua/metalua/extension/trycatch.mlua +189 -0
  224. data/vendor/lua/lib/lua/metalua/extension/types-runtime.mlua +159 -0
  225. data/vendor/lua/lib/lua/metalua/extension/types.mlua +352 -0
  226. data/vendor/lua/lib/lua/metalua/extension/withdo.mlua +30 -0
  227. data/vendor/lua/lib/lua/metalua/extension/xglobal-runtime.lua +41 -0
  228. data/vendor/lua/lib/lua/metalua/extension/xglobal.mlua +20 -0
  229. data/vendor/lua/lib/lua/metalua/extension/xloop.mlua +100 -0
  230. data/vendor/lua/lib/lua/metalua/extension/xmatch.mlua +216 -0
  231. data/vendor/lua/lib/lua/metalua/metaloop.mlua +76 -0
  232. data/vendor/lua/lib/lua/metalua/mlc.lua +0 -0
  233. data/vendor/lua/lib/lua/metalua/mlc_xcall.lua +119 -0
  234. data/vendor/lua/lib/lua/metalua/mlp.lua +0 -0
  235. data/vendor/lua/lib/lua/metalua/package2.lua +101 -0
  236. data/vendor/lua/lib/lua/metalua/runtime.lua +3 -0
  237. data/vendor/lua/lib/lua/metalua/string2.lua +44 -0
  238. data/vendor/lua/lib/lua/metalua/table2.lua +372 -0
  239. data/vendor/lua/lib/lua/metalua/walk.mlua +304 -0
  240. data/vendor/lua/lib/lua/metalua/walk/bindings.mlua +41 -0
  241. data/vendor/lua/lib/lua/metalua/walk/id.mlua +186 -0
  242. data/vendor/lua/lib/lua/metalua/walk/scope.lua +54 -0
  243. data/vendor/lua/lib/lua/mime.lua +87 -0
  244. data/vendor/lua/lib/lua/mime/core.dll +0 -0
  245. data/vendor/lua/lib/lua/mobdebug.lua +1484 -0
  246. data/vendor/lua/lib/lua/modules.lua +16 -0
  247. data/vendor/lua/lib/lua/object.lua +56 -0
  248. data/vendor/lua/lib/lua/oil/Exception.lua +26 -0
  249. data/vendor/lua/lib/lua/oil/arch.lua +27 -0
  250. data/vendor/lua/lib/lua/oil/arch/basic/client.lua +29 -0
  251. data/vendor/lua/lib/lua/oil/arch/basic/common.lua +13 -0
  252. data/vendor/lua/lib/lua/oil/arch/basic/server.lua +27 -0
  253. data/vendor/lua/lib/lua/oil/arch/cooperative/common.lua +10 -0
  254. data/vendor/lua/lib/lua/oil/arch/cooperative/server.lua +16 -0
  255. data/vendor/lua/lib/lua/oil/arch/corba/client.lua +39 -0
  256. data/vendor/lua/lib/lua/oil/arch/corba/common.lua +58 -0
  257. data/vendor/lua/lib/lua/oil/arch/corba/intercepted/client.lua +9 -0
  258. data/vendor/lua/lib/lua/oil/arch/corba/intercepted/server.lua +9 -0
  259. data/vendor/lua/lib/lua/oil/arch/corba/server.lua +35 -0
  260. data/vendor/lua/lib/lua/oil/arch/ludo/byref.lua +18 -0
  261. data/vendor/lua/lib/lua/oil/arch/ludo/client.lua +19 -0
  262. data/vendor/lua/lib/lua/oil/arch/ludo/common.lua +18 -0
  263. data/vendor/lua/lib/lua/oil/arch/ludo/server.lua +19 -0
  264. data/vendor/lua/lib/lua/oil/arch/typed/client.lua +27 -0
  265. data/vendor/lua/lib/lua/oil/arch/typed/common.lua +9 -0
  266. data/vendor/lua/lib/lua/oil/arch/typed/server.lua +18 -0
  267. data/vendor/lua/lib/lua/oil/assert.lua +87 -0
  268. data/vendor/lua/lib/lua/oil/builder.lua +45 -0
  269. data/vendor/lua/lib/lua/oil/builder/basic/client.lua +31 -0
  270. data/vendor/lua/lib/lua/oil/builder/basic/common.lua +11 -0
  271. data/vendor/lua/lib/lua/oil/builder/basic/server.lua +13 -0
  272. data/vendor/lua/lib/lua/oil/builder/cooperative/common.lua +11 -0
  273. data/vendor/lua/lib/lua/oil/builder/cooperative/server.lua +11 -0
  274. data/vendor/lua/lib/lua/oil/builder/corba/client.lua +13 -0
  275. data/vendor/lua/lib/lua/oil/builder/corba/common.lua +24 -0
  276. data/vendor/lua/lib/lua/oil/builder/corba/gencode.lua +13 -0
  277. data/vendor/lua/lib/lua/oil/builder/corba/intercepted/client.lua +11 -0
  278. data/vendor/lua/lib/lua/oil/builder/corba/intercepted/server.lua +11 -0
  279. data/vendor/lua/lib/lua/oil/builder/corba/server.lua +13 -0
  280. data/vendor/lua/lib/lua/oil/builder/lua/client.lua +11 -0
  281. data/vendor/lua/lib/lua/oil/builder/lua/server.lua +12 -0
  282. data/vendor/lua/lib/lua/oil/builder/ludo/byref.lua +13 -0
  283. data/vendor/lua/lib/lua/oil/builder/ludo/client.lua +13 -0
  284. data/vendor/lua/lib/lua/oil/builder/ludo/common.lua +14 -0
  285. data/vendor/lua/lib/lua/oil/builder/ludo/server.lua +13 -0
  286. data/vendor/lua/lib/lua/oil/builder/typed/client.lua +16 -0
  287. data/vendor/lua/lib/lua/oil/builder/typed/server.lua +12 -0
  288. data/vendor/lua/lib/lua/oil/compat.lua +846 -0
  289. data/vendor/lua/lib/lua/oil/component.lua +1 -0
  290. data/vendor/lua/lib/lua/oil/corba/giop.lua +301 -0
  291. data/vendor/lua/lib/lua/oil/corba/giop/Codec.lua +1568 -0
  292. data/vendor/lua/lib/lua/oil/corba/giop/CodecGen.lua +589 -0
  293. data/vendor/lua/lib/lua/oil/corba/giop/Exception.lua +25 -0
  294. data/vendor/lua/lib/lua/oil/corba/giop/Indexer.lua +63 -0
  295. data/vendor/lua/lib/lua/oil/corba/giop/Listener.lua +343 -0
  296. data/vendor/lua/lib/lua/oil/corba/giop/Messenger.lua +228 -0
  297. data/vendor/lua/lib/lua/oil/corba/giop/Referrer.lua +180 -0
  298. data/vendor/lua/lib/lua/oil/corba/giop/Requester.lua +462 -0
  299. data/vendor/lua/lib/lua/oil/corba/idl.lua +597 -0
  300. data/vendor/lua/lib/lua/oil/corba/idl/Compiler.lua +133 -0
  301. data/vendor/lua/lib/lua/oil/corba/idl/Importer.lua +235 -0
  302. data/vendor/lua/lib/lua/oil/corba/idl/Indexer.lua +95 -0
  303. data/vendor/lua/lib/lua/oil/corba/idl/Registry.lua +1821 -0
  304. data/vendor/lua/lib/lua/oil/corba/idl/ir.lua +847 -0
  305. data/vendor/lua/lib/lua/oil/corba/idl/sysex.lua +21 -0
  306. data/vendor/lua/lib/lua/oil/corba/iiop/Profiler.lua +200 -0
  307. data/vendor/lua/lib/lua/oil/corba/intercepted/Listener.lua +158 -0
  308. data/vendor/lua/lib/lua/oil/corba/intercepted/Requester.lua +181 -0
  309. data/vendor/lua/lib/lua/oil/corba/services/event.lua +126 -0
  310. data/vendor/lua/lib/lua/oil/corba/services/event/ConsumerAdmin.lua +50 -0
  311. data/vendor/lua/lib/lua/oil/corba/services/event/EventFactory.lua +15 -0
  312. data/vendor/lua/lib/lua/oil/corba/services/event/EventQueue.lua +37 -0
  313. data/vendor/lua/lib/lua/oil/corba/services/event/ProxyPushConsumer.lua +75 -0
  314. data/vendor/lua/lib/lua/oil/corba/services/event/ProxyPushSupplier.lua +62 -0
  315. data/vendor/lua/lib/lua/oil/corba/services/event/SingleDeferredDispatcher.lua +60 -0
  316. data/vendor/lua/lib/lua/oil/corba/services/event/SingleSynchronousDispatcher.lua +39 -0
  317. data/vendor/lua/lib/lua/oil/corba/services/event/SupplierAdmin.lua +50 -0
  318. data/vendor/lua/lib/lua/oil/corba/services/naming.lua +436 -0
  319. data/vendor/lua/lib/lua/oil/kernel/base/Acceptor.lua +268 -0
  320. data/vendor/lua/lib/lua/oil/kernel/base/Channels.lua +121 -0
  321. data/vendor/lua/lib/lua/oil/kernel/base/Connector.lua +147 -0
  322. data/vendor/lua/lib/lua/oil/kernel/base/Dispatcher.lua +99 -0
  323. data/vendor/lua/lib/lua/oil/kernel/base/Proxies.lua +86 -0
  324. data/vendor/lua/lib/lua/oil/kernel/base/Proxies/asynchronous.lua +56 -0
  325. data/vendor/lua/lib/lua/oil/kernel/base/Proxies/protected.lua +17 -0
  326. data/vendor/lua/lib/lua/oil/kernel/base/Proxies/synchronous.lua +17 -0
  327. data/vendor/lua/lib/lua/oil/kernel/base/Proxies/utils.lua +29 -0
  328. data/vendor/lua/lib/lua/oil/kernel/base/Receiver.lua +110 -0
  329. data/vendor/lua/lib/lua/oil/kernel/base/Servants.lua +207 -0
  330. data/vendor/lua/lib/lua/oil/kernel/base/Sockets.lua +44 -0
  331. data/vendor/lua/lib/lua/oil/kernel/cooperative/Receiver.lua +139 -0
  332. data/vendor/lua/lib/lua/oil/kernel/intercepted/Listener.lua +47 -0
  333. data/vendor/lua/lib/lua/oil/kernel/intercepted/Requester.lua +58 -0
  334. data/vendor/lua/lib/lua/oil/kernel/lua/Dispatcher.lua +76 -0
  335. data/vendor/lua/lib/lua/oil/kernel/lua/Proxies.lua +69 -0
  336. data/vendor/lua/lib/lua/oil/kernel/typed/Dispatcher.lua +91 -0
  337. data/vendor/lua/lib/lua/oil/kernel/typed/Proxies.lua +153 -0
  338. data/vendor/lua/lib/lua/oil/kernel/typed/Servants.lua +137 -0
  339. data/vendor/lua/lib/lua/oil/ludo/Codec.lua +66 -0
  340. data/vendor/lua/lib/lua/oil/ludo/CodecByRef.lua +103 -0
  341. data/vendor/lua/lib/lua/oil/ludo/Listener.lua +151 -0
  342. data/vendor/lua/lib/lua/oil/ludo/Referrer.lua +72 -0
  343. data/vendor/lua/lib/lua/oil/ludo/Requester.lua +107 -0
  344. data/vendor/lua/lib/lua/oil/oo.lua +1 -0
  345. data/vendor/lua/lib/lua/oil/port.lua +1 -0
  346. data/vendor/lua/lib/lua/oil/properties.lua +57 -0
  347. data/vendor/lua/lib/lua/oil/verbose.lua +133 -0
  348. data/vendor/lua/lib/lua/package_ext.lua +15 -0
  349. data/vendor/lua/lib/lua/parser.lua +268 -0
  350. data/vendor/lua/lib/lua/pl/Date.lua +555 -0
  351. data/vendor/lua/lib/lua/pl/List.lua +613 -0
  352. data/vendor/lua/lib/lua/pl/Map.lua +113 -0
  353. data/vendor/lua/lib/lua/pl/MultiMap.lua +62 -0
  354. data/vendor/lua/lib/lua/pl/OrderedMap.lua +151 -0
  355. data/vendor/lua/lib/lua/pl/Set.lua +153 -0
  356. data/vendor/lua/lib/lua/pl/app.lua +165 -0
  357. data/vendor/lua/lib/lua/pl/array2d.lua +501 -0
  358. data/vendor/lua/lib/lua/pl/class.lua +180 -0
  359. data/vendor/lua/lib/lua/pl/comprehension.lua +286 -0
  360. data/vendor/lua/lib/lua/pl/config.lua +176 -0
  361. data/vendor/lua/lib/lua/pl/data.lua +606 -0
  362. data/vendor/lua/lib/lua/pl/dir.lua +475 -0
  363. data/vendor/lua/lib/lua/pl/file.lua +70 -0
  364. data/vendor/lua/lib/lua/pl/func.lua +376 -0
  365. data/vendor/lua/lib/lua/pl/init.lua +68 -0
  366. data/vendor/lua/lib/lua/pl/input.lua +173 -0
  367. data/vendor/lua/lib/lua/pl/lapp.lua +407 -0
  368. data/vendor/lua/lib/lua/pl/lexer.lua +456 -0
  369. data/vendor/lua/lib/lua/pl/luabalanced.lua +264 -0
  370. data/vendor/lua/lib/lua/pl/operator.lua +201 -0
  371. data/vendor/lua/lib/lua/pl/path.lua +398 -0
  372. data/vendor/lua/lib/lua/pl/permute.lua +63 -0
  373. data/vendor/lua/lib/lua/pl/platf/luajava.lua +101 -0
  374. data/vendor/lua/lib/lua/pl/pretty.lua +285 -0
  375. data/vendor/lua/lib/lua/pl/seq.lua +551 -0
  376. data/vendor/lua/lib/lua/pl/sip.lua +344 -0
  377. data/vendor/lua/lib/lua/pl/strict.lua +70 -0
  378. data/vendor/lua/lib/lua/pl/stringio.lua +158 -0
  379. data/vendor/lua/lib/lua/pl/stringx.lua +440 -0
  380. data/vendor/lua/lib/lua/pl/tablex.lua +817 -0
  381. data/vendor/lua/lib/lua/pl/template.lua +103 -0
  382. data/vendor/lua/lib/lua/pl/test.lua +135 -0
  383. data/vendor/lua/lib/lua/pl/text.lua +243 -0
  384. data/vendor/lua/lib/lua/pl/utils.lua +550 -0
  385. data/vendor/lua/lib/lua/pl/xml.lua +689 -0
  386. data/vendor/lua/lib/lua/profiler.dll +0 -0
  387. data/vendor/lua/lib/lua/re.lua +248 -0
  388. data/vendor/lua/lib/lua/rex_onig.dll +0 -0
  389. data/vendor/lua/lib/lua/rex_pcre.dll +0 -0
  390. data/vendor/lua/lib/lua/rex_posix.dll +0 -0
  391. data/vendor/lua/lib/lua/rings.dll +0 -0
  392. data/vendor/lua/lib/lua/serialize.lua +193 -0
  393. data/vendor/lua/lib/lua/set.lua +149 -0
  394. data/vendor/lua/lib/lua/socket.lua +133 -0
  395. data/vendor/lua/lib/lua/socket/core.dll +0 -0
  396. data/vendor/lua/lib/lua/socket/ftp.lua +281 -0
  397. data/vendor/lua/lib/lua/socket/http.lua +350 -0
  398. data/vendor/lua/lib/lua/socket/smtp.lua +251 -0
  399. data/vendor/lua/lib/lua/socket/tp.lua +123 -0
  400. data/vendor/lua/lib/lua/socket/url.lua +297 -0
  401. data/vendor/lua/lib/lua/ssl.dll +0 -0
  402. data/vendor/lua/lib/lua/ssl.lua +93 -0
  403. data/vendor/lua/lib/lua/ssl/https.lua +138 -0
  404. data/vendor/lua/lib/lua/stable.lua +28 -0
  405. data/vendor/lua/lib/lua/std.lua +16 -0
  406. data/vendor/lua/lib/lua/strbuf.lua +32 -0
  407. data/vendor/lua/lib/lua/strict.lua +45 -0
  408. data/vendor/lua/lib/lua/string_ext.lua +274 -0
  409. data/vendor/lua/lib/lua/table_ext.lua +117 -0
  410. data/vendor/lua/lib/lua/tar.lua +262 -0
  411. data/vendor/lua/lib/lua/task.dll +0 -0
  412. data/vendor/lua/lib/lua/tree.lua +81 -0
  413. data/vendor/lua/lib/lua/unicode.dll +0 -0
  414. data/vendor/lua/lib/lua/verbose_require.lua +11 -0
  415. data/vendor/lua/lib/lua/vstruct.lua +86 -0
  416. data/vendor/lua/lib/lua/vstruct/ast.lua +192 -0
  417. data/vendor/lua/lib/lua/vstruct/ast/Bitpack.lua +33 -0
  418. data/vendor/lua/lib/lua/vstruct/ast/Generator.lua +174 -0
  419. data/vendor/lua/lib/lua/vstruct/ast/IO.lua +45 -0
  420. data/vendor/lua/lib/lua/vstruct/ast/List.lua +56 -0
  421. data/vendor/lua/lib/lua/vstruct/ast/Name.lua +20 -0
  422. data/vendor/lua/lib/lua/vstruct/ast/Repeat.lua +23 -0
  423. data/vendor/lua/lib/lua/vstruct/ast/Root.lua +19 -0
  424. data/vendor/lua/lib/lua/vstruct/ast/Table.lua +65 -0
  425. data/vendor/lua/lib/lua/vstruct/cursor.lua +81 -0
  426. data/vendor/lua/lib/lua/vstruct/io.lua +45 -0
  427. data/vendor/lua/lib/lua/vstruct/io/a.lua +24 -0
  428. data/vendor/lua/lib/lua/vstruct/io/b.lua +28 -0
  429. data/vendor/lua/lib/lua/vstruct/io/bigendian.lua +21 -0
  430. data/vendor/lua/lib/lua/vstruct/io/c.lua +25 -0
  431. data/vendor/lua/lib/lua/vstruct/io/defaults.lua +24 -0
  432. data/vendor/lua/lib/lua/vstruct/io/endianness.lua +41 -0
  433. data/vendor/lua/lib/lua/vstruct/io/f.lua +129 -0
  434. data/vendor/lua/lib/lua/vstruct/io/hostendian.lua +21 -0
  435. data/vendor/lua/lib/lua/vstruct/io/i.lua +42 -0
  436. data/vendor/lua/lib/lua/vstruct/io/littleendian.lua +21 -0
  437. data/vendor/lua/lib/lua/vstruct/io/m.lua +62 -0
  438. data/vendor/lua/lib/lua/vstruct/io/p.lua +23 -0
  439. data/vendor/lua/lib/lua/vstruct/io/s.lua +27 -0
  440. data/vendor/lua/lib/lua/vstruct/io/seekb.lua +18 -0
  441. data/vendor/lua/lib/lua/vstruct/io/seekf.lua +18 -0
  442. data/vendor/lua/lib/lua/vstruct/io/seekto.lua +18 -0
  443. data/vendor/lua/lib/lua/vstruct/io/u.lua +54 -0
  444. data/vendor/lua/lib/lua/vstruct/io/x.lua +34 -0
  445. data/vendor/lua/lib/lua/vstruct/io/z.lua +63 -0
  446. data/vendor/lua/lib/lua/vstruct/lexer.lua +100 -0
  447. data/vendor/lua/lib/lua/vstruct/pack.lua +142 -0
  448. data/vendor/lua/lib/lua/vstruct/test.lua +47 -0
  449. data/vendor/lua/lib/lua/vstruct/test/basic.lua +73 -0
  450. data/vendor/lua/lib/lua/vstruct/test/common.lua +100 -0
  451. data/vendor/lua/lib/lua/vstruct/test/fp-bigendian.lua +56 -0
  452. data/vendor/lua/lib/lua/vstruct/test/fp-littleendian.lua +56 -0
  453. data/vendor/lua/lib/lua/vstruct/test/struct-test-gen.lua +1230 -0
  454. data/vendor/lua/lib/lua/vstruct/unpack.lua +126 -0
  455. data/vendor/lua/lib/lua/wx.dll +0 -0
  456. data/vendor/lua/lib/lua/xml.lua +75 -0
  457. data/vendor/lua/lib/lua/zip.dll +0 -0
  458. data/vendor/lua/lib/lua/zlib.dll +0 -0
  459. metadata +529 -0
@@ -0,0 +1,176 @@
1
+ --- Reads configuration files into a Lua table.
2
+ -- Understands INI files, classic Unix config files, and simple
3
+ -- delimited columns of values.
4
+ --
5
+ -- # test.config
6
+ -- # Read timeout in seconds
7
+ -- read.timeout=10
8
+ -- # Write timeout in seconds
9
+ -- write.timeout=5
10
+ -- #acceptable ports
11
+ -- ports = 1002,1003,1004
12
+ --
13
+ -- -- readconfig.lua
14
+ -- require 'pl'
15
+ -- local t = config.read 'test.config'
16
+ -- print(pretty.write(t))
17
+ --
18
+ -- ### output #####
19
+ -- {
20
+ -- ports = {
21
+ -- 1002,
22
+ -- 1003,
23
+ -- 1004
24
+ -- },
25
+ -- write_timeout = 5,
26
+ -- read_timeout = 10
27
+ -- }
28
+ --
29
+ -- See the Guide for further @{06-data.md.Reading_Configuration_Files|discussion}
30
+ --
31
+ -- Dependencies: none
32
+ -- @module pl.config
33
+
34
+ local type,tonumber,ipairs,io, table = _G.type,_G.tonumber,_G.ipairs,_G.io,_G.table
35
+
36
+ local function split(s,re)
37
+ local res = {}
38
+ local t_insert = table.insert
39
+ re = '[^'..re..']+'
40
+ for k in s:gmatch(re) do t_insert(res,k) end
41
+ return res
42
+ end
43
+
44
+ local function strip(s)
45
+ return s:gsub('^%s+',''):gsub('%s+$','')
46
+ end
47
+
48
+ local function strip_quotes (s)
49
+ return s:gsub("['\"](.*)['\"]",'%1')
50
+ end
51
+
52
+ local config = {}
53
+
54
+ --- like io.lines(), but allows for lines to be continued with '\'.
55
+ -- @param file a file-like object (anything where read() returns the next line) or a filename.
56
+ -- Defaults to stardard input.
57
+ -- @return an iterator over the lines, or nil
58
+ -- @return error 'not a file-like object' or 'file is nil'
59
+ function config.lines(file)
60
+ local f,openf,err
61
+ local line = ''
62
+ if type(file) == 'string' then
63
+ f,err = io.open(file,'r')
64
+ if not f then return nil,err end
65
+ openf = true
66
+ else
67
+ f = file or io.stdin
68
+ if not file.read then return nil, 'not a file-like object' end
69
+ end
70
+ if not f then return nil, 'file is nil' end
71
+ return function()
72
+ local l = f:read()
73
+ while l do
74
+ -- does the line end with '\'?
75
+ local i = l:find '\\%s*$'
76
+ if i then -- if so,
77
+ line = line..l:sub(1,i-1)
78
+ elseif line == '' then
79
+ return l
80
+ else
81
+ l = line..l
82
+ line = ''
83
+ return l
84
+ end
85
+ l = f:read()
86
+ end
87
+ if openf then f:close() end
88
+ end
89
+ end
90
+
91
+ --- read a configuration file into a table
92
+ -- @param file either a file-like object or a string, which must be a filename
93
+ -- @param cnfg a configuration table that may contain these fields:
94
+ --
95
+ -- * `variablilize` make names into valid Lua identifiers (default `true`)
96
+ -- * `convert_numbers` function to convert values into numbers (default `tonumber`)
97
+ -- * `trim_space` ensure that there is no starting or trailing whitespace with values (default `true`)
98
+ -- * `trim_quotes` remove quotes from strings (default `false`)
99
+ -- * `list_delim` delimiter to use when separating columns (default ',')
100
+ -- * `ignore_assign` ignore any key-pair assignments (default `false`)
101
+ -- * `kepsep` use this as key-pair separator (default '=')
102
+ --
103
+ -- @return a table containing items, or nil
104
+ -- @return error message (same as @{config.lines})
105
+ function config.read(file,cnfg)
106
+ local f,openf,err
107
+ cnfg = cnfg or {}
108
+ local function check_cnfg (var,def)
109
+ local val = cnfg[var]
110
+ if val == nil then return def else return val end
111
+ end
112
+ local t = {}
113
+ local top_t = t
114
+ local variablilize = check_cnfg ('variabilize',true)
115
+ local list_delim = check_cnfg('list_delim',',')
116
+ local convert_numbers = check_cnfg('convert_numbers',tonumber)
117
+ if convert_numbers==true then convert_numbers = tonumber end
118
+ local trim_space = check_cnfg('trim_space',true)
119
+ local trim_quotes = check_cnfg('trim_quotes',false)
120
+ local ignore_assign = check_cnfg('ignore_assign',false)
121
+ local keysep = check_cnfg('keysep','=')
122
+ local keypat = keysep == ' ' and '%s+' or '%s*'..keysep..'%s*'
123
+
124
+ local function process_name(key)
125
+ if variablilize then
126
+ key = key:gsub('[^%w]','_')
127
+ end
128
+ return key
129
+ end
130
+
131
+ local function process_value(value)
132
+ if list_delim and value:find(list_delim) then
133
+ value = split(value,list_delim)
134
+ for i,v in ipairs(value) do
135
+ value[i] = process_value(v)
136
+ end
137
+ elseif convert_numbers and value:find('^[%d%+%-]') then
138
+ local val = convert_numbers(value)
139
+ if val then value = val end
140
+ end
141
+ if type(value) == 'string' then
142
+ if trim_space then value = strip(value) end
143
+ if trim_quotes then value = strip_quotes(value) end
144
+ end
145
+ return value
146
+ end
147
+
148
+ local iter,err = config.lines(file)
149
+ if not iter then return nil,err end
150
+ for line in iter do
151
+ -- strips comments
152
+ local ci = line:find('%s*[#;]')
153
+ if ci then line = line:sub(1,ci-1) end
154
+ -- and ignore blank lines
155
+ if line:find('^%s*$') then
156
+ elseif line:find('^%[') then -- section!
157
+ local section = process_name(line:match('%[([^%]]+)%]'))
158
+ t = top_t
159
+ t[section] = {}
160
+ t = t[section]
161
+ else
162
+ line = line:gsub('^%s*','')
163
+ local i1,i2 = line:find(keypat)
164
+ if i1 and not ignore_assign then -- key,value assignment
165
+ local key = process_name(line:sub(1,i1-1))
166
+ local value = process_value(line:sub(i2+1))
167
+ t[key] = value
168
+ else -- a plain list of values...
169
+ t[#t+1] = process_value(line)
170
+ end
171
+ end
172
+ end
173
+ return top_t
174
+ end
175
+
176
+ return config
@@ -0,0 +1,606 @@
1
+ --- Reading and querying simple tabular data.
2
+ --
3
+ -- data.read 'test.txt'
4
+ -- ==> {{10,20},{2,5},{40,50},fieldnames={'x','y'},delim=','}
5
+ --
6
+ -- Provides a way of creating basic SQL-like queries.
7
+ --
8
+ -- require 'pl'
9
+ -- local d = data.read('xyz.txt')
10
+ -- local q = d:select('x,y,z where x > 3 and z < 2 sort by y')
11
+ -- for x,y,z in q do
12
+ -- print(x,y,z)
13
+ -- end
14
+ --
15
+ -- See @{06-data.md.Reading_Columnar_Data|the Guide}
16
+ --
17
+ -- Dependencies: `pl.utils`, `pl.array2d` (fallback methods)
18
+ -- @module pl.data
19
+
20
+ local utils = require 'pl.utils'
21
+ local _DEBUG = rawget(_G,'_DEBUG')
22
+
23
+ local patterns,function_arg,usplit = utils.patterns,utils.function_arg,utils.split
24
+ local append,concat = table.insert,table.concat
25
+ local gsub = string.gsub
26
+ local io = io
27
+ local _G,print,type,tonumber,ipairs,setmetatable,pcall,error,setfenv = _G,print,type,tonumber,ipairs,setmetatable,pcall,error,setfenv
28
+
29
+
30
+ local data = {}
31
+
32
+ local parse_select
33
+
34
+ local function count(s,chr)
35
+ chr = utils.escape(chr)
36
+ local _,cnt = s:gsub(chr,' ')
37
+ return cnt
38
+ end
39
+
40
+ local function rstrip(s)
41
+ return s:gsub('%s+$','')
42
+ end
43
+
44
+ local function make_list(l)
45
+ return setmetatable(l,utils.stdmt.List)
46
+ end
47
+
48
+ local function split(s,delim)
49
+ return make_list(usplit(s,delim))
50
+ end
51
+
52
+ local function map(fun,t)
53
+ local res = {}
54
+ for i = 1,#t do
55
+ append(res,fun(t[i]))
56
+ end
57
+ return res
58
+ end
59
+
60
+ local function find(t,v)
61
+ for i = 1,#t do
62
+ if v == t[i] then return i end
63
+ end
64
+ end
65
+
66
+ local DataMT = {
67
+ column_by_name = function(self,name)
68
+ if type(name) == 'number' then
69
+ name = '$'..name
70
+ end
71
+ local arr = {}
72
+ for res in data.query(self,name) do
73
+ append(arr,res)
74
+ end
75
+ return make_list(arr)
76
+ end,
77
+
78
+ copy_select = function(self,condn)
79
+ condn = parse_select(condn,self)
80
+ local iter = data.query(self,condn)
81
+ local res = {}
82
+ local row = make_list{iter()}
83
+ while #row > 0 do
84
+ append(res,row)
85
+ row = make_list{iter()}
86
+ end
87
+ res.delim = self.delim
88
+ return data.new(res,split(condn.fields,','))
89
+ end,
90
+
91
+ column_names = function(self)
92
+ return self.fieldnames
93
+ end,
94
+ }
95
+
96
+ local array2d
97
+
98
+ DataMT.__index = function(self,name)
99
+ local f = DataMT[name]
100
+ if f then return f end
101
+ if not array2d then
102
+ array2d = require 'pl.array2d'
103
+ end
104
+ return array2d[name]
105
+ end
106
+
107
+ --- return a particular column as a list of values (method).
108
+ -- @param name either name of column, or numerical index.
109
+ -- @function Data.column_by_name
110
+
111
+ --- return a query iterator on this data (method).
112
+ -- @param condn the query expression
113
+ -- @function Data.select
114
+ -- @see data.query
115
+
116
+ --- return a row iterator on this data (method).
117
+ -- @param condn the query expression
118
+ -- @function Data.select_row
119
+
120
+ --- return a new data object based on this query (method).
121
+ -- @param condn the query expression
122
+ -- @function Data.copy_select
123
+
124
+ --- return the field names of this data object (method).
125
+ -- @function Data.column_names
126
+
127
+ --- write out a row (method).
128
+ -- @param f file-like object
129
+ -- @function Data.write_row
130
+
131
+ --- write data out to file (method).
132
+ -- @param f file-like object
133
+ -- @function Data.write
134
+
135
+
136
+ -- [guessing delimiter] We check for comma, tab and spaces in that order.
137
+ -- [issue] any other delimiters to be checked?
138
+ local delims = {',','\t',' ',';'}
139
+
140
+ local function guess_delim (line)
141
+ if line=='' then return ' ' end
142
+ for _,delim in ipairs(delims) do
143
+ if count(line,delim) > 0 then
144
+ return delim == ' ' and '%s+' or delim
145
+ end
146
+ end
147
+ return ' '
148
+ end
149
+
150
+ -- [file parameter] If it's a string, we try open as a filename. If nil, then
151
+ -- either stdin or stdout depending on the mode. Otherwise, check if this is
152
+ -- a file-like object (implements read or write depending)
153
+ local function open_file (f,mode)
154
+ local opened, err
155
+ local reading = mode == 'r'
156
+ if type(f) == 'string' then
157
+ if f == 'stdin' then
158
+ f = io.stdin
159
+ elseif f == 'stdout' then
160
+ f = io.stdout
161
+ else
162
+ f,err = io.open(f,mode)
163
+ if not f then return nil,err end
164
+ opened = true
165
+ end
166
+ end
167
+ if f and ((reading and not f.read) or (not reading and not f.write)) then
168
+ return nil, "not a file-like object"
169
+ end
170
+ return f,nil,opened
171
+ end
172
+
173
+ local function all_n ()
174
+
175
+ end
176
+
177
+ --- read a delimited file in a Lua table.
178
+ -- By default, attempts to treat first line as separated list of fieldnames.
179
+ -- @param file a filename or a file-like object (default stdin)
180
+ -- @param cnfg options table: can override delim (a string pattern), fieldnames (a list),
181
+ -- specify no_convert (default is to convert), numfields (indices of columns known
182
+ -- to be numbers) and thousands_dot (thousands separator in Excel CSV is '.')
183
+ function data.read(file,cnfg)
184
+ local convert,err,opened
185
+ local D = {}
186
+ if not cnfg then cnfg = {} end
187
+ local f,err,opened = open_file(file,'r')
188
+ if not f then return nil, err end
189
+ local thousands_dot = cnfg.thousands_dot
190
+
191
+ local function try_tonumber(x)
192
+ if thousands_dot then x = x:gsub('%.(...)','%1') end
193
+ return tonumber(x)
194
+ end
195
+
196
+ local line = f:read()
197
+ if not line then return nil, "empty file" end
198
+ -- first question: what is the delimiter?
199
+ D.delim = cnfg.delim and cnfg.delim or guess_delim(line)
200
+ local delim = D.delim
201
+ local collect_end = cnfg.last_field_collect
202
+ local numfields = cnfg.numfields
203
+ -- some space-delimited data starts with a space. This should not be a column,
204
+ -- although it certainly would be for comma-separated, etc.
205
+ local strip
206
+ if delim == '%s+' and line:find(delim) == 1 then
207
+ strip = function(s) return s:gsub('^%s+','') end
208
+ line = strip(line)
209
+ end
210
+ -- first line will usually be field names. Unless fieldnames are specified,
211
+ -- we check if it contains purely numerical values for the case of reading
212
+ -- plain data files.
213
+ if not cnfg.fieldnames then
214
+ local fields = split(line,delim)
215
+ local nums = map(tonumber,fields)
216
+ if #nums == #fields then
217
+ convert = tonumber
218
+ append(D,nums)
219
+ numfields = {}
220
+ for i = 1,#nums do numfields[i] = i end
221
+ else
222
+ cnfg.fieldnames = fields
223
+ end
224
+ line = f:read()
225
+ if strip then line = strip(line) end
226
+ elseif type(cnfg.fieldnames) == 'string' then
227
+ cnfg.fieldnames = split(cnfg.fieldnames,delim)
228
+ end
229
+ -- at this point, the column headers have been read in. If the first
230
+ -- row consisted of numbers, it has already been added to the dataset.
231
+ if cnfg.fieldnames then
232
+ D.fieldnames = cnfg.fieldnames
233
+ -- [conversion] unless @no_convert, we need the numerical field indices
234
+ -- of the first data row. Can also be specified by @numfields.
235
+ if not cnfg.no_convert then
236
+ if not numfields then
237
+ numfields = {}
238
+ local fields = split(line,D.delim)
239
+ for i = 1,#fields do
240
+ if tonumber(fields[i]) then
241
+ append(numfields,i)
242
+ end
243
+ end
244
+ end
245
+ if #numfields > 0 then -- there are numerical fields
246
+ -- note that using dot as the thousands separator (@thousands_dot)
247
+ -- requires a special conversion function!
248
+ convert = thousands_dot and try_tonumber or tonumber
249
+ end
250
+ end
251
+ end
252
+ -- keep going until finished
253
+ while line do
254
+ if not line:find ('^%s*$') then
255
+ if strip then line = strip(line) end
256
+ local fields = split(line,delim)
257
+ if convert then
258
+ for k = 1,#numfields do
259
+ local i = numfields[k]
260
+ local val = convert(fields[i])
261
+ if val == nil then
262
+ return nil, "not a number: "..fields[i]
263
+ else
264
+ fields[i] = val
265
+ end
266
+ end
267
+ end
268
+ -- [collecting end field] If @last_field_collect then we will collect
269
+ -- all extra space-delimited fields into a single last field.
270
+ if collect_end and #fields > #D.fieldnames then
271
+ local ends,N = {},#D.fieldnames
272
+ for i = N+1,#fields do
273
+ append(ends,fields[i])
274
+ end
275
+ ends = concat(ends,' ')
276
+ local cfields = {}
277
+ for i = 1,N do cfields[i] = fields[i] end
278
+ cfields[N] = cfields[N]..' '..ends
279
+ fields = cfields
280
+ end
281
+ append(D,fields)
282
+ end
283
+ line = f:read()
284
+ end
285
+ if opened then f:close() end
286
+ if delim == '%s+' then D.delim = ' ' end
287
+ if not D.fieldnames then D.fieldnames = {} end
288
+ return data.new(D)
289
+ end
290
+
291
+ local function write_row (data,f,row,delim)
292
+ f:write(concat(row,delim),'\n')
293
+ end
294
+
295
+ function DataMT:write_row(f,row)
296
+ write_row(self,f,row,self.delim)
297
+ end
298
+
299
+ --- write 2D data to a file.
300
+ -- Does not assume that the data has actually been
301
+ -- generated with `new` or `read`.
302
+ -- @param data 2D array
303
+ -- @param file filename or file-like object
304
+ -- @param fieldnames list of fields (optional)
305
+ -- @param delim delimiter (default tab)
306
+ function data.write (data,file,fieldnames,delim)
307
+ local f,err,opened = open_file(file,'w')
308
+ if not f then return nil, err end
309
+ if fieldnames and #fieldnames > 0 then
310
+ f:write(concat(data.fieldnames,delim),'\n')
311
+ end
312
+ delim = delim or '\t'
313
+ for i = 1,#data do
314
+ write_row(data,f,data[i],delim)
315
+ end
316
+ if opened then f:close() end
317
+ end
318
+
319
+
320
+ function DataMT:write(file)
321
+ data.write(self,file,self.fieldnames,self.delim)
322
+ end
323
+
324
+ local function massage_fieldnames (fields)
325
+ -- fieldnames must be valid Lua identifiers; ignore any surrounding padding
326
+ for i = 1,#fields do
327
+ fields[i] = rstrip(fields[i]):gsub('^%s*',''):gsub('%W','_')
328
+ end
329
+ end
330
+
331
+ --- create a new dataset from a table of rows.
332
+ -- Can specify the fieldnames, else the table must have a field called
333
+ -- 'fieldnames', which is either a string of delimiter-separated names,
334
+ -- or a table of names. <br>
335
+ -- If the table does not have a field called 'delim', then an attempt will be
336
+ -- made to guess it from the fieldnames string, defaults otherwise to tab.
337
+ -- @param d the table.
338
+ -- @param fieldnames optional fieldnames
339
+ -- @return the table.
340
+ function data.new (d,fieldnames)
341
+ d.fieldnames = d.fieldnames or fieldnames or ''
342
+ if not d.delim and type(d.fieldnames) == 'string' then
343
+ d.delim = guess_delim(d.fieldnames)
344
+ d.fieldnames = split(d.fieldnames,d.delim)
345
+ end
346
+ d.fieldnames = make_list(d.fieldnames)
347
+ massage_fieldnames(d.fieldnames)
348
+ setmetatable(d,DataMT)
349
+ -- a query with just the fieldname will return a sequence
350
+ -- of values, which seq.copy turns into a table.
351
+ return d
352
+ end
353
+
354
+ local sorted_query = [[
355
+ return function (t)
356
+ local i = 0
357
+ local v
358
+ local ls = {}
359
+ for i,v in ipairs(t) do
360
+ if CONDITION then
361
+ ls[#ls+1] = v
362
+ end
363
+ end
364
+ table.sort(ls,function(v1,v2)
365
+ return SORT_EXPR
366
+ end)
367
+ local n = #ls
368
+ return function()
369
+ i = i + 1
370
+ v = ls[i]
371
+ if i > n then return end
372
+ return FIELDLIST
373
+ end
374
+ end
375
+ ]]
376
+
377
+ -- question: is this optimized case actually worth the extra code?
378
+ local simple_query = [[
379
+ return function (t)
380
+ local n = #t
381
+ local i = 0
382
+ local v
383
+ return function()
384
+ repeat
385
+ i = i + 1
386
+ v = t[i]
387
+ until i > n or CONDITION
388
+ if i > n then return end
389
+ return FIELDLIST
390
+ end
391
+ end
392
+ ]]
393
+
394
+ local function is_string (s)
395
+ return type(s) == 'string'
396
+ end
397
+
398
+ local field_error
399
+
400
+ local function fieldnames_as_string (data)
401
+ return concat(data.fieldnames,',')
402
+ end
403
+
404
+ local function massage_fields(data,f)
405
+ local idx
406
+ if f:find '^%d+$' then
407
+ idx = tonumber(f)
408
+ else
409
+ idx = find(data.fieldnames,f)
410
+ end
411
+ if idx then
412
+ return 'v['..idx..']'
413
+ else
414
+ field_error = f..' not found in '..fieldnames_as_string(data)
415
+ return f
416
+ end
417
+ end
418
+
419
+
420
+ local function process_select (data,parms)
421
+ --- preparing fields ----
422
+ local res,ret
423
+ field_error = nil
424
+ local fields = parms.fields
425
+ local numfields = fields:find '%$' or #data.fieldnames == 0
426
+ if fields:find '^%s*%*%s*' then
427
+ if not numfields then
428
+ fields = fieldnames_as_string(data)
429
+ else
430
+ local ncol = #data[1]
431
+ fields = {}
432
+ for i = 1,ncol do append(fields,'$'..i) end
433
+ fields = concat(fields,',')
434
+ end
435
+ end
436
+ local idpat = patterns.IDEN
437
+ if numfields then
438
+ idpat = '%$(%d+)'
439
+ else
440
+ -- massage field names to replace non-identifier chars
441
+ fields = rstrip(fields):gsub('[^,%w]','_')
442
+ end
443
+ local massage_fields = utils.bind1(massage_fields,data)
444
+ ret = gsub(fields,idpat,massage_fields)
445
+ if field_error then return nil,field_error end
446
+ parms.fields = fields
447
+ parms.proc_fields = ret
448
+ parms.where = parms.where or 'true'
449
+ if is_string(parms.where) then
450
+ parms.where = gsub(parms.where,idpat,massage_fields)
451
+ field_error = nil
452
+ end
453
+ return true
454
+ end
455
+
456
+
457
+ parse_select = function(s,data)
458
+ local endp
459
+ local parms = {}
460
+ local w1,w2 = s:find('where ')
461
+ local s1,s2 = s:find('sort by ')
462
+ if w1 then -- where clause!
463
+ endp = (s1 or 0)-1
464
+ parms.where = s:sub(w2+1,endp)
465
+ end
466
+ if s1 then -- sort by clause (must be last!)
467
+ parms.sort_by = s:sub(s2+1)
468
+ end
469
+ endp = (w1 or s1 or 0)-1
470
+ parms.fields = s:sub(1,endp)
471
+ local status,err = process_select(data,parms)
472
+ if not status then return nil,err
473
+ else return parms end
474
+ end
475
+
476
+ --- create a query iterator from a select string.
477
+ -- Select string has this format: <br>
478
+ -- FIELDLIST [ where LUA-CONDN [ sort by FIELD] ]<br>
479
+ -- FIELDLIST is a comma-separated list of valid fields, or '*'. <br> <br>
480
+ -- The condition can also be a table, with fields 'fields' (comma-sep string or
481
+ -- table), 'sort_by' (string) and 'where' (Lua expression string or function)
482
+ -- @param data table produced by read
483
+ -- @param condn select string or table
484
+ -- @param context a list of tables to be searched when resolving functions
485
+ -- @param return_row if true, wrap the results in a row table
486
+ -- @return an iterator over the specified fields, or nil
487
+ -- @return an error message
488
+ function data.query(data,condn,context,return_row)
489
+ local err
490
+ if is_string(condn) then
491
+ condn,err = parse_select(condn,data)
492
+ if not condn then return nil,err end
493
+ elseif type(condn) == 'table' then
494
+ if type(condn.fields) == 'table' then
495
+ condn.fields = concat(condn.fields,',')
496
+ end
497
+ if not condn.proc_fields then
498
+ local status,err = process_select(data,condn)
499
+ if not status then return nil,err end
500
+ end
501
+ else
502
+ return nil, "condition must be a string or a table"
503
+ end
504
+ local query, k
505
+ if condn.sort_by then -- use sorted_query
506
+ query = sorted_query
507
+ else
508
+ query = simple_query
509
+ end
510
+ local fields = condn.proc_fields or condn.fields
511
+ if return_row then
512
+ fields = '{'..fields..'}'
513
+ end
514
+ query,k = query:gsub('FIELDLIST',fields)
515
+ if is_string(condn.where) then
516
+ query = query:gsub('CONDITION',condn.where)
517
+ condn.where = nil
518
+ else
519
+ query = query:gsub('CONDITION','_condn(v)')
520
+ condn.where = function_arg(0,condn.where,'condition.where must be callable')
521
+ end
522
+ if condn.sort_by then
523
+ local expr,sort_var,sort_dir
524
+ local sort_by = condn.sort_by
525
+ local i1,i2 = sort_by:find('%s+')
526
+ if i1 then
527
+ sort_var,sort_dir = sort_by:sub(1,i1-1),sort_by:sub(i2+1)
528
+ else
529
+ sort_var = sort_by
530
+ sort_dir = 'asc'
531
+ end
532
+ if sort_var:match '^%$' then sort_var = sort_var:sub(2) end
533
+ sort_var = massage_fields(data,sort_var)
534
+ if field_error then return nil,field_error end
535
+ if sort_dir == 'asc' then
536
+ sort_dir = '<'
537
+ else
538
+ sort_dir = '>'
539
+ end
540
+ expr = ('%s %s %s'):format(sort_var:gsub('v','v1'),sort_dir,sort_var:gsub('v','v2'))
541
+ query = query:gsub('SORT_EXPR',expr)
542
+ end
543
+ if condn.where then
544
+ query = 'return function(_condn) '..query..' end'
545
+ end
546
+ if _DEBUG then print(query) end
547
+
548
+ local fn,err = loadstring(query,'tmp')
549
+ if not fn then return nil,err end
550
+ fn = fn() -- get the function
551
+ if condn.where then
552
+ fn = fn(condn.where)
553
+ end
554
+ local qfun = fn(data)
555
+ if context then
556
+ -- [specifying context for condition] @context is a list of tables which are
557
+ -- 'injected'into the condition's custom context
558
+ append(context,_G)
559
+ local lookup = {}
560
+ setfenv(qfun,lookup)
561
+ setmetatable(lookup,{
562
+ __index = function(tbl,key)
563
+ -- _G.print(tbl,key)
564
+ for k,t in ipairs(context) do
565
+ if t[key] then return t[key] end
566
+ end
567
+ end
568
+ })
569
+ end
570
+ return qfun
571
+ end
572
+
573
+
574
+ DataMT.select = data.query
575
+ DataMT.select_row = function(d,condn,context)
576
+ return data.query(d,condn,context,true)
577
+ end
578
+
579
+ --- Filter input using a query.
580
+ -- @param Q a query string
581
+ -- @param infile filename or file-like object
582
+ -- @param outfile filename or file-like object
583
+ -- @param dont_fail true if you want to return an error, not just fail
584
+ function data.filter (Q,infile,outfile,dont_fail)
585
+ local err
586
+ local d = data.read(infile or 'stdin')
587
+ local out = open_file(outfile or 'stdout')
588
+ local iter,err = d:select(Q)
589
+ local delim = d.delim
590
+ if not iter then
591
+ err = 'error: '..err
592
+ if dont_fail then
593
+ return nil,err
594
+ else
595
+ utils.quit(1,err)
596
+ end
597
+ end
598
+ while true do
599
+ local res = {iter()}
600
+ if #res == 0 then break end
601
+ out:write(concat(res,delim),'\n')
602
+ end
603
+ end
604
+
605
+ return data
606
+