aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--containers.lua10
-rw-r--r--containers.moon11
2 files changed, 11 insertions, 10 deletions
diff --git a/containers.lua b/containers.lua
index 1490a85..ab632c4 100644
--- a/containers.lua
+++ b/containers.lua
@@ -27,7 +27,7 @@ as_nomsu = function(self)
end
end
end
- return error("Not supported: " .. tostring(self))
+ return tostring(self)
end
local as_lua
as_lua = function(self)
@@ -45,7 +45,7 @@ as_lua = function(self)
end
end
end
- return error("Not supported: " .. tostring(self))
+ return tostring(self)
end
local _list_mt = {
__type = "List",
@@ -56,7 +56,7 @@ local _list_mt = {
local _len_0 = 1
for _index_0 = 1, #self do
local b = self[_index_0]
- _accum_0[_len_0] = tostring(b)
+ _accum_0[_len_0] = as_nomsu(b)
_len_0 = _len_0 + 1
end
return _accum_0
@@ -194,7 +194,7 @@ local _list_mt = {
end
return nil
end,
- slice_1_to_2 = function(self, start, stop)
+ from_1_to_2 = function(self, start, stop)
local n = #self
if n < 0 then
start = (n + 1 - start)
@@ -240,7 +240,7 @@ local _dict_mt = {
local _accum_0 = { }
local _len_0 = 1
for k, v in pairs(self) do
- _accum_0[_len_0] = tostring(tostring(k)) .. ": " .. tostring(tostring(v))
+ _accum_0[_len_0] = tostring(as_nomsu(k)) .. ": " .. tostring(as_nomsu(v))
_len_0 = _len_0 + 1
end
return _accum_0
diff --git a/containers.moon b/containers.moon
index 3c78037..8a91241 100644
--- a/containers.moon
+++ b/containers.moon
@@ -13,7 +13,7 @@ as_nomsu = =>
if mt = getmetatable(@)
if _as_nomsu = mt.as_nomsu
return _as_nomsu(@)
- error("Not supported: #{@}")
+ return tostring(@)
as_lua = =>
if type(@) == 'number'
@@ -21,16 +21,17 @@ as_lua = =>
if mt = getmetatable(@)
if _as_lua = mt.as_lua
return _as_lua(@)
- error("Not supported: #{@}")
+ return tostring(@)
-- List and Dict classes to provide basic equality/tostring functionality for the tables
-- used in Nomsu. This way, they retain a notion of whether they were originally lists or dicts.
+
_list_mt =
__type: "List"
__eq:equivalent
-- Could consider adding a __newindex to enforce list-ness, but would hurt performance
__tostring: =>
- "["..concat([tostring(b) for b in *@], ", ").."]"
+ "["..concat([as_nomsu(b) for b in *@], ", ").."]"
as_nomsu: =>
"["..concat([as_nomsu(b) for b in *@], ", ").."]"
as_lua: =>
@@ -77,7 +78,7 @@ _list_mt =
if x == item
return i
return nil
- slice_1_to_2: (start, stop)=>
+ from_1_to_2: (start, stop)=>
n = #@
start = (n+1-start) if n < 0
stop = (n+1-stop) if n < 0
@@ -101,7 +102,7 @@ _dict_mt =
__eq:equivalent
__len:size
__tostring: =>
- "{"..concat(["#{tostring(k)}: #{tostring(v)}" for k,v in pairs @], ", ").."}"
+ "{"..concat(["#{as_nomsu(k)}: #{as_nomsu(v)}" for k,v in pairs @], ", ").."}"
as_nomsu: =>
"{"..concat(["#{as_nomsu(k)}: #{as_nomsu(v)}" for k,v in pairs @], ", ").."}"
as_lua: =>