Skip to content

Commit 73019b9

Browse files
author
Ian
committed
[!] Branch for lua v5.1.
1 parent 66cc705 commit 73019b9

File tree

12 files changed

+95
-130
lines changed

12 files changed

+95
-130
lines changed

lcf-scm-1.rockspec renamed to lcf-5.1-0.rockspec

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package = 'lcf'
2-
version = 'scm-1'
2+
version = '5.1-0'
33

44
source = {
55
url = 'git://github.com/martin-eden/lua_code_formatter.git',
6+
tag = '5.1-0',
67
}
78

89
description = {
@@ -18,7 +19,7 @@ easy to understand form, not the shortest one.
1819
}
1920

2021
dependencies = {
21-
'lua ~> 5.3',
22+
'lua == 5.1',
2223
}
2324

2425
build = {
@@ -113,7 +114,6 @@ build = {
113114
['lcf.workshop.file.as_string'] = 'workshop/file/as_string.lua',
114115
['lcf.workshop.file.exists'] = 'workshop/file/exists.lua',
115116
['lcf.workshop.file.get_size'] = 'workshop/file/get_size.lua',
116-
['lcf.workshop.file.get_unique_name'] = 'workshop/file/get_unique_name.lua',
117117
['lcf.workshop.file.safe_open'] = 'workshop/file/safe_open.lua',
118118
['lcf.workshop.file.text_file_as_string'] = 'workshop/file/text_file_as_string.lua',
119119
['lcf.workshop.graph.assembly_order'] = 'workshop/graph/assembly_order.lua',
@@ -126,8 +126,7 @@ build = {
126126
['lcf.workshop.handy_mechs.new'] = 'workshop/handy_mechs/new.lua',
127127
['lcf.workshop.handy_mechs.number_representer'] = 'workshop/handy_mechs/number_representer.lua',
128128
['lcf.workshop.handy_mechs.override_params'] = 'workshop/handy_mechs/override_params.lua',
129-
['lcf.workshop.handy_mechs.string_adders.any'] = 'workshop/handy_mechs/string_adders/any.lua',
130-
['lcf.workshop.handy_mechs.string_adders.file'] = 'workshop/handy_mechs/string_adders/file.lua',
129+
['lcf.workshop.handy_mechs.string_adders.array'] = 'workshop/handy_mechs/string_adders/array.lua',
131130
['lcf.workshop.load_from.generic_loader'] = 'workshop/load_from/generic_loader.lua',
132131
['lcf.workshop.load_from.lua'] = 'workshop/load_from/lua.lua',
133132
['lcf.workshop.load_from.lua.serialize_table.lua_code'] = 'workshop/load_from/lua/serialize_table/lua_code.lua',

workshop/base.lua

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,16 @@ do
2626
end
2727
end
2828
end
29-
_G.is_integer = function(n) return (math.type(n) == 'integer') end
30-
_G.assert_integer =
31-
function(a, responsibility_level)
32-
local responsibility_level = (responsibility_level or 1)
33-
if (math.type(a) ~= 'integer') then
34-
error(('Argument must be integer, not %s.'):format(type(a)), responsibility_level + 1)
35-
end
36-
end
3729
end
3830

3931
-- Make sure we have table.pack and table.unpack:
4032
do
41-
_G.table.pack = _G.table.pack or _G.pack
33+
_G.table.pack =
34+
_G.table.pack or
35+
_G.pack or
36+
function(...)
37+
return {n = select('#', ...), ...}
38+
end
4239
_G.table.unpack = _G.table.unpack or _G.unpack
4340
end
4441

workshop/compile/lua/serialize_table/lua_table/interface.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ return
66
always_index_keys = false,
77
name_giver = request('^.^.^.^.handy_mechs.name_giver'),
88
table_iterator = request('^.^.^.^.table.ordered_pass'),
9-
string_adder = request('^.^.^.^.handy_mechs.string_adders.any'),
9+
string_adder = request('^.^.^.^.handy_mechs.string_adders.array'),
1010
token_giver = request('^.^.token_givers.any'),
1111
quote_string = request('^.^.quote_string'),
1212
serialize_key = request('serialize_key'),

workshop/compile/lua/token_givers/readable.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ return
1414
if is_empty_table then
1515
return '}'
1616
else
17-
return '\n' .. self.indents_table.indents[deep // 2] .. '}'
17+
return '\n' .. self.indents_table.indents[math.floor(deep / 2)] .. '}'
1818
end
1919
end,
2020
records_delimiter =
@@ -28,9 +28,9 @@ return
2828
key_indent =
2929
function(self, deep, is_first)
3030
if is_first then
31-
return '\n' .. self.indents_table.indents[(deep + 1) // 2]
31+
return '\n' .. self.indents_table.indents[math.floor((deep + 1) / 2)]
3232
else
33-
return self.indents_table.indents[(deep + 1) // 2]
33+
return self.indents_table.indents[math.floor((deep + 1) / 2)]
3434
end
3535
end,
3636
key_prefix = '[',

workshop/file/as_string.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local safe_open = request('safe_open')
33
return
44
function(file_name)
55
local fIn = safe_open(file_name, 'rb')
6-
local result = fIn:read('a')
6+
local result = fIn:read('*a')
77
fIn:close()
88
return result
99
end

workshop/file/get_unique_name.lua

Lines changed: 0 additions & 26 deletions
This file was deleted.

workshop/handy_mechs/indents_table.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ local init =
55
{
66
__index =
77
function(t, key)
8-
if is_integer(key) then
8+
if is_number(key) then
9+
key = math.floor(key)
910
local value = self.indent_chunk:rep(key)
1011
t[key] = value
1112
return value

workshop/handy_mechs/number_representer.lua

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,19 @@ return
8484
local is_neg = (n < 0)
8585
n = math.abs(n)
8686

87-
::redo::
88-
local int_part, frac_part = math.modf(n)
89-
-- print(self.type, int_part, frac_part, pos, n)
90-
if units[pos - 1] and (int_part == 0) then
91-
n = n * units[pos][1]
92-
pos = pos - 1
93-
goto redo
94-
end
95-
if units[pos + 1] and (int_part >= units[pos + 1][1]) then
96-
pos = pos + 1
97-
n = n / units[pos][1]
98-
goto redo
87+
local int_part, frac_part
88+
while true do
89+
int_part, frac_part = math.modf(n)
90+
-- print(self.type, int_part, frac_part, pos, n)
91+
if units[pos - 1] and (int_part == 0) then
92+
n = n * units[pos][1]
93+
pos = pos - 1
94+
elseif units[pos + 1] and (int_part >= units[pos + 1][1]) then
95+
pos = pos + 1
96+
n = n / units[pos][1]
97+
else
98+
break
99+
end
99100
end
100101

101102
local unit_name = units[pos][2]

workshop/handy_mechs/string_adders/any.lua

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
-- String concatter implementation as array with bounded upper size.
2+
3+
--[[
4+
After reaching some threshold all elements of array compressed to
5+
one element and garbage collection is performed.
6+
]]
7+
8+
return
9+
{
10+
comfort_array_size = 4e6,
11+
maximum_array_size = 8e6,
12+
estimated_compression_to_act = math.sqrt(2),
13+
debug_output = false,
14+
data = {},
15+
table_rec_size = 52,
16+
total_data_len = 0,
17+
init =
18+
function(self)
19+
self.data = {}
20+
self.total_data_len = 0
21+
end,
22+
compress =
23+
function(self)
24+
self.data = {table.concat(self.data)}
25+
collectgarbage()
26+
end,
27+
add =
28+
function(self, term)
29+
self.data[#self.data + 1] = term
30+
self.total_data_len = self.total_data_len + #term
31+
if (#self.data > self.comfort_array_size) then
32+
local data_size = #self.data * self.table_rec_size + self.total_data_len
33+
local compressed_size = self.table_rec_size + self.total_data_len
34+
if
35+
(data_size / compressed_size > self.estimated_compression_to_act) or
36+
(#self.data > self.maximum_array_size)
37+
then
38+
local mem_before = collectgarbage('count') / 1024
39+
local num_els_before = #self.data
40+
self:compress()
41+
if self.debug_output then
42+
local mem_current = collectgarbage('count') / 1024
43+
print(
44+
('[#%.0fk, %.0fMB, %.0fMB, %.1f]: [%.0fMiB] -> [%.0fMiB][%.0fMiB]'):
45+
format(
46+
num_els_before / 1e3,
47+
data_size / 1e6,
48+
compressed_size / 1e6,
49+
(data_size - compressed_size) / 1e6,
50+
mem_before,
51+
mem_current,
52+
mem_before - mem_current
53+
)
54+
)
55+
end
56+
end
57+
end
58+
end,
59+
get_result =
60+
function(self)
61+
return table.concat(self.data)
62+
end,
63+
}

workshop/handy_mechs/string_adders/file.lua

Lines changed: 0 additions & 65 deletions
This file was deleted.

workshop/string/text_block/get_line_length.lua

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ return
22
function(self, line_num)
33
local line_len, text_len
44
if self.lines[line_num] then
5-
local indent_chunk_len = utf8.len(self.indent_chunk)
6-
text_len =
7-
(
8-
utf8.len(self.lines[line_num]) or
9-
string.len(self.lines[line_num])
10-
)
5+
local indent_chunk_len = #self.indent_chunk
6+
text_len = #self.lines[line_num]
117
line_len =
128
text_len + indent_chunk_len * self.line_indents[line_num]
139
end

0 commit comments

Comments
 (0)