diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-04-19 17:38:31 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-04-19 17:38:42 -0700 |
| commit | 310712385b5bd3b9f25c1ba15ccdb8ad5606fc6c (patch) | |
| tree | 407900bc61fdad990f47f75e32ec7f6edfc05c8e /lua_obj.lua | |
| parent | ecb4341bdc62dac64b487ac6c67882da51e5205e (diff) | |
Made Source a little more concise.
Diffstat (limited to 'lua_obj.lua')
| -rw-r--r-- | lua_obj.lua | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lua_obj.lua b/lua_obj.lua index c4bbb32..4585d58 100644 --- a/lua_obj.lua +++ b/lua_obj.lua @@ -19,9 +19,9 @@ Source = immutable({ end, __tostring = function(self) if self.stop then - return "Source(\"" .. tostring(self.filename) .. "\", " .. tostring(self.start) .. ", " .. tostring(self.stop) .. ")" + return "\"" .. tostring(self.filename) .. "[" .. tostring(self.start) .. ":" .. tostring(self.stop) .. "]\"" else - return "Source(\"" .. tostring(self.filename) .. "\", " .. tostring(self.start) .. ")" + return "\"" .. tostring(self.filename) .. "[" .. tostring(self.start) .. "]\"" end end, __lt = function(self, other) @@ -148,11 +148,14 @@ do ... } if type(self.source) == 'string' then - local filename, start, stop = self.source:match("^(.-)[(%d+):(%d+)]$") + 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, #self) + self.source = Source(self.source, 1, #self + 1) end end end, |
