webmcp
view framework/env/parse/boolean.lua @ 4:5e32ef998acf
Version 1.0.4
ui.link{...} with POST target can now be parameterized with BOTH content and text to allow HTML content for JavaScript browsers and a text-only version for accessiblity
Changes related to database selectors:
- Support for row-based locking
- New method :count(), caching and returning the number of rows, which WOULD have been returned by :exec()
- Bugfix: WHERE and HAVING expressions are now enclosed in parenthesis to avoid problems with operator precedence
ui.script{...} now supports external .js files
Changes in langtool.lua to cope with escaped new-line chars (\n)
ui.link{...} with POST target can now be parameterized with BOTH content and text to allow HTML content for JavaScript browsers and a text-only version for accessiblity
Changes related to database selectors:
- Support for row-based locking
- New method :count(), caching and returning the number of rows, which WOULD have been returned by :exec()
- Bugfix: WHERE and HAVING expressions are now enclosed in parenthesis to avoid problems with operator precedence
ui.script{...} now supports external .js files
Changes in langtool.lua to cope with escaped new-line chars (\n)
author | jbe/bsw |
---|---|
date | Fri Dec 25 12:00:00 2009 +0100 (2009-12-25) |
parents | 9fdfb27f8e67 |
children |
line source
1 function parse.boolean(str, dest_type, options)
2 if dest_type ~= atom.boolean then
3 error("parse.boolean(...) can only return booleans, but a different destination type than atom.boolean was given.")
4 end
5 local options = options or {}
6 local trimmed_str = string.match(str or "", "^%s*(.-)%s*$")
7 if options.true_as or options.false_as or options.nil_as then
8 if trimmed_str == options.true_as then
9 return true
10 elseif trimmed_str == options.false_as then
11 return false
12 elseif trimmed_str == options.nil_as or trimmed_str == "" then
13 return nil
14 else
15 error("Boolean value not recognized.")
16 end
17 else
18 local char = string.upper(string.sub(trimmed_str, 1, 1))
19 if char == "1" or char == "T" or char == "Y" then
20 return true
21 elseif char == "0" or char == "F" or char == "N" then
22 return false
23 elseif char == "" then
24 return nil
25 else
26 error("Boolean value not recognized.")
27 end
28 end
29 end