diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-01-01 15:05:58 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-01-01 15:07:10 -0800 |
| commit | b6d3cbd61cd08e39d20a569b7c5ece6bb25897dd (patch) | |
| tree | ccf3930b7a2834ffad1a10a9d91f0042542dec34 /code_obj.lua | |
| parent | 0760d4fb6495c4aa4f74038457acede5063f514a (diff) | |
Misc changes, including text indented interpolations are now indented
relative to the text, not the opening '("', code objects can now remove
all free vars, the REPL uses global vars. Error API is changing a bit.
Diffstat (limited to 'code_obj.lua')
| -rw-r--r-- | code_obj.lua | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/code_obj.lua b/code_obj.lua index 5afca1d..a09608f 100644 --- a/code_obj.lua +++ b/code_obj.lua @@ -320,6 +320,10 @@ do return self:dirty() end, remove_free_vars = function(self, vars) + if vars == nil then + vars = nil + end + vars = vars or self:get_free_vars() if not (#vars > 0) then return end @@ -351,33 +355,34 @@ do end return self:dirty() end, - declare_locals = function(self, to_declare) - if to_declare == nil then - to_declare = nil - end - if to_declare == nil then - local seen - to_declare, seen = { }, { } - local gather_from - gather_from = function(self) - local _list_0 = self.free_vars - for _index_0 = 1, #_list_0 do - local var = _list_0[_index_0] - if not (seen[var]) then - seen[var] = true - to_declare[#to_declare + 1] = var - end + get_free_vars = function(self) + local vars, seen = { }, { } + local gather_from + gather_from = function(self) + local _list_0 = self.free_vars + for _index_0 = 1, #_list_0 do + local var = _list_0[_index_0] + if not (seen[var]) then + seen[var] = true + vars[#vars + 1] = var end - local _list_1 = self.bits - for _index_0 = 1, #_list_1 do - local bit = _list_1[_index_0] - if not (type(bit) == 'string') then - gather_from(bit) - end + end + local _list_1 = self.bits + for _index_0 = 1, #_list_1 do + local bit = _list_1[_index_0] + if not (type(bit) == 'string') then + gather_from(bit) end end - gather_from(self) end + gather_from(self) + return vars + end, + declare_locals = function(self, to_declare) + if to_declare == nil then + to_declare = nil + end + to_declare = to_declare or self:get_free_vars() if #to_declare > 0 then self:remove_free_vars(to_declare) self:prepend("local " .. tostring(concat(to_declare, ", ")) .. ";\n") |
