diff options
Diffstat (limited to 'code_obj.lua')
| -rw-r--r-- | code_obj.lua | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/code_obj.lua b/code_obj.lua index c563a91..4c9eac0 100644 --- a/code_obj.lua +++ b/code_obj.lua @@ -151,38 +151,37 @@ do _class_0 = setmetatable({ __init = function(self, source, ...) self.source = source - self.indents = { } self.bits = { ... } - if type(self.source) == 'string' then - local filename, start, stop = self.source:match("^(.-)%[(%d+):(%d+)%]$") - if not (filename) then - filename, start = self.source:match("^(.-)%[(%d+)%]$") - end - if start or stop then - self.source = Source(filename, tonumber(start), tonumber(stop)) - else - self.source = Source(self.source, 1, #tostring(self) + 1) - end - end - assert(self.source == nil or Source:is_instance(self.source)) - local indent = 0 + local indent, indents = 0, { } + local match = string.match for i, b in ipairs(self.bits) do - assert(not Source:is_instance(b)) if type(b) == 'string' then do - local spaces = b:match("\n([ ]*)[^\n]*$") + local spaces = match(b, "\n([ ]*)[^\n]*$") if spaces then indent = #spaces end end elseif indent ~= 0 then - self.indents[i] = indent + indents[i] = indent end end self.current_indent = indent + self.indents = indents self.__str = nil + if type(self.source) == 'string' then + local filename, start, stop = self.source:match("^(.-)%[(%d+):(%d+)%]$") + if not (filename) then + filename, start = self.source:match("^(.-)%[(%d+)%]$") + end + if start or stop then + self.source = Source(filename, tonumber(start), tonumber(stop)) + else + self.source = Source(self.source, 1, #tostring(self) + 1) + end + end end, __base = _base_0, __name = "Code" |
