From 7731c11c70a4b0902cbe543387e9bd6994bf51cf Mon Sep 17 00:00:00 2001 From: Paul Liverman Date: Fri, 1 Apr 2016 14:14:24 -0700 Subject: [PATCH] experimental inclusion of extensions --- src/pop/extensions/streamlined_get_set.moon | 14 ++++++++++++++ src/pop/init.moon | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/pop/extensions/streamlined_get_set.moon diff --git a/src/pop/extensions/streamlined_get_set.moon b/src/pop/extensions/streamlined_get_set.moon new file mode 100644 index 0000000..bfd8ab3 --- /dev/null +++ b/src/pop/extensions/streamlined_get_set.moon @@ -0,0 +1,14 @@ +-- adds methods to elements using a single function for get and set operations +-- ex: instead of getWidth() and setWidth(val), use width() and width(val) + +import graphics from love +import sub, len from string + +path = sub ..., 1, len(...) - len "/extensions/streamlined_get_set" +element = require "#{path}/elements/element" + +element.__base.position = (x, y) => + if x or y + return @setPosition x, y + else + return @getPosition! diff --git a/src/pop/init.moon b/src/pop/init.moon index aae4c28..cc434ee 100644 --- a/src/pop/init.moon +++ b/src/pop/init.moon @@ -47,6 +47,16 @@ pop.load = -> print "skin loaded: \"#{name}\"" + -- load extensions by just running them via require + extensions = filesystem.getDirectoryItems "#{path}/extensions" + + for i = 1, #extensions + unless extensions[i]\sub(-4) == ".lua" + continue + + name = extensions[i]\sub 1, -5 + require "#{path}/extensions/#{name}" + -- main window (called screen because there will be a window element class) pop.screen = pop.create("element", false)\setSize(graphics.getWidth!, graphics.getHeight!) print "created \"pop.screen\""