diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-15 16:36:21 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-15 16:36:38 -0700 |
| commit | 01aa199f7acfe9af57c5970793259b36e060fd11 (patch) | |
| tree | 0af9fd009d820053f83dd60eed862886bfb3eb5c /nomsu.lua | |
| parent | 28cd9ae0b7a09d8f2cd0cd929f1ebdce4b081502 (diff) | |
Adding support for coroutines, and cleaning up comment syntax.
Diffstat (limited to 'nomsu.lua')
| -rw-r--r-- | nomsu.lua | 40 |
1 files changed, 38 insertions, 2 deletions
@@ -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 |
