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,550 @@
1
+ --- Generally useful routines.
2
+ -- See @{01-introduction.md.Generally_useful_functions|the Guide}.
3
+ -- @module pl.utils
4
+ local format,gsub,byte = string.format,string.gsub,string.byte
5
+ local clock = os.clock
6
+ local stdout = io.stdout
7
+ local append = table.insert
8
+
9
+ local collisions = {}
10
+
11
+ local utils = {}
12
+
13
+ utils._VERSION = "1.0.3"
14
+
15
+ local lua51 = rawget(_G,'setfenv')
16
+
17
+ utils.lua51 = lua51
18
+ if not lua51 then -- Lua 5.2 compatibility
19
+ unpack = table.unpack
20
+ loadstring = load
21
+ end
22
+
23
+ utils.dir_separator = _G.package.config:sub(1,1)
24
+
25
+ --- end this program gracefully.
26
+ -- @param code The exit code or a message to be printed
27
+ -- @param ... extra arguments for message's format'
28
+ -- @see utils.fprintf
29
+ function utils.quit(code,...)
30
+ if type(code) == 'string' then
31
+ utils.fprintf(io.stderr,code,...)
32
+ code = -1
33
+ else
34
+ utils.fprintf(io.stderr,...)
35
+ end
36
+ io.stderr:write('\n')
37
+ os.exit(code)
38
+ end
39
+
40
+ --- print an arbitrary number of arguments using a format.
41
+ -- @param fmt The format (see string.format)
42
+ -- @param ... Extra arguments for format
43
+ function utils.printf(fmt,...)
44
+ utils.assert_string(1,fmt)
45
+ utils.fprintf(stdout,fmt,...)
46
+ end
47
+
48
+ --- write an arbitrary number of arguments to a file using a format.
49
+ -- @param f File handle to write to.
50
+ -- @param fmt The format (see string.format).
51
+ -- @param ... Extra arguments for format
52
+ function utils.fprintf(f,fmt,...)
53
+ utils.assert_string(2,fmt)
54
+ f:write(format(fmt,...))
55
+ end
56
+
57
+ local function import_symbol(T,k,v,libname)
58
+ local key = rawget(T,k)
59
+ -- warn about collisions!
60
+ if key and k ~= '_M' and k ~= '_NAME' and k ~= '_PACKAGE' and k ~= '_VERSION' then
61
+ utils.printf("warning: '%s.%s' overrides existing symbol\n",libname,k)
62
+ end
63
+ rawset(T,k,v)
64
+ end
65
+
66
+ local function lookup_lib(T,t)
67
+ for k,v in pairs(T) do
68
+ if v == t then return k end
69
+ end
70
+ return '?'
71
+ end
72
+
73
+ local already_imported = {}
74
+
75
+ --- take a table and 'inject' it into the local namespace.
76
+ -- @param t The Table
77
+ -- @param T An optional destination table (defaults to callers environment)
78
+ function utils.import(t,T)
79
+ T = T or _G
80
+ t = t or utils
81
+ if type(t) == 'string' then
82
+ t = require (t)
83
+ end
84
+ local libname = lookup_lib(T,t)
85
+ if already_imported[t] then return end
86
+ already_imported[t] = libname
87
+ for k,v in pairs(t) do
88
+ import_symbol(T,k,v,libname)
89
+ end
90
+ end
91
+
92
+ utils.patterns = {
93
+ FLOAT = '[%+%-%d]%d*%.?%d*[eE]?[%+%-]?%d*',
94
+ INTEGER = '[+%-%d]%d*',
95
+ IDEN = '[%a_][%w_]*',
96
+ FILE = '[%a%.\\][:%][%w%._%-\\]*'
97
+ }
98
+
99
+ --- escape any 'magic' characters in a string
100
+ -- @param s The input string
101
+ function utils.escape(s)
102
+ utils.assert_string(1,s)
103
+ return (s:gsub('[%-%.%+%[%]%(%)%$%^%%%?%*]','%%%1'))
104
+ end
105
+
106
+ --- return either of two values, depending on a condition.
107
+ -- @param cond A condition
108
+ -- @param value1 Value returned if cond is true
109
+ -- @param value2 Value returned if cond is false (can be optional)
110
+ function utils.choose(cond,value1,value2)
111
+ if cond then return value1
112
+ else return value2
113
+ end
114
+ end
115
+
116
+ local raise
117
+
118
+ --- return the contents of a file as a string
119
+ -- @param filename The file path
120
+ -- @param is_bin open in binary mode
121
+ -- @return file contents
122
+ function utils.readfile(filename,is_bin)
123
+ local mode = is_bin and 'b' or ''
124
+ utils.assert_string(1,filename)
125
+ local f,err = io.open(filename,'r'..mode)
126
+ if not f then return utils.raise (err) end
127
+ local res,err = f:read('*a')
128
+ f:close()
129
+ if not res then return raise (err) end
130
+ return res
131
+ end
132
+
133
+ --- write a string to a file
134
+ -- @param filename The file path
135
+ -- @param str The string
136
+ -- @return true or nil
137
+ -- @return error message
138
+ -- @raise error if filename or str aren't strings
139
+ function utils.writefile(filename,str)
140
+ utils.assert_string(1,filename)
141
+ utils.assert_string(2,str)
142
+ local f,err = io.open(filename,'w')
143
+ if not f then return raise(err) end
144
+ f:write(str)
145
+ f:close()
146
+ return true
147
+ end
148
+
149
+ --- return the contents of a file as a list of lines
150
+ -- @param filename The file path
151
+ -- @return file contents as a table
152
+ -- @raise errror if filename is not a string
153
+ function utils.readlines(filename)
154
+ utils.assert_string(1,filename)
155
+ local f,err = io.open(filename,'r')
156
+ if not f then return raise(err) end
157
+ local res = {}
158
+ for line in f:lines() do
159
+ append(res,line)
160
+ end
161
+ f:close()
162
+ return res
163
+ end
164
+
165
+ --- split a string into a list of strings separated by a delimiter.
166
+ -- @param s The input string
167
+ -- @param re A Lua string pattern; defaults to '%s+'
168
+ -- @param plain don't use Lua patterns
169
+ -- @param n optional maximum number of splits
170
+ -- @return a list-like table
171
+ -- @raise error if s is not a string
172
+ function utils.split(s,re,plain,n)
173
+ utils.assert_string(1,s)
174
+ local find,sub,append = string.find, string.sub, table.insert
175
+ local i1,ls = 1,{}
176
+ if not re then re = '%s+' end
177
+ if re == '' then return {s} end
178
+ while true do
179
+ local i2,i3 = find(s,re,i1,plain)
180
+ if not i2 then
181
+ local last = sub(s,i1)
182
+ if last ~= '' then append(ls,last) end
183
+ if #ls == 1 and ls[1] == '' then
184
+ return {}
185
+ else
186
+ return ls
187
+ end
188
+ end
189
+ append(ls,sub(s,i1,i2-1))
190
+ if n and #ls == n then
191
+ ls[#ls] = sub(s,i1)
192
+ return ls
193
+ end
194
+ i1 = i3+1
195
+ end
196
+ end
197
+
198
+ --- split a string into a number of values.
199
+ -- @param s the string
200
+ -- @param re the delimiter, default space
201
+ -- @return n values
202
+ -- @usage first,next = splitv('jane:doe',':')
203
+ -- @see split
204
+ function utils.splitv (s,re)
205
+ return unpack(utils.split(s,re))
206
+ end
207
+
208
+ local lua51_load = load
209
+
210
+ if utils.lua51 then -- define Lua 5.2 style load()
211
+ function utils.load(str,src,mode,env)
212
+ local chunk,err
213
+ if type(str) == 'string' then
214
+ chunk,err = loadstring(str,src)
215
+ else
216
+ chunk,err = lua51_load(str,src)
217
+ end
218
+ if chunk and env then setfenv(chunk,env) end
219
+ return chunk,err
220
+ end
221
+ else
222
+ utils.load = load
223
+ -- setfenv/getfenv replacements for Lua 5.2
224
+ -- by Sergey Rozhenko
225
+ -- http://lua-users.org/lists/lua-l/2010-06/msg00313.html
226
+ -- Roberto Ierusalimschy notes that it is possible for getfenv to return nil
227
+ -- in the case of a function with no globals:
228
+ -- http://lua-users.org/lists/lua-l/2010-06/msg00315.html
229
+ function setfenv(f, t)
230
+ f = (type(f) == 'function' and f or debug.getinfo(f + 1, 'f').func)
231
+ local name
232
+ local up = 0
233
+ repeat
234
+ up = up + 1
235
+ name = debug.getupvalue(f, up)
236
+ until name == '_ENV' or name == nil
237
+ if name then
238
+ debug.upvaluejoin(f, up, function() return name end, 1) -- use unique upvalue
239
+ debug.setupvalue(f, up, t)
240
+ end
241
+ if f ~= 0 then return f end
242
+ end
243
+
244
+ function getfenv(f)
245
+ local f = f or 0
246
+ f = (type(f) == 'function' and f or debug.getinfo(f + 1, 'f').func)
247
+ local name, val
248
+ local up = 0
249
+ repeat
250
+ up = up + 1
251
+ name, val = debug.getupvalue(f, up)
252
+ until name == '_ENV' or name == nil
253
+ return val
254
+ end
255
+ end
256
+
257
+
258
+ --- execute a shell command.
259
+ -- This is a compatibility function that returns the same for Lua 5.1 and Lua 5.2
260
+ -- @param cmd a shell command
261
+ -- @return true if successful
262
+ -- @return actual return code
263
+ function utils.execute (cmd)
264
+ local res1,res2,res2 = os.execute(cmd)
265
+ if lua51 then
266
+ return res1==0,res1
267
+ else
268
+ return res1,res2
269
+ end
270
+ end
271
+
272
+ if lua51 then
273
+ function table.pack (...)
274
+ local n = select('#',...)
275
+ return {n=n; ...}
276
+ end
277
+ local sep = package.config:sub(1,1)
278
+ function package.searchpath (mod,path)
279
+ mod = mod:gsub('%.',sep)
280
+ for m in path:gmatch('[^;]+') do
281
+ local nm = m:gsub('?',mod)
282
+ local f = io.open(nm,'r')
283
+ if f then f:close(); return nm end
284
+ end
285
+ end
286
+ end
287
+
288
+ if not table.pack then table.pack = _G.pack end
289
+ if not rawget(_G,"pack") then _G.pack = table.pack end
290
+
291
+ --- take an arbitrary set of arguments and make into a table.
292
+ -- This returns the table and the size; works fine for nil arguments
293
+ -- @param ... arguments
294
+ -- @return table
295
+ -- @return table size
296
+ -- @usage local t,n = utils.args(...)
297
+
298
+ --- 'memoize' a function (cache returned value for next call).
299
+ -- This is useful if you have a function which is relatively expensive,
300
+ -- but you don't know in advance what values will be required, so
301
+ -- building a table upfront is wasteful/impossible.
302
+ -- @param func a function of at least one argument
303
+ -- @return a function with at least one argument, which is used as the key.
304
+ function utils.memoize(func)
305
+ return setmetatable({}, {
306
+ __index = function(self, k, ...)
307
+ local v = func(k,...)
308
+ self[k] = v
309
+ return v
310
+ end,
311
+ __call = function(self, k) return self[k] end
312
+ })
313
+ end
314
+
315
+ --- is the object either a function or a callable object?.
316
+ -- @param obj Object to check.
317
+ function utils.is_callable (obj)
318
+ return type(obj) == 'function' or getmetatable(obj) and getmetatable(obj).__call
319
+ end
320
+
321
+ --- is the object of the specified type?.
322
+ -- If the type is a string, then use type, otherwise compare with metatable
323
+ -- @param obj An object to check
324
+ -- @param tp String of what type it should be
325
+ function utils.is_type (obj,tp)
326
+ if type(tp) == 'string' then return type(obj) == tp end
327
+ local mt = getmetatable(obj)
328
+ return tp == mt
329
+ end
330
+
331
+ local fileMT = getmetatable(io.stdout)
332
+
333
+ --- a string representation of a type.
334
+ -- For tables with metatables, we assume that the metatable has a `_name`
335
+ -- field. Knows about Lua file objects.
336
+ -- @param obj an object
337
+ -- @return a string like 'number', 'table' or 'List'
338
+ function utils.type (obj)
339
+ local t = type(obj)
340
+ if t == 'table' or t == 'userdata' then
341
+ local mt = getmetatable(obj)
342
+ if mt == fileMT then
343
+ return 'file'
344
+ else
345
+ return mt._name or "unknown "..t
346
+ end
347
+ else
348
+ return t
349
+ end
350
+ end
351
+
352
+ --- is this number an integer?
353
+ -- @param x a number
354
+ -- @raise error if x is not a number
355
+ function utils.is_integer (x)
356
+ return math.ceil(x)==x
357
+ end
358
+
359
+ utils.stdmt = {
360
+ List = {_name='List'}, Map = {_name='Map'},
361
+ Set = {_name='Set'}, MultiMap = {_name='MultiMap'}
362
+ }
363
+
364
+ local _function_factories = {}
365
+
366
+ --- associate a function factory with a type.
367
+ -- A function factory takes an object of the given type and
368
+ -- returns a function for evaluating it
369
+ -- @param mt metatable
370
+ -- @param fun a callable that returns a function
371
+ function utils.add_function_factory (mt,fun)
372
+ _function_factories[mt] = fun
373
+ end
374
+
375
+ local function _string_lambda(f)
376
+ local raise = utils.raise
377
+ if f:find '^|' or f:find '_' then
378
+ local args,body = f:match '|([^|]*)|(.+)'
379
+ if f:find '_' then
380
+ args = '_'
381
+ body = f
382
+ else
383
+ if not args then return raise 'bad string lambda' end
384
+ end
385
+ local fstr = 'return function('..args..') return '..body..' end'
386
+ local fn,err = loadstring(fstr)
387
+ if not fn then return raise(err) end
388
+ fn = fn()
389
+ return fn
390
+ else return raise 'not a string lambda'
391
+ end
392
+ end
393
+
394
+ --- an anonymous function as a string. This string is either of the form
395
+ -- '|args| expression' or is a function of one argument, '_'
396
+ -- @param lf function as a string
397
+ -- @return a function
398
+ -- @usage string_lambda '|x|x+1' (2) == 3
399
+ -- @usage string_lambda '_+1 (2) == 3
400
+ -- @function utils.string_lambda
401
+ utils.string_lambda = utils.memoize(_string_lambda)
402
+
403
+ local ops
404
+
405
+ --- process a function argument.
406
+ -- This is used throughout Penlight and defines what is meant by a function:
407
+ -- Something that is callable, or an operator string as defined by <code>pl.operator</code>,
408
+ -- such as '>' or '#'. If a function factory has been registered for the type, it will
409
+ -- be called to get the function.
410
+ -- @param idx argument index
411
+ -- @param f a function, operator string, or callable object
412
+ -- @param msg optional error message
413
+ -- @return a callable
414
+ -- @raise if idx is not a number or if f is not callable
415
+ -- @see utils.is_callable
416
+ function utils.function_arg (idx,f,msg)
417
+ utils.assert_arg(1,idx,'number')
418
+ local tp = type(f)
419
+ if tp == 'function' then return f end -- no worries!
420
+ -- ok, a string can correspond to an operator (like '==')
421
+ if tp == 'string' then
422
+ if not ops then ops = require 'pl.operator'.optable end
423
+ local fn = ops[f]
424
+ if fn then return fn end
425
+ local fn, err = utils.string_lambda(f)
426
+ if not fn then error(err..': '..f) end
427
+ return fn
428
+ elseif tp == 'table' or tp == 'userdata' then
429
+ local mt = getmetatable(f)
430
+ if not mt then error('not a callable object',2) end
431
+ local ff = _function_factories[mt]
432
+ if not ff then
433
+ if not mt.__call then error('not a callable object',2) end
434
+ return f
435
+ else
436
+ return ff(f) -- we have a function factory for this type!
437
+ end
438
+ end
439
+ if not msg then msg = " must be callable" end
440
+ if idx > 0 then
441
+ error("argument "..idx..": "..msg,2)
442
+ else
443
+ error(msg,2)
444
+ end
445
+ end
446
+
447
+ --- bind the first argument of the function to a value.
448
+ -- @param fn a function of at least two values (may be an operator string)
449
+ -- @param p a value
450
+ -- @return a function such that f(x) is fn(p,x)
451
+ -- @raise same as @{function_arg}
452
+ -- @see pl.func.curry
453
+ function utils.bind1 (fn,p)
454
+ fn = utils.function_arg(1,fn)
455
+ return function(...) return fn(p,...) end
456
+ end
457
+
458
+ --- bind the second argument of the function to a value.
459
+ -- @param fn a function of at least two values (may be an operator string)
460
+ -- @param p a value
461
+ -- @return a function such that f(x) is fn(x,p)
462
+ -- @raise same as @{function_arg}
463
+ function utils.bind2 (fn,p)
464
+ fn = utils.function_arg(1,fn)
465
+ return function(x,...) return fn(x,p,...) end
466
+ end
467
+
468
+
469
+ --- assert that the given argument is in fact of the correct type.
470
+ -- @param n argument index
471
+ -- @param val the value
472
+ -- @param tp the type
473
+ -- @param verify an optional verfication function
474
+ -- @param msg an optional custom message
475
+ -- @param lev optional stack position for trace, default 2
476
+ -- @raise if the argument n is not the correct type
477
+ -- @usage assert_arg(1,t,'table')
478
+ -- @usage assert_arg(n,val,'string',path.isdir,'not a directory')
479
+ function utils.assert_arg (n,val,tp,verify,msg,lev)
480
+ if type(val) ~= tp then
481
+ error(("argument %d expected a '%s', got a '%s'"):format(n,tp,type(val)),lev or 2)
482
+ end
483
+ if verify and not verify(val) then
484
+ error(("argument %d: '%s' %s"):format(n,val,msg),lev or 2)
485
+ end
486
+ end
487
+
488
+ --- assert the common case that the argument is a string.
489
+ -- @param n argument index
490
+ -- @param val a value that must be a string
491
+ -- @raise val must be a string
492
+ function utils.assert_string (n,val)
493
+ utils.assert_arg(n,val,'string',nil,nil,3)
494
+ end
495
+
496
+ local err_mode = 'default'
497
+
498
+ --- control the error strategy used by Penlight.
499
+ -- Controls how <code>utils.raise</code> works; the default is for it
500
+ -- to return nil and the error string, but if the mode is 'error' then
501
+ -- it will throw an error. If mode is 'quit' it will immediately terminate
502
+ -- the program.
503
+ -- @param mode - either 'default', 'quit' or 'error'
504
+ -- @see utils.raise
505
+ function utils.on_error (mode)
506
+ err_mode = mode
507
+ end
508
+
509
+ --- used by Penlight functions to return errors. Its global behaviour is controlled
510
+ -- by <code>utils.on_error</code>
511
+ -- @param err the error string.
512
+ -- @see utils.on_error
513
+ function utils.raise (err)
514
+ if err_mode == 'default' then return nil,err
515
+ elseif err_mode == 'quit' then utils.quit(err)
516
+ else error(err,2)
517
+ end
518
+ end
519
+
520
+ raise = utils.raise
521
+
522
+ --- load a code string or bytecode chunk.
523
+ -- @param code Lua code as a string or bytecode
524
+ -- @param name for source errors
525
+ -- @param mode kind of chunk, 't' for text, 'b' for bytecode, 'bt' for all (default)
526
+ -- @param env the environment for the new chunk (default nil)
527
+ -- @return compiled chunk
528
+ -- @return error message (chunk is nil)
529
+ -- @function utils.load
530
+
531
+
532
+ --- Lua 5.2 Compatible Functions
533
+ -- @section lua52
534
+
535
+ --- pack an argument list into a table.
536
+ -- @param ... any arguments
537
+ -- @return a table with field n set to the length
538
+ -- @return the length
539
+ -- @function table.pack
540
+
541
+ ------
542
+ -- return the full path where a Lua module name would be matched.
543
+ -- @param mod module name, possibly dotted
544
+ -- @param path a path in the same form as package.path or package.cpath
545
+ -- @see path.package_path
546
+ -- @function package.searchpath
547
+
548
+ return utils
549
+
550
+