Category:Lua

  • Lua script to get MP3 Audio address

    Time:2022-5-5

    It can run directly under Linux ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 #!/usr/bin/lua5.1 –Luacurl http://luacurl.luaforge.net/ –luajson https://github.com/mbalmer/luajson require(“luacurl”) require(‘json’) […]

  • Lua gets UTF8 string length and string interception and uses replace

    Time:2022-5-4

    1、 Lua get UTF8 string length Copy codeThe code is as follows: —Method for obtaining the correct length of utf8 encoded string — @param str — @return number function utfstrlen(str) local len = #str; local left = len; local cnt = 0; local arr={0,0xc0,0xe0,0xf0,0xf8,0xfc}; while left ~= 0 do local tmp=string.byte(str,-left); local i=#arr; while arr[i] […]

  • Lua performance optimization skills (I): Preface

    Time:2022-5-3

    And in all othersprograming languageAs in, inLuaIn, we should still follow the following two maxims on program optimization: Principle 1: do not optimize.Principle 2: do not optimize for the time being (for experts). These two principles are particularly meaningful for Lua programming, which stands out among scripting languages because of its performance. Of course, we […]

  • Lua performance optimization skills (II): basic facts

    Time:2022-5-2

    Before running any code, Lua will translate (precompile) the source code into an internal format. This format is a virtual machine instruction sequence, which is similar to the machine code executed by the real CPU. After that, the internal format will be interpreted and executed by C code composed of a while loop containing a […]

  • Lua performance optimization skills (III): about table

    Time:2022-5-1

    In general, you don’t need to know the details of lua implementation table to use it. In fact, Lua spent a lot of effort to hide the internal implementation details. However, the implementation details reveal the performance overhead of table operations. Therefore, to optimize the program using tables (specifically Lua program here), it is very […]

  • Lua performance optimization skills (IV): about string

    Time:2022-4-30

    Similar to the table, understanding how Lua implements strings allows you to use it more efficiently. Lua implements strings in a way that is different from the two main ways used by most other scripting languages. First, all strings in Lua are internalized [1], which means that Lua maintains a single copy of any string. […]

  • Lua performance optimization skills (V): reduction, reuse and recycling

    Time:2022-4-29

    When dealing with Lua resources, we should also follow the 3R principle advocated for Earth Resources – reduce, reuse and recycle, that is, reduce, reuse and recycle. Cutting is the easiest way. There are many ways to avoid using new objects. For example, if your program uses too many tables, you can consider changing the […]

  • Lua performance optimization skills (VI): final tips

    Time:2022-4-28

    As we said in the preface, optimization is a highly skilled work. Starting from whether the program needs to be optimized, there are several aspects to consider. If the program really has performance problems, we should focus on where and how to optimize it. The techniques we discuss here are neither the only nor the […]

  • Methods and user-defined functions for obtaining UTF8 string length in Lua

    Time:2022-4-27

    Copy codeThe code is as follows: —Method for obtaining the correct length of utf8 encoded string — @param str — @return number function utfstrlen(str) local len = #str; local left = len; local cnt = 0; local arr={0,0xc0,0xe0,0xf0,0xf8,0xfc}; while left ~= 0 do local tmp=string.byte(str,-left); local i=#arr; while arr[i] do if tmp>=arr[i] then left=left-i;break;end i=i-1; […]

  • Use examples of lua common time functions

    Time:2022-4-26

    ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 –Gets the current Greenwich mean time print(os.time())   –Get the string representation of the […]

  • Lua obtains the system time, time formatting method and formatting parameters

    Time:2022-4-25

    1、 Timestamp corresponding to the current system time Copy codeThe code is as follows: local ntime = os.time print(ntime) 2、 Format the time display, refer to the following tableIt is often used to set header, etc Copy codeThe code is as follows: ngx.header[“Last-Modified:”]  = os.date(“%a, %d %b %Y %X GMT”) ngx.header[“Content-Type”]    = “text/html; charset=utf-8” ngx.header[“Cache-Control”]   […]

  • Using packagepath in Lua to solve the path conflict problem of multiple projects

    Time:2022-4-24

    When multiple Lua projects have the same file names of multiple files in the same server, the files of the project in the front row in the path will be used first, resulting in the referenced files are not what you expect. For example, project a and project B have a file test Lua, and […]