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/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'), 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