Skip to content

Commit c6cbe72

Browse files
committed
Update module for 0.3
1 parent 2558e28 commit c6cbe72

File tree

3 files changed

+101
-36
lines changed

3 files changed

+101
-36
lines changed

Makefile

Lines changed: 64 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,82 @@ LUA = /5.2
88
BETA = /5.3
99

1010
LUA_DIR = $(PREFIX)
11-
LUA_SHAREDIR = $(LUA_DIR)/share/lua
1211
LUA_LIBDIR = $(LUA_DIR)/lib/lua
12+
LUA_SHAREDIR = $(LUA_DIR)/share/lua
13+
14+
msg_install = 'Requires permission of "root" to create the system directory'
15+
msg_unistall = 'Requires permission of "root" to remove the system directory'
16+
msg_end = "Files can be located in:'\n '$(LUA_LIBDIR)/*Version' and '$(LUA_SHAREDIR)/*Version'\nTo remove use '$ make unistall'"
17+
18+
install: all
19+
unistall: all
20+
21+
22+
installall: all
23+
all:
24+
@echo 'Module for Lua'
25+
@echo $(msg_install)
26+
@sudo mkdir -p $(LUA_LIBDIR)$(LAST)
27+
@sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(LAST)
28+
@sudo mkdir -p $(LUA_LIBDIR)$(LUA)
29+
@sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(LUA)
30+
@sudo mkdir -p $(LUA_LIBDIR)$(BETA)
31+
@sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(BETA)
32+
@sudo mkdir -p $(LUA_SHAREDIR)$(LAST)
33+
@sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(LAST)
34+
@sudo mkdir -p $(LUA_SHAREDIR)$(LUA)
35+
@sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(LUA)
36+
@sudo mkdir -p $(LUA_SHAREDIR)$(BETA)
37+
@sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(BETA)
38+
@echo $(msg_end)
1339

14-
install: 5.2
15-
1640
5.1:
17-
@echo 'Libs for Lua5.1'
18-
@echo 'Requirement permission "root" to create directory in the system'
41+
@echo 'Module for Lua5.1'
42+
@echo $(msg_install)
1943
@sudo mkdir -p $(LUA_LIBDIR)$(LAST)
44+
@sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(LAST)
2045
@sudo mkdir -p $(LUA_SHAREDIR)$(LAST)
21-
@cp -f $(SOURCES) $(LUA_LIBDIR)$(LAST)
22-
@cp -f $(SOURCES) $(LUA_SHAREDIR)$(LAST)
23-
@echo 'Files can be located in:'
24-
@echo "'$(LUA_LIBDIR)' and '@(LUA_SHAREDIR)'"
25-
@echo "To remove use '$ make unistall'"
46+
@sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(LAST)
47+
@echo $(msg_end)
2648

2749
5.2:
28-
@echo 'Libs for Lua5.2'
29-
@echo 'Requirement permission "root" to create directory in the system'
50+
@echo 'Module for Lua5.2'
51+
@echo $(msg_install)
3052
@sudo mkdir -p $(LUA_LIBDIR)$(LUA)
53+
@sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(LUA)
3154
@sudo mkdir -p $(LUA_SHAREDIR)$(LUA)
32-
@cp -f $(SOURCES) $(LUA_LIBDIR)$(LUA)
33-
@cp -f $(SOURCES) $(LUA_SHAREDIR)$(LUA)
34-
@echo 'Files can be located in:'
35-
@echo "'$(LUA_LIBDIR)' and '@(LUA_SHAREDIR)'"
36-
@echo "To remove use '$ make unistall'"
55+
@sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(LUA)
56+
@echo $(msg_end)
3757

3858
5.3:
39-
@echo 'Libs for Lua5.3'
40-
@echo 'Requirement permission "root" to create directory in the system'
59+
@echo 'Module for Lua5.3'
60+
@echo $(msg_install)
4161
@sudo mkdir -p $(LUA_LIBDIR)$(BETA)
62+
@sudo cp -f $(SOURCES) $(LUA_LIBDIR)$(BETA)
4263
@sudo mkdir -p $(LUA_SHAREDIR)$(BETA)
43-
@cp -f $(SOURCES) $(LUA_LIBDIR)$(BETA)
44-
@cp -f $(SOURCES) $(LUA_SHAREDIR)$(BETA)
45-
@echo 'Files can be located in:'
46-
@echo "'$(LUA_LIBDIR)' and '@(LUA_SHAREDIR)'"
47-
@echo "To remove use '$ make unistall'"
64+
@sudo cp -f $(SOURCES) $(LUA_SHAREDIR)$(BETA)
65+
@echo $(msg_end)
66+
67+
unistall5.1:
68+
@echo $(msg_install)
69+
@sudo rm -f $(LUA_LIBDIR)$(LAST)/htmlEntities.lua
70+
@sudo rm -f $(LUA_LIBDIR)$(LAST)/htmlEntities.lua
71+
72+
unistall5.2:
73+
@echo $(msg_install)
74+
@sudo rm -f $(LUA_LIBDIR)$(LUA)/htmlEntities.lua
75+
@sudo rm -f $(LUA_SHAREDIR)$(LUA)/htmlEntities.lua
76+
77+
unistall5.3:
78+
@echo $(msg_install)
79+
@sudo rm -f $(LUA_LIBDIR)$(BETA)/htmlEntities.lua
80+
@sudo rm -f $(LUA_SHAREDIR)$(BETA)/htmlEntities.lua
4881

