mirror of
https://github.com/JamesonHuang/OpenWrt_Luci_Lua.git
synced 2025-06-22 11:00:38 +00:00
adjust directory 2
This commit is contained in:
14
1_3.test_code/lua_test/1_1.test_convert_repeat_var.lua
Normal file
14
1_3.test_code/lua_test/1_1.test_convert_repeat_var.lua
Normal file
@ -0,0 +1,14 @@
|
||||
local val = "1,2,3,4,5,6,0"
|
||||
--local val = "1,2,3,4,5,6,0"
|
||||
--local val = "1,2,3,4,5,6,0"
|
||||
--local val = "1,3,5"
|
||||
local repeat_var = "0000000"
|
||||
for i = 1, #val, 2 do
|
||||
idx = string.sub(val, i, i)
|
||||
if idx ~= tostring(0) then
|
||||
repeat_var = string.sub(repeat_var, 0, idx - 1) .. tostring(1) .. string.sub(repeat_var, idx + 1, #repeat_var)
|
||||
else
|
||||
repeat_var = string.sub(repeat_var, 1, #repeat_var - 1) .. tostring(1)
|
||||
end
|
||||
print(repeat_var)
|
||||
end
|
2
1_3.test_code/lua_test/1_2.test_str_sub_from_last.lua
Normal file
2
1_3.test_code/lua_test/1_2.test_str_sub_from_last.lua
Normal file
@ -0,0 +1,2 @@
|
||||
local str = "hello world!"
|
||||
print(string.sub(str, -3, -1))
|
22
1_3.test_code/lua_test/test.lua
Normal file
22
1_3.test_code/lua_test/test.lua
Normal file
@ -0,0 +1,22 @@
|
||||
--[[print("lua")
|
||||
tmp2 = os.date("!*t")
|
||||
print(tmp2)
|
||||
tmp = os.date("*t")
|
||||
print(os.date())
|
||||
print(tmp)
|
||||
local x = os.time()
|
||||
print(x)
|
||||
]]--
|
||||
print(os.date(now))
|
||||
print(os.date("%x"))
|
||||
print(os.date("%M"))
|
||||
print(os.date("*t", now)) --table
|
||||
print(os.date("!*t", now)) --UTC
|
||||
|
||||
--字符串形式
|
||||
local tmp = os.date(now)
|
||||
print(tmp)
|
||||
--转table
|
||||
local tmp2 = os.date("!*t", tmp)
|
||||
|
||||
print( os.time(tmp2))
|
38
1_3.test_code/lua_test/test_str_foreach.lua
Normal file
38
1_3.test_code/lua_test/test_str_foreach.lua
Normal file
@ -0,0 +1,38 @@
|
||||
|
||||
---------------------Lua遍历字符串的每个字符-----------------------
|
||||
local s = "hello hi, again"
|
||||
print(string.len(s))
|
||||
|
||||
|
||||
--[[----failed,expected table, not a string
|
||||
for i, v in ipairs(s) do
|
||||
print(v)
|
||||
end
|
||||
]]--
|
||||
|
||||
|
||||
--[[success!
|
||||
for i = 0, #s do
|
||||
print(string.sub(s, i, i))
|
||||
end
|
||||
]]--
|
||||
|
||||
|
||||
--------------------------wifi repeat代码--------------------------
|
||||
local repeat_var_from_http = "1111111"
|
||||
if string.len(repeat_var_from_http) ~= 7 then
|
||||
print("len error")
|
||||
return
|
||||
end
|
||||
local week_repeat = ""
|
||||
for i = 1, #repeat_var_from_http do
|
||||
tmp = string.sub(repeat_var_from_http, i, i)
|
||||
if tmp == "1" then
|
||||
if(i == #repeat_var_from_http) then
|
||||
week_repeat = week_repeat..0
|
||||
break
|
||||
end
|
||||
week_repeat = week_repeat..tostring(i)..","
|
||||
end
|
||||
end
|
||||
print(week_repeat)
|
2
1_3.test_code/lua_test/test_three_eye_char.lua
Normal file
2
1_3.test_code/lua_test/test_three_eye_char.lua
Normal file
@ -0,0 +1,2 @@
|
||||
local var = 10 > 9 and 10 or 9
|
||||
print(var)
|
25
1_3.test_code/python_test/foreach_test.py
Normal file
25
1_3.test_code/python_test/foreach_test.py
Normal file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
|
||||
#遍历字符串每个字符
|
||||
word = 'helloworld!'
|
||||
str = "strcat method4: "
|
||||
for letter in word:
|
||||
print "strcat method1: " + letter
|
||||
print "strcat method2: ", letter
|
||||
print "strcat method3: %s" %(letter)
|
||||
#print str.join(letter) #fail
|
||||
|
||||
#遍历数组元素
|
||||
words = ['hello', 'world']
|
||||
for word in words:
|
||||
print "word:",word
|
||||
|
||||
#for(int i = 0; i < 10; i += 2)
|
||||
for num in range(0, 10, 2):
|
||||
print num
|
||||
|
||||
#index
|
||||
for index in range(len(words)):
|
||||
print words[index]
|
||||
|
15
1_3.test_code/sed_test/sedTest
Normal file
15
1_3.test_code/sed_test/sedTest
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
|
||||
|
||||
#* * * * * echo "hello" >> /cron.txt
|
||||
#* * * * * echo "face" >> /cron.txt
|
||||
#* * * * * echo "null" >> /cron.txt
|
||||
#* * * * * echo "teee" >> /cron.txt
|
||||
|
||||
|
||||
#* * * * * echo "test" >> /cron.txt
|
||||
|
||||
|
||||
|
||||
|
||||
|
10
1_3.test_code/sed_test/sed命令学习.txt
Normal file
10
1_3.test_code/sed_test/sed命令学习.txt
Normal file
@ -0,0 +1,10 @@
|
||||
移除空白行:
|
||||
sed -i '/^$/d' file
|
||||
|
||||
在指定行前加#号,注释该行:
|
||||
sed -i '/tacb/s/^/#/g' /etc/crontabs/root
|
||||
|
||||
取消#号,取消注释:
|
||||
sed -i '/hello/s/^#//' /etc/crontabs/root
|
||||
|
||||
cat t.txt|sed -n -e 's/^#\(.*\)/\1/p'
|
Reference in New Issue
Block a user