aboutsummaryrefslogtreecommitdiff
path: root/nomsu.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-15 16:36:21 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-15 16:36:38 -0700
commit01aa199f7acfe9af57c5970793259b36e060fd11 (patch)
tree0af9fd009d820053f83dd60eed862886bfb3eb5c /nomsu.lua
parent28cd9ae0b7a09d8f2cd0cd929f1ebdce4b081502 (diff)
Adding support for coroutines, and cleaning up comment syntax.
Diffstat (limited to 'nomsu.lua')
-rw-r--r--nomsu.lua40
1 files changed, 38 insertions, 2 deletions
diff --git a/nomsu.lua b/nomsu.lua
index e835562..3c2fc4e 100644
--- a/nomsu.lua
+++ b/nomsu.lua
@@ -1,7 +1,7 @@
+local _pairs, _ipairs = pairs, ipairs
if jit then
package.cpath = "./luajit_lpeg/?.so;" .. package.cpath
bit32 = require('bit')
- local _pairs, _ipairs = pairs, ipairs
pairs = function(x)
do
local mt = getmetatable(x)
@@ -486,7 +486,7 @@ do
end
return nil
end,
- tree_with_replaced_vars = function(self, tree, replacements)
+ tree_with_replacements = function(self, tree, replacements)
if not (next(replacements)) then
return tree
end
@@ -669,6 +669,42 @@ do
return #x
end)
end
+ self.environment.ipairs = function(x)
+ if type(x) == 'function' then
+ return coroutine.wrap(x)
+ elseif type(x) == 'thread' then
+ return coroutine.resume, x, nil
+ else
+ do
+ local mt = getmetatable(x)
+ if mt then
+ if mt.__ipairs then
+ return mt.__ipairs(x)
+ end
+ else
+ return _ipairs(x)
+ end
+ end
+ end
+ end
+ self.environment.pairs = function(x)
+ if type(x) == 'function' then
+ return coroutine.wrap(x)
+ elseif type(x) == 'thread' then
+ return coroutine.resume, x, nil
+ else
+ do
+ local mt = getmetatable(x)
+ if mt then
+ if mt.__pairs then
+ return mt.__pairs(x)
+ end
+ else
+ return _pairs(x)
+ end
+ end
+ end
+ end
for k, v in pairs(Types) do
self.environment[k] = v
end