49-
unistall:
82+
unistallall:
83+
@echo $(msg_install)
84+
@sudo rm -f $(LUA_LIBDIR)$(LAST)/htmlEntities.lua
5085
@sudo rm -f $(LUA_LIBDIR)$(LUA)/htmlEntities.lua
51-
@sudo rm -f $(LUA_SHAREDIR)$(LUA)/htmlEntities.lua
86+
@sudo rm -f $(LUA_LIBDIR)$(BETA)/htmlEntities.lua
87+
@sudo rm -f $(LUA_SHAREDIR)$(LAST)/htmlEntities.lua
88+
@sudo rm -f $(LUA_SHAREDIR)$(LUA)/htmlEntities.lua
89+
@sudo rm -f $(LUA_SHAREDIR)$(BETA)/htmlEntities.lua

example.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ function test_module()
55
local text = [[&XAMPLE text
66
⁢≡≡≡≡≡≡≡≡≡≡>]]
77

8+
for k,v in pairs(htmlEntities) do
9+
if v and type(v) == 'string' then
10+
print(k .. ': ' .. v)
11+
end
12+
end
13+
814
local dec = htmlEntities.decode(text)
9-
print('Version'..htmlEntities.version)
10-
print('Input: ' .. text .. '\n\nOutput: ' .. dec)
15+
print('\nInput: ' .. text .. '\n\nOutput: ' .. dec)
1116

1217
repeat
1318
io.write('\nYou want to do a test (y/n) ')
@@ -20,7 +25,8 @@ function test_module()
2025
io.write('> ')
2126
io.flush()
2227
local input = io.read()
23-
print('\nInput: ' .. input .. '\n\nOutput: ' .. htmlEntities.decode(input))
28+
--print('\nInput: ' .. input .. '\n\nOutput: ' .. htmlEntities.encode(input)) --Encode
29+
print('\nInput: ' .. input .. '\n\nOutput: ' .. htmlEntities.decode(input)) --Decode
2430
test()
2531
end
2632
if res == 'y' then test() end

src/htmlEntities.lua

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- Module options:
22
local debug_htmlEntities = false
33
local ASCII_htmlEntities = true
4+
local utf8_htmlEntities = true
45
local register_global_module_htmlEntities = false
56
local global_module_name_htmlEntities = 'htmlEntities'
67

@@ -29,9 +30,11 @@ Copyright (c) 2016 Tiago Danin
2930
]==]--
3031

3132
local htmlEntities = {
32-
version = "htmlEntities 0.2",
33-
name = "htmlEntities",
34-
author = "Tiago Danin - 2016"
33+
version = '0.3',
34+
name = 'htmlEntities-for-lua',
35+
author = 'Tiago Danin - 2016',
36+
license = 'The MIT License (MIT)',
37+
page = 'github.com/TiagoDanin/htmlEntities-for-lua'
3538
}
3639

3740
if register_global_module_htmlEntities then
@@ -309,16 +312,24 @@ local htmlEntities_table = {
309312
}
310313

311314
function htmlEntities.ASCII_dec (input)
315+
if not input then print('htmlEntities >> ERRO: input is value nil') return end
312316
if math.abs(input) < 256 then
313-
local output = input:char()
314-
return output
317+
if _VERSION == 'Lua 5.3' then
318+
return utf8.char(input)
319+
else
320+
local output = string.char(input)
321+
if utf8_htmlEntities and not output:match('([%z\1-\127\194-\244][\128-\191]*)')then
322+
return input
323+
end
324+
return output
325+
end
315326
else
316327
return input
317328
end
318329
end
319330

320331
function htmlEntities.decode (input)
321-
if not input then print('htmlEntities >> ERRO: input is value nil') end
332+
if not input then print('htmlEntities >> ERRO: input is value nil') return end
322333
local output = string.gsub(input, '&.-;', htmlEntities_table)
323334
if ASCII_htmlEntities then
324335
output = string.gsub(output, '&#([1234567890]*);', htmlEntities.ASCII_dec)
@@ -328,4 +339,14 @@ function htmlEntities.decode (input)
328339
return output
329340
end
330341

331-
return htmlEntities
342+
function htmlEntities.encode (input)
343+
if not input then print('htmlEntities >> ERRO: input is value nil') return end
344+
input = htmlEntities.decode(input)
345+
local output = ''
346+
for k = 1, string.len(input) do
347+
output = output .. '&#'.. string.sub(input,k,k):byte() ..';'
348+
end
349+
return output
350+
end
351+
352+
return htmlEntities

0 commit comments

Comments
 (0)