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

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/199499.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-05 10:22
下一篇 2024-12-05 10:22

相關推薦

  • PHP和Python哪個好找工作?

    PHP和Python都是非常流行的編程語言,它們被廣泛應用於不同領域的開發中。但是,在考慮擇業方向的時候,很多人都會有一個問題:PHP和Python哪個好找工作?這篇文章將從多個方…

    編程 2025-04-29
  • Python簡單數學計算

    本文將從多個方面介紹Python的簡單數學計算,包括基礎運算符、函數、庫以及實際應用場景。 一、基礎運算符 Python提供了基礎的算術運算符,包括加(+)、減(-)、乘(*)、除…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • Python海龜代碼簡單畫圖

    本文將介紹如何使用Python的海龜庫進行簡單畫圖,並提供相關示例代碼。 一、基礎用法 使用Python的海龜庫,我們可以控制一個小海龜在窗口中移動,並利用它的「畫筆」在窗口中繪製…

    編程 2025-04-29
  • PHP怎麼接幣

    想要在自己的網站或應用中接受比特幣等加密貨幣的支付,就需要對該加密貨幣擁有一定的了解,並使用對應的API進行開發。本文將從多個方面詳細闡述如何使用PHP接受加密貨幣的支付。 一、環…

    編程 2025-04-29
  • 如何使用Python將print輸出到界面?

    在Python中,print是最常用的調試技巧之一。在編寫代碼時,您可能需要在屏幕上輸出一些值、字符串或結果,以便您可以更好地理解並調試代碼。因此,在Python中將print輸出…

    編程 2025-04-29
  • Python print輸出變量

    Python是一種腳本語言,語法簡單易懂,目前被廣泛應用於數據處理、人工智能、web開發、遊戲開發等領域。其中print函數是Python中最常用的函數之一,用於將變量輸出到控制台…

    編程 2025-04-28
  • Python設置print顏色

    無論是在學習Python語言還是在實際開發中,輸出結果都是非常關鍵的部分。Python內置的print()函數是最常用的輸出方法之一,而如何設置輸出結果的顏色,則是開發人員經常遇到…

    編程 2025-04-28
  • Python櫻花樹代碼簡單

    本文將對Python櫻花樹代碼進行詳細的闡述和講解,幫助讀者更好地理解該代碼的實現方法。 一、簡介 櫻花樹是一種圖形效果,它的實現方法比較簡單。Python中可以通過turtle這…

    編程 2025-04-28
  • 使用PHP foreach遍歷有相同屬性的值

    本篇文章將介紹如何使用PHP foreach遍歷具有相同屬性的值,並給出相應的代碼示例。 一、基礎概念 在講解如何使用PHP foreach遍歷有相同屬性的值之前,我們需要先了解幾…

    編程 2025-04-28

發表回復

登錄後才能評論