From 93eb5385d98cb9122a64ef8d83e4b5a9a2c822cb Mon Sep 17 00:00:00 2001 From: TsT Date: Tue, 30 Dec 2014 01:18:00 +0100 Subject: [PATCH 1/3] sample code bugfix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 734202c..ba9d88e 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ Quickie is an [immediate mode gui][IMGUI] library for [LÖVE][LOVE]. Initial function love.keypressed(key, code) gui.keyboard.pressed(key) -- LÖVE 0.8: see if this code can be converted in a character - if pcall(string.char, code) code > 0 then + if pcall(string.char, code) and code > 0 then gui.keyboard.textinput(string.char(code)) end end From 9763d4123ed8375ce235041e1d368c17c5a473b3 Mon Sep 17 00:00:00 2001 From: TsT Date: Tue, 30 Dec 2014 01:53:08 +0100 Subject: [PATCH 2/3] Allow require"Quickie.init" Need for Lua 5.1 package.path contains ./?/init.lua by default with Lua 5.2+ --- init.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 11c5e92..42f20ca 100644 --- a/init.lua +++ b/init.lua @@ -24,8 +24,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]]-- -local BASE = (...) .. '.' -assert(not BASE:match('%.init%.$'), "Invalid require path `"..(...).."' (drop the `.init').") +local BASE = (... or ''):gsub('%.init$', '') + +assert(not BASE:match('%.init$'), "Invalid require path `"..(... or '').."' (drop the `.init').") +BASE = BASE.."." return { core = require(BASE .. 'core'), From 5531c5d6365bbc76e97830f0d443c3dd574b3b59 Mon Sep 17 00:00:00 2001 From: TsT Date: Tue, 30 Dec 2014 23:19:49 +0100 Subject: [PATCH 3/3] define function before returing it, easier to parse for documentation stuff --- button.lua | 4 ++-- checkbox.lua | 4 ++-- input.lua | 3 ++- label.lua | 4 ++-- mouse.lua | 2 ++ slider.lua | 3 ++- slider2d.lua | 3 ++- 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/button.lua b/button.lua index a1f0589..ca86505 100644 --- a/button.lua +++ b/button.lua @@ -31,7 +31,7 @@ local keyboard = require(BASE .. 'keyboard') -- the widget -- {text = text, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} -return function(w) +local function button(w) assert(type(w) == "table" and w.text, "Invalid argument") -- if tight fit requested, compute the size according to text size @@ -74,4 +74,4 @@ return function(w) return mouse.releasedOn(id) or keyboard.pressedOn(id, 'return') end - +return button diff --git a/checkbox.lua b/checkbox.lua index 5137bb0..ecba521 100644 --- a/checkbox.lua +++ b/checkbox.lua @@ -30,7 +30,7 @@ local mouse = require(BASE .. 'mouse') local keyboard = require(BASE .. 'keyboard') -- {checked = status, text = "", algin = "left", pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} -return function(w) +local function checkbox(w) assert(type(w) == "table") w.text = w.text or "" @@ -65,4 +65,4 @@ return function(w) return w.checked ~= checked end - +return checkbox diff --git a/input.lua b/input.lua index b161993..74ce785 100644 --- a/input.lua +++ b/input.lua @@ -32,7 +32,7 @@ local keyboard = require(BASE .. 'keyboard') local utf8 = require(BASE .. 'utf8') -- {info = {text = "", cursor = text:len()}, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} -return function(w) +local function input(w) assert(type(w) == "table" and type(w.info) == "table", "Invalid argument") w.info.text = w.info.text or "" w.info.cursor = math.min(w.info.cursor or w.info.text:len(), w.info.text:len()) @@ -78,3 +78,4 @@ return function(w) return mouse.releasedOn(id) or keyboard.pressedOn(id, 'return') end +return input diff --git a/label.lua b/label.lua index 345516c..4d114e6 100644 --- a/label.lua +++ b/label.lua @@ -31,7 +31,7 @@ local mouse = require(BASE .. 'mouse') local keyboard = require(BASE .. 'keyboard') -- {text = text, align = align, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} -return function(w) +local function label(w) assert(type(w) == "table" and w.text, "Invalid argument") w.align = w.align or 'left' @@ -58,4 +58,4 @@ return function(w) return mouse.releasedOn(id) end - +return label diff --git a/mouse.lua b/mouse.lua index 85db24b..b7a476e 100644 --- a/mouse.lua +++ b/mouse.lua @@ -24,6 +24,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]]-- +local love = require("love") + local _M -- holds the module. needed to make widgetHit overridable local x,y = 0,0 diff --git a/slider.lua b/slider.lua index 4700ae5..259d8fd 100644 --- a/slider.lua +++ b/slider.lua @@ -31,7 +31,7 @@ local mouse = require(BASE .. 'mouse') local keyboard = require(BASE .. 'keyboard') -- {info = {value = v, min = 0, max = 1, step = (max-min)/20}, vertical = boolean, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} -return function(w) +local function slider(w) assert(type(w) == 'table' and type(w.info) == "table" and w.info.value, "Invalid argument.") w.info.min = w.info.min or 0 w.info.max = w.info.max or math.max(w.info.value, 1) @@ -77,3 +77,4 @@ return function(w) return changed end +return slider diff --git a/slider2d.lua b/slider2d.lua index 19e264c..022544c 100644 --- a/slider2d.lua +++ b/slider2d.lua @@ -31,7 +31,7 @@ local mouse = require(BASE .. 'mouse') local keyboard = require(BASE .. 'keyboard') -- {info = {value = {x,y}, min = {0,0}, max = {1,1}, step = (max-min)/20}, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw} -return function(w) +local function slider2d(w) assert(type(w) == 'table' and type(w.info) == "table" and w.info.value, "Invalid argument.") w.info.min = { w.info.min and w.info.min[1] or 0, @@ -97,3 +97,4 @@ return function(w) return changed end +return slider2d