您的位置:

lua实现php的print的简单介绍

本文目录一览:

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