本文目錄一覽:
lua語言 怎麼將信息打印到界面
自己用代碼寫個打印信息到界面的函數,綁定到lua里,然後在lua里調用。
在Lua中運行print(os.date(“%x”, 906000490)),為什麼輸出是09/16/1998
你給的格式不對。
os.date ([format [, time]])
If format starts with ‘!’, then the date is formatted in Coordinated Universal Time. After this optional character, if format is the string “*t”, then date returns a table with the following fields: year (four digits), month (1–12), day (1–31), hour (0–23), min (0–59), sec (0–61), wday (weekday, Sunday is 1), yday (day of the year), and isdst (daylight saving flag, a boolean).
If format is not “*t”, then date returns the date as a string, formatted according to the same rules as the C function strftime.
strftime的格式大致如下:
%a Abbreviated weekday name
%A Full weekday name
%b Abbreviated month name
%B Full month name
%c Date and time representation appropriate for locale
%d Day of month as decimal number (01 – 31)
%H Hour in 24-hour format (00 – 23)
%I Hour in 12-hour format (01 – 12)
%j Day of year as decimal number (001 – 366)
%m Month as decimal number (01 – 12)
%M Minute as decimal number (00 – 59)
%p Current locale’s A.M./P.M. indicator for 12-hour clock
%S Second as decimal number (00 – 59)
%U Week of year as decimal number, with Sunday as first day of week (00 – 53)
%w Weekday as decimal number (0 – 6; Sunday is 0)
%W Week of year as decimal number, with Monday as first day of week (00 – 53)
%x Date representation for current locale
%X Time representation for current locale
%y Year without century, as decimal number (00 – 99)
%Y Year with century, as decimal number
%z, %Z Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown
%% Percent sign
Format code
%#c Long date and time representation, appropriate for current locale. For example: “Tuesday, March 14, 1995, 12:41:29”.
%#x Long date representation, appropriate to current locale. For example: “Tuesday, March 14, 1995”.
%#d, %#H, %#I, %#j, %#m, %#M, %#S, %#U, %#w, %#W, %#y, %#Y Remove leading zeros (if any).
怎麼把如下php代碼寫成lua代碼?
base64需要自己找個庫調用一下,其他部分實現了,下面是代碼
local function decode(str, skey)
str = str or “”
skey = skey or “cxphp”
local replaceStr = string.gsub(str, “O0O0O”, “=”)
replaceStr = string.gsub(replaceStr, “o000o”, “+”)
replaceStr = string.gsub(replaceStr, “oo00o”, “/”)
local strArr = {}
local replaceStrLen = string.len(replaceStr)
for pos = 1, replaceStrLen, 2 do
local posEnd = math.min(pos + 1, replaceStrLen)
strArr [#strArr + 1] = string.sub(replaceStr, pos, posEnd)
end
local strCount = #strArr
for key = 1, string.len(skey) do
local value = string.sub(skey, key, key)
print(key, value, strArr[key], string.sub(strArr[key], 2, 2))
if key = strCount and strArr[key] and string.sub(strArr[key], 2, 2) == value then
strArr[key] = string.sub(strArr[key], 1, 1)
end
end
local needToDecode = table.concat(strArr)
print(needToDecode)
— TODO: find a lib base64_decode
end
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/199499.html