diff options
author | steve donovan <steve.j.donovan@gmail.com> | 2011-11-27 20:46:26 +0400 |
---|---|---|
committer | steve donovan <steve.j.donovan@gmail.com> | 2011-11-27 20:46:26 +0400 |
commit | e0a005f96d492310dc2b13adb27ee0776215e944 (patch) | |
tree | 39474a2e92dbc1d763b3c4de22e1c8ab53fe1dfb | |
parent | dcab67d66600a8d1387a69f57d152d5440ca0d18 (diff) | |
parent | bc077bb292ede0dbb5aa72b204576583f461d528 (diff) |
resolving merge conflicts0.9.8
-rw-r--r-- | lua/pl/Date.lua | 7 | ||||
-rw-r--r-- | lua/pl/app.lua | 4 | ||||
-rw-r--r-- | lua/pl/config.lua | 6 | ||||
-rw-r--r-- | lua/pl/data.lua | 5 | ||||
-rwxr-xr-x | lua/pl/dir.lua | 27 | ||||
-rw-r--r-- | lua/pl/template.lua | 6 | ||||
-rw-r--r-- | lua/pl/utils.lua | 7 | ||||
-rw-r--r-- | tests/test-strict.lua | 6 |
8 files changed, 51 insertions, 17 deletions
diff --git a/lua/pl/Date.lua b/lua/pl/Date.lua index fa9b9f6..c11a9ef 100644 --- a/lua/pl/Date.lua +++ b/lua/pl/Date.lua @@ -434,11 +434,11 @@ local function parse_iso_end(p,ns,sec) -- ISO 8601 dates may end in Z (for UTC) or [+-][isotime] if p:match 'z$' then return sec, {h=0,m=0} end -- we're UTC! p = p:gsub(':','') -- turn 00:30 to 0030 - _,_,sign,offs = p:find('^([%+%-])(%d+)') + local _,_,sign,offs = p:find('^([%+%-])(%d+)') if not sign then return sec, nil end -- not UTC if #offs == 2 then offs = offs .. '00' end -- 01 to 0100 - tz = { h = tonumber(offs:sub(1,2)), m = tonumber(offs:sub(3,4)) } + local tz = { h = tonumber(offs:sub(1,2)), m = tonumber(offs:sub(3,4)) } if sign == '-' then tz.h = -tz.h; tz.m = -tz.m end return sec, tz end @@ -483,6 +483,7 @@ local function parse_date_unsafe (s,US) if p then -- time is hh:mm[:ss], hhmm[ss] or H.M[am|pm] _,nxt,hour,min = p:find '^(%d+):(%d+)' + local ns if nxt then -- are there seconds? _,ns,sec = p:find ('^:(%d+)',nxt+1) --if ns then @@ -493,7 +494,7 @@ local function parse_date_unsafe (s,US) if ns then apm = p:match '[ap]m$' else -- or hhmm[ss] - + local hourmin _,nxt,hourmin = p:find ('^(%d+)') if nxt then hour = hourmin:sub(1,2) diff --git a/lua/pl/app.lua b/lua/pl/app.lua index a14b1b8..8452550 100644 --- a/lua/pl/app.lua +++ b/lua/pl/app.lua @@ -47,7 +47,8 @@ end -- These will look like '~/.SNAME/file', with '~' as with expanduser and -- SNAME is the name of the script without .lua extension. -- @param file a filename (w/out path) --- @return a full pathname +-- @return a full pathname, or nil +-- @return 'cannot create' error function app.appfile (file) local sname = path.basename(check_script_name()) local name,ext = path.splitext(sname) @@ -82,6 +83,7 @@ end -- @param flags_with_values any flags that take values, e.g. <code>{out=true}</code> -- @return a table of flags (flag=value pairs) -- @return an array of parameters +-- @raise if args is nil, then the global `args` must be available! function app.parse_args (args,flags_with_values) if not args then args = _G.arg diff --git a/lua/pl/config.lua b/lua/pl/config.lua index 9a36330..bd6b897 100644 --- a/lua/pl/config.lua +++ b/lua/pl/config.lua @@ -53,7 +53,8 @@ local config = {} --- like io.lines(), but allows for lines to be continued with '\'. -- @param file a file-like object (anything where read() returns the next line) or a filename. -- Defaults to stardard input. --- @return an iterator over the lines +-- @return an iterator over the lines, or nil +-- @return error 'not a file-like object' or 'file is nil' function config.lines(file) local f,openf,err local line = '' @@ -96,7 +97,8 @@ end -- <li> trim_quotes remove quotes from strings (default false)</li> -- <li> list_delim delimiter to use when separating columns (default ',')</li> -- </ul> --- @return nil,error_msg in case of an error, otherwise a table containing items +-- @return a table containing items, or nil +-- @return error message (same as @{config.lines} function config.read(file,cnfg) local f,openf,err cnfg = cnfg or {} diff --git a/lua/pl/data.lua b/lua/pl/data.lua index 280a90f..931c926 100644 --- a/lua/pl/data.lua +++ b/lua/pl/data.lua @@ -458,14 +458,15 @@ end --- create a query iterator from a select string. -- Select string has this format: <br> -- FIELDLIST [ where LUA-CONDN [ sort by FIELD] ]<br> --- FIELDLISt is a comma-separated list of valid fields, or '*'. <br> <br> +-- FIELDLIST is a comma-separated list of valid fields, or '*'. <br> <br> -- The condition can also be a table, with fields 'fields' (comma-sep string or -- table), 'sort_by' (string) and 'where' (Lua expression string or function) -- @param data table produced by read -- @param condn select string or table -- @param context a list of tables to be searched when resolving functions -- @param return_row if true, wrap the results in a row table --- @return an iterator over the specified fields +-- @return an iterator over the specified fields, or nil +-- @return an error message function data.query(data,condn,context,return_row) local err if is_string(condn) then diff --git a/lua/pl/dir.lua b/lua/pl/dir.lua index 1c40157..5cea49e 100755 --- a/lua/pl/dir.lua +++ b/lua/pl/dir.lua @@ -42,16 +42,20 @@ end -- (cf. fnmatch.fnmatch in Python, 11.8) -- @param file A file name -- @param pattern A shell pattern +-- @return true or false +-- @raise file and pattern must be strings function dir.fnmatch(file,pattern) assert_string(1,file) assert_string(2,pattern) return path.normcase(file):find(filemask(pattern)) ~= nil end ---- return a list of all files in a list of files which match the pattern. +--- return a list of all files which match the pattern. -- (cf. fnmatch.filter in Python, 11.8) -- @param files A table containing file names -- @param pattern A shell pattern. +-- @return list of files +-- @raise file and pattern must be strings function dir.filter(files,pattern) assert_arg(1,files,'table') assert_string(2,pattern) @@ -81,6 +85,8 @@ end --- return a list of all files in a directory which match the a shell pattern. -- @param dir A directory. If not given, all files in current directory are returned. -- @param mask A shell pattern. If not given, all files are returned. +-- @return lsit of files +-- @raise dir and mask must be strings function dir.getfiles(dir,mask) assert_dir(1,dir) assert_string(2,mask) @@ -96,6 +102,8 @@ end --- return a list of all subdirectories of the directory. -- @param dir A directory +-- @return a list of directories +-- @raise dir must be a string function dir.getdirectories(dir) assert_dir(1,dir) return _listfiles(dir,false) @@ -232,6 +240,7 @@ end -- @param dest destination file or directory -- @param flag true if you want to force the copy (default) -- @return true if operation succeeded +-- @raise src and dest must be strings function dir.copyfile (src,dest,flag) assert_string(1,src) assert_string(2,dest) @@ -243,6 +252,7 @@ end -- @param src source file -- @param dest destination file or directory -- @return true if operation succeeded +-- @raise src and dest must be strings function dir.movefile (src,dest) assert_string(1,src) assert_string(2,dest) @@ -287,6 +297,8 @@ end -- @param root A starting directory -- @param bottom_up False if we start listing entries immediately. -- @param follow_links follow symbolic links +-- @return an iterator returning root,dirs,files +-- @raise root must be a string function dir.walk(root,bottom_up,follow_links) assert_string(1,root) if not path.isdir(root) then return raise 'not a directory' end @@ -301,6 +313,9 @@ end --- remove a whole directory tree. -- @param fullpath A directory path +-- @return true or nil +-- @return error if failed +-- @raise fullpath must be a string function dir.rmtree(fullpath) assert_string(1,fullpath) if not path.isdir(fullpath) then return raise 'not a directory' end @@ -339,6 +354,8 @@ end --- create a directory path. -- This will create subdirectories as necessary! -- @param p A directory path +-- @return a valid created path +-- @raise p must be a string function dir.makepath (p) assert_string(1,p) return _makepath(path.normcase(path.abspath(p))) @@ -352,8 +369,10 @@ end -- @param file_fun an optional function to apply on all files -- @param verbose an optional boolean to control the verbosity of the output. -- It can also be a logging function that behaves like print() --- @return if failed, false plus an error message. If completed the traverse, --- true, a list of failed directory creations and a list of failed file operations. +-- @return true, or nil +-- @return error message, or list of failed directory creations +-- @return list of failed file operations +-- @raise path1 and path2 must be strings -- @usage clonetree('.','../backup',copyfile) function dir.clonetree (path1,path2,file_fun,verbose) assert_string(1,path1) @@ -402,6 +421,7 @@ end --- return an iterator over all entries in a directory tree -- @param d a directory -- @return an iterator giving pathname and mode (true for dir, false otherwise) +-- @raise d must be a non-empty string function dir.dirtree( d ) assert( d and d ~= "", "directory parameter is missing or empty" ) local exists, isdir = path.exists, path.isdir @@ -436,6 +456,7 @@ end -- @param start_path {string} A directory. If not given, all files in current directory are returned. -- @param pattern {string} A shell pattern. If not given, all files are returned. -- @return Table containing all the files found recursively starting at <i>path</i> and filtered by <i>pattern</i>. +-- @raise start_path must be a string function dir.getallfiles( start_path, pattern ) assert( type( start_path ) == "string", "bad argument #1 to 'GetAllFiles' (Expected string but recieved " .. type( start_path ) .. ")" ) pattern = pattern or "" diff --git a/lua/pl/template.lua b/lua/pl/template.lua index 2ffaa3a..dbff1f2 100644 --- a/lua/pl/template.lua +++ b/lua/pl/template.lua @@ -72,10 +72,12 @@ local template = {} -- </ul> function template.substitute(str,env) env = env or {} - if env._parent then + if rawget(env,"_parent") then setmetatable(env,{__index = env._parent}) end - local code = parseHashLines(str,env._brackets or '()',env._escape or '#') + local brackets = rawget(env,"_brackets") or '()' + local escape = rawget(env,"_escape") or '#' + local code = parseHashLines(str,brackets,escape) local fn,err = utils.load(code,'TMP','t',env) if not fn then return nil,err end fn = fn() diff --git a/lua/pl/utils.lua b/lua/pl/utils.lua index 87f8348..af1553b 100644 --- a/lua/pl/utils.lua +++ b/lua/pl/utils.lua @@ -277,7 +277,7 @@ if not lua52 then end if not table.pack then table.pack = _G.pack end -if not _G.pack then _G.pack = table.pack end +if not rawget(_G,"pack") then _G.pack = table.pack end --- take an arbitrary set of arguments and make into a table. -- This returns the table and the size; works fine for nil arguments @@ -401,6 +401,7 @@ local ops -- @param f a function, operator string, or callable object -- @param msg optional error message -- @return a callable +-- @raise if idx is not a number or if f is not callable -- @see utils.is_callable function utils.function_arg (idx,f,msg) utils.assert_arg(1,idx,'number') @@ -437,6 +438,7 @@ end -- @param fn a function of at least two values (may be an operator string) -- @param p a value -- @return a function such that f(x) is fn(p,x) +-- @raise same as @{function_arg} -- @see pl.func.curry function utils.bind1 (fn,p) fn = utils.function_arg(1,fn) @@ -450,6 +452,7 @@ end -- @param verify an optional verfication function -- @param msg an optional custom message -- @param lev optional stack position for trace, default 2 +-- @raise if the argument n is not the correct type -- @usage assert_arg(1,t,'table') -- @usage assert_arg(n,val,'string',path.isdir,'not a directory') function utils.assert_arg (n,val,tp,verify,msg,lev) @@ -464,6 +467,7 @@ end --- assert the common case that the argument is a string. -- @param n argument index -- @param val a value that must be a string +-- @raise val must be a string function utils.assert_string (n,val) utils.assert_arg(n,val,'string',nil,nil,nil,3) end @@ -520,7 +524,6 @@ raise = utils.raise -- @see path.package_path -- @function package.searchpath - return utils diff --git a/tests/test-strict.lua b/tests/test-strict.lua index be29c46..7087600 100644 --- a/tests/test-strict.lua +++ b/tests/test-strict.lua @@ -1,8 +1,10 @@ -require 'pl'
+--require 'pl'
require 'pl.strict'
+local utils = require 'pl.utils'
utils.printf("that's fine!\n")
-res,err = pcall(function()
+local res,err = pcall(function()
print(x)
+ print 'ok?'
end)
assert(err,"variable 'x' is not declared")
|