Merge branch 'fennel-030' into 'master'
Upgrade to Fennel 0.3.0. See merge request alexjgriffith/min-love2d-fennel!3
This commit is contained in:
commit
67692bd5e0
746
lib/fennel.lua
746
lib/fennel.lua
File diff suppressed because it is too large
Load diff
|
@ -2,7 +2,7 @@ local function view_quote(str)
|
||||||
return ("\"" .. str:gsub("\"", "\\\"") .. "\"")
|
return ("\"" .. str:gsub("\"", "\\\"") .. "\"")
|
||||||
end
|
end
|
||||||
local short_control_char_escapes = {["\11"] = "\\v", ["\12"] = "\\f", ["\13"] = "\\r", ["\7"] = "\\a", ["\8"] = "\\b", ["\9"] = "\\t", ["\n"] = "\\n"}
|
local short_control_char_escapes = {["\11"] = "\\v", ["\12"] = "\\f", ["\13"] = "\\r", ["\7"] = "\\a", ["\8"] = "\\b", ["\9"] = "\\t", ["\n"] = "\\n"}
|
||||||
local long_control_char_esapes
|
local long_control_char_escapes = nil
|
||||||
do
|
do
|
||||||
local long = {}
|
local long = {}
|
||||||
for i = 0, 31 do
|
for i = 0, 31 do
|
||||||
|
@ -12,11 +12,11 @@ do
|
||||||
long[ch] = ("\\%03d"):format(i)
|
long[ch] = ("\\%03d"):format(i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
long_control_char_esapes = long
|
long_control_char_escapes = long
|
||||||
end
|
end
|
||||||
local function escape(str)
|
local function escape(str)
|
||||||
local str = str:gsub("\\", "\\\\")
|
local str = str:gsub("\\", "\\\\")
|
||||||
local str = str:gsub("(%c)%f[0-9]", long_control_char_esapes)
|
local str = str:gsub("(%c)%f[0-9]", long_control_char_escapes)
|
||||||
return str:gsub("%c", short_control_char_escapes)
|
return str:gsub("%c", short_control_char_escapes)
|
||||||
end
|
end
|
||||||
local function sequence_key_3f(k, len)
|
local function sequence_key_3f(k, len)
|
||||||
|
@ -84,7 +84,7 @@ local function puts(self, ...)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
local function tabify(self)
|
local function tabify(self)
|
||||||
return puts(self, "\n", self.indent:rep(self.level))
|
return puts(self, "\n", (self.indent):rep(self.level))
|
||||||
end
|
end
|
||||||
local function already_visited_3f(self, v)
|
local function already_visited_3f(self, v)
|
||||||
return (self.ids[v] ~= nil)
|
return (self.ids[v] ~= nil)
|
||||||
|
@ -99,10 +99,10 @@ local function get_id(self, v)
|
||||||
end
|
end
|
||||||
return tostring(id)
|
return tostring(id)
|
||||||
end
|
end
|
||||||
local function put_sequential_table(self, t, length)
|
local function put_sequential_table(self, t, len)
|
||||||
puts(self, "[")
|
puts(self, "[")
|
||||||
self.level = (self.level + 1)
|
self.level = (self.level + 1)
|
||||||
for i = 1, length do
|
for i = 1, len do
|
||||||
puts(self, " ")
|
puts(self, " ")
|
||||||
put_value(self, t[i])
|
put_value(self, t[i])
|
||||||
end
|
end
|
||||||
|
@ -110,19 +110,25 @@ local function put_sequential_table(self, t, length)
|
||||||
return puts(self, " ]")
|
return puts(self, " ]")
|
||||||
end
|
end
|
||||||
local function put_key(self, k)
|
local function put_key(self, k)
|
||||||
if ((type(k) == "string") and k:find("^[-%w?\\^_`!#$%&*+./@~:|<=>]+$")) then
|
if ((type(k) == "string") and k:find("^[-%w?\\^_!$%&*+./@:|<=>]+$")) then
|
||||||
return puts(self, ":", k)
|
return puts(self, ":", k)
|
||||||
else
|
else
|
||||||
return put_value(self, k)
|
return put_value(self, k)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function put_kv_table(self, t)
|
local function put_kv_table(self, t, ordered_keys)
|
||||||
puts(self, "{")
|
puts(self, "{")
|
||||||
self.level = (self.level + 1)
|
self.level = (self.level + 1)
|
||||||
for k, v in pairs(t) do
|
for _, k in ipairs(ordered_keys) do
|
||||||
tabify(self)
|
tabify(self)
|
||||||
put_key(self, k)
|
put_key(self, k)
|
||||||
puts(self, " ")
|
puts(self, " ")
|
||||||
|
put_value(self, t[k])
|
||||||
|
end
|
||||||
|
for i, v in ipairs(t) do
|
||||||
|
tabify(self)
|
||||||
|
put_key(self, i)
|
||||||
|
puts(self, " ")
|
||||||
put_value(self, v)
|
put_value(self, v)
|
||||||
end
|
end
|
||||||
self.level = (self.level - 1)
|
self.level = (self.level - 1)
|
||||||
|
@ -130,21 +136,21 @@ local function put_kv_table(self, t)
|
||||||
return puts(self, "}")
|
return puts(self, "}")
|
||||||
end
|
end
|
||||||
local function put_table(self, t)
|
local function put_table(self, t)
|
||||||
if already_visited_3f(self, t) then
|
if (already_visited_3f(self, t) and self["detect-cycles?"]) then
|
||||||
return puts(self, "#<table ", get_id(self, t), ">")
|
return puts(self, "#<table ", get_id(self, t), ">")
|
||||||
elseif (self.level >= self.depth) then
|
elseif (self.level >= self.depth) then
|
||||||
return puts(self, "{...}")
|
return puts(self, "{...}")
|
||||||
elseif "else" then
|
elseif "else" then
|
||||||
local non_seq_keys, length = get_nonsequential_keys(t)
|
local non_seq_keys, len = get_nonsequential_keys(t)
|
||||||
local id = get_id(self, t)
|
local id = get_id(self, t)
|
||||||
if (self.appearances[t] > 1) then
|
if ((1 < (self.appearances[t] or 0)) and self["detect-cycles?"]) then
|
||||||
return puts(self, "#<", id, ">")
|
return puts(self, "#<table", id, ">")
|
||||||
elseif ((#non_seq_keys == 0) and (#t == 0)) then
|
elseif ((#non_seq_keys == 0) and (#t == 0)) then
|
||||||
return puts(self, "{}")
|
return puts(self, "{}")
|
||||||
elseif (#non_seq_keys == 0) then
|
elseif (#non_seq_keys == 0) then
|
||||||
return put_sequential_table(self, t, length)
|
return put_sequential_table(self, t, len)
|
||||||
elseif "else" then
|
elseif "else" then
|
||||||
return put_kv_table(self, t)
|
return put_kv_table(self, t, non_seq_keys)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -161,10 +167,29 @@ local function _0_(self, v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
put_value = _0_
|
put_value = _0_
|
||||||
local function fennelview(root, options)
|
local function one_line(str)
|
||||||
|
local ret = str:gsub("\n", " "):gsub("%[ ", "["):gsub(" %]", "]"):gsub("%{ ", "{"):gsub(" %}", "}"):gsub("%( ", "("):gsub(" %)", ")")
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
local function fennelview(x, options)
|
||||||
local options = (options or {})
|
local options = (options or {})
|
||||||
local inspector = {["max-ids"] = {}, appearances = count_table_appearances(root, {}), buffer = {}, depth = (options.depth or 128), ids = {}, indent = (options.indent or " "), level = 0}
|
local inspector = inspector
|
||||||
put_value(inspector, root)
|
local function _1_()
|
||||||
return table.concat(inspector.buffer)
|
if options["one-line"] then
|
||||||
|
return ""
|
||||||
|
else
|
||||||
|
return " "
|
||||||
|
end
|
||||||
|
end
|
||||||
|
inspector = {["detect-cycles?"] = not (false == options["detect-cycles?"]), ["max-ids"] = {}, appearances = count_table_appearances(x, {}), buffer = {}, depth = (options.depth or 128), ids = {}, indent = (options.indent or _1_()), level = 0}
|
||||||
|
put_value(inspector, x)
|
||||||
|
do
|
||||||
|
local str = table.concat(inspector.buffer)
|
||||||
|
if options["one-line"] then
|
||||||
|
return one_line(str)
|
||||||
|
else
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return fennelview
|
return fennelview
|
||||||
|
|
35
wrap.fnl
35
wrap.fnl
|
@ -13,26 +13,25 @@
|
||||||
(mode.activate ...)))
|
(mode.activate ...)))
|
||||||
|
|
||||||
(fn love.load []
|
(fn love.load []
|
||||||
(: canvas :setFilter "nearest" "nearest")
|
(canvas:setFilter "nearest" "nearest")
|
||||||
(repl.start))
|
(repl.start))
|
||||||
|
|
||||||
(fn love.draw []
|
(fn love.draw []
|
||||||
;; the canvas allows you to get sharp pixel-art style scaling; if you
|
;; the canvas allows you to get sharp pixel-art style scaling; if you
|
||||||
;; don't want that, just skip that and call mode.draw directly.
|
;; don't want that, just skip that and call mode.draw directly.
|
||||||
(love.graphics.setCanvas canvas)
|
(love.graphics.setCanvas canvas)
|
||||||
(love.graphics.clear)
|
(love.graphics.clear)
|
||||||
(love.graphics.setColor 1 1 1)
|
(love.graphics.setColor 1 1 1)
|
||||||
(mode.draw)
|
(mode.draw)
|
||||||
(love.graphics.setCanvas)
|
(love.graphics.setCanvas)
|
||||||
(love.graphics.setColor 1 1 1)
|
(love.graphics.setColor 1 1 1)
|
||||||
(love.graphics.draw canvas 0 0 0 scale scale))
|
(love.graphics.draw canvas 0 0 0 scale scale))
|
||||||
|
|
||||||
(fn love.update[dt]
|
(fn love.update [dt]
|
||||||
(mode.update dt set-mode))
|
(mode.update dt set-mode))
|
||||||
|
|
||||||
(fn love.keypressed [key]
|
(fn love.keypressed [key]
|
||||||
(if
|
(if (and (love.keyboard.isDown "lctrl" "rctrl" "capslock") (= key "q"))
|
||||||
(and (love.keyboard.isDown "lctrl" "rctrl" "capslock") (= key "q"))
|
(love.event.quit)
|
||||||
(love.event.quit)
|
;; add what each keypress should do in each mode
|
||||||
;; add what each keypress should do in each mode
|
(mode.keypressed key set-mode)))
|
||||||
(mode.keypressed key set-mode)))
|
|
||||||
|
|
Loading…
Reference in a new issue