mirror of
https://github.com/JamesonHuang/OpenWrt_Luci_Lua.git
synced 2025-06-18 09:13:15 +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)
|
Reference in New Issue
Block a user