跟着 Lua 5.1 官方参考文档学习 Lua (12)
文章目录
- 5.7 – Input and Output Facilities
- 补充内容
- `io.input ([file])`
- `io.read (···)`
- `io.write (···)`
- `io.output ([file])`
- `io.lines ([filename])`
- `io.flush ()`
- `io.close ([file])`
- `io.open (filename [, mode])`
- `io.popen (prog [, mode])`
- `io.tmpfile ()`
- `io.type (ob)`
- `file:read (···)`
- `file:lines ()`
- `file:write (···)`
- `file:flush ()`
- `file:seek ([whence] [, offset])`
- `file:setvbuf (mode [, size])`
- `file:close ()`
- 5.8 – Operating System Facilities
- `os.clock ()`
- `os.date ([format [, time]])`
- `os.difftime (t2, t1)`
- `os.execute ([command])`
- `os.exit ([code])`
- `os.getenv (varname)`
- `os.remove (filename)`
- `os.rename (oldname, newname)`
- `os.setlocale (locale [, category])`
- `os.time ([table])`
- `os.tmpname ()`
- 5.9 – The Debug Library
- 6 – Lua Stand-alone
- 7 – Incompatibilities with the Previous Version
- 8 – The Complete Syntax of Lua
5.7 – Input and Output Facilities
The I/O library provides two different styles for file manipulation. The first one uses implicit file descriptors; that is, there are operations to set a default input file and a default output file, and all input/output operations are over these default files. The second style uses explicit file descriptors.
When using implicit file descriptors, all operations are supplied by table io
. When using explicit file descriptors, the operation io.open
returns a file descriptor and then all operations are supplied as methods of the file descriptor.
The table io
also provides three predefined file descriptors with their usual meanings from C: io.stdin
, io.stdout
, and io.stderr
. The I/O library never closes these files.
Unless otherwise stated, all I/O functions return nil on failure (plus an error message as a second result and a system-dependent error code as a third result) and some value different from nil on success.
补充内容
21.1 The Simple I/O Model
The simple model does all of its operations on two current files. The library initializes the current input file as the process standard input (stdin) and the current output file as the process standard output (stdout). Therefore, when we execute something like io.read(), we read a line from the standard input. We can change these current files with the io.input and io.output functions. A call like io.input(filename) opens the given file in read mode and sets it as the current input file. From this point on, all input will come from this file, until another call to io.input; io.output does a similar job for output. In case of error, both functions raise the error. If you want to handle errors directly, you must use io.open, from the complete model.
As write is simpler than read, we will look at it first. The io.write function simply gets an arbitrary number of string arguments and writes them to the current output file. Numbers are converted to strings following the usual conversion rules; for full control over this conversion, you should use the
string.format function:
> io.write("sin (3) = ", math.sin(3), "\n")
--> sin (3) = 0.14112000805987
> io.write(string.format("sin (3) = %.4f\n", math.sin(3)))
--> sin (3) = 0.1411
Avoid code like io.write(a…b…c); the call io.write(a,b,c) accomplishes the same effect with fewer resources, as it avoids the concatenations.
As a rule, you should use print for quick-and-dirty programs, or for debugging, and write when you need full control over your output:
> print("hello", "Lua"); print("Hi")
--> hello Lua
--> Hi
> io.write("hello", "Lua"); io.write("Hi", "\n")
--> helloLuaHi
Unlike print, write adds no extra characters to the output, such as tabs or newlines. Moreover, write uses the current output file, whereas print always uses the standard output. Finally, print automatically applies tostring to its arguments, so it can also show tables, functions, and nil.
The io.read function reads strings from the current input file. Its arguments control what is read:
“*all” reads the whole file
“*line” reads the next line
“*number” reads a number
num reads a string with up to num characters
The call *io.read("all") reads the whole current input file, starting at its current position. If we are at the end of the file, or if the file is empty, the call returns an empty string
Because Lua handles long strings efficiently, a simple technique for writing filters in Lua is to read the whole file into a string, do the processing to the string (typically with gsub), and then write the string to the output:
t = io.read("*all") -- read the whole file
t = string.gsub(t, ...) -- do the job
io.write(t) -- write the file
The call io.read(“*line”) returns the next line from the current input file, without the newline character. When we reach the end of file, the call returns nil (as there is no next line to return). This pattern is the default for read.
Usually, I use this pattern only when the algorithm naturally handles the file line by line; otherwise, I favor reading the whole file at once, with *all, or in blocks, as we will see later.
As a simple example of the use of this pattern, the following program copies
its current input to the current output, numbering each line:
for count = 1, math.huge dolocal line = io.read()if line == nil then break endio.write(string.format("%6d ", count), line, "\n")
end
However, to iterate on a whole file line by line, we do better to use the io.lines iterator. For instance, we can write a complete program to sort the lines of a file as follows:
local lines = {}
-- read the lines in table ’lines’
for line in io.lines() do lines[#lines + 1] = line end
-- sort
table.sort(lines)
-- write all the lines
for _, l in ipairs(lines) do io.write(l, "\n") end
Besides the basic read patterns, you can call read with a number n as an argument: in this case, read tries to read n characters from the input file. If it cannot read any character (end of file), read returns nil; otherwise, it returns a string with at most n characters.
As an example of this read pattern, the following program is an efficient way (in Lua, of course) to copy a file from stdin to stdout:
while true dolocal block = io.read(2 ^ 13) -- buffer size is 8Kif not block then break endio.write(block)
end
As a special case, io.read(0) works as a test for end of file: it returns an empty string if there is more to be read or nil otherwise.
21.2 The Complete I/O Model
For more control over I/O, you can use the complete model. A central concept in this model is the file handle, which is equivalent to streams (FILE*) in C: itrepresents an open file with a current position.
To open a file, you use the io.open function, which mimics the fopen function in C. It takes as arguments the name of the file to open plus a mode string. This mode string may contain an ‘r’ for reading, a ‘w’ for writing (which also erases any previous content of the file), or an ‘a’ for appending, plus an optional ‘b’ to open binary files. The open function returns a new handle for the file. In case of error, open returns nil, plus an error message and an error number:
print(io.open("non-existent-file", "r"))
--> nil non-existent-file: No such file or directory 2
print(io.open("/etc/passwd", "w"))
--> nil /etc/passwd: Permission denied 13
The interpretation of the error numbers is system dependent.
A typical idiom to check for errors is
local f = assert(io.open(filename, mode))
If the open fails, the error message goes as the second argument to assert, which then shows the message. After you open a file, you can read from it or write to it with the methods read/write. They are similar to the read/write functions, but you call them as methods on the file handle, using the colon syntax. For instance, to open a file and read it all, you can use a chunk like this:
local f = assert(io.open(filename, "r"))
local t = f:read("*all")
f:close()
The I/O library offers handles for the three predefined C streams: io.stdin, io.stdout, and io.stderr. So, you can send a message directly to the error stream with a code like this:
io.stderr:write(message)
We can mix the complete model with the simple model. We get the current input file handle by calling io.input(), without arguments. We set this handle with the call io.input(handle). (Similar calls are also valid for io.output.) For instance, if you want to change the current input file temporarily, you can write something like this:
local temp = io.input() -- save current file
io.input("newinput") -- open a new current file
-- <do something with new input>
io.input():close() -- close current file
io.input(temp) -- restore previous current file
A small performance trick
Usually, in Lua, it is faster to read a file as a whole than to read it line by line. However, sometimes we must face a big file (say, tens or hundreds megabytes) for which it is not reasonable to read it all at once. If you want to handle such big files with maximum performance, the fastest way is to read them in reasonably large chunks (e.g., 8 Kbytes each). To avoid the problem of breaking lines in the
middle, you simply ask to read a chunk plus a line:
local lines, rest = f:read(BUFSIZE, "*line")
The variable rest will get the rest of any line broken by the chunk. We then concatenate the chunk and this rest of line. This way, the resulting chunk will always break at line boundaries.
The example in Listing 21.1 uses this technique to implement wc, a program that counts the number of characters, words, and lines in a file.
local BUFSIZE = 2 ^ 13 -- 8K
local f = io.input(arg[1]) -- open input file
local cc, lc, wc = 0, 0, 0 -- char, line, and word counts
while true dolocal lines, rest = f:read(BUFSIZE, "*line")if not lines then break endif rest then lines = lines .. rest .. "\n" endcc = cc + #lines-- count words in the chunklocal _, t = string.gsub(lines, "%S+", "")wc = wc + t-- count newlines in the chunk_, t = string.gsub(lines, "\n", "\n")lc = lc + t
end
print(lc, wc, cc)
Binary files
The simple-model functions io.input and io.output always open a file in text mode (the default). In Unix, there is no difference between binary files and text files. But in some systems, notably Windows, binary files must be opened with a special flag. To handle such binary files, you must use io.open, with the letter ‘b’ in the mode string.
Binary data in Lua are handled similarly to text. A string in Lua may contain any bytes, and almost all functions in the libraries can handle arbitrary bytes. You can even do pattern matching over binary data, as long as the pattern does not contain a zero byte. If you want to match this byte in the subject, you can use the class %z instead.
Typically, you read binary data either with the *all pattern, that reads the whole file, or with the pattern n, that reads n bytes. As a simple example, the following program converts a text file from DOS format to Unix format (that is, it translates sequences of carriage return–newlines to newlines). It does not use the standard I/O files (stdin–stdout), because these files are open in text mode. Instead, it assumes that the names of the input file and the output file are given as arguments to the program:
local inp = assert(io.open(arg[1], "rb"))
local out = assert(io.open(arg[2], "wb"))
local data = inp:read("*all")
data = string.gsub(data, "\r\n", "\n")
out:write(data)
assert(out:close())
As another example, the following program prints all strings found in a binary file:
local f = assert(io.open(arg[1], "rb"))
local data = f:read("*all")
local validchars = "[%w%p%s]"
local pattern = string.rep(validchars, 6) .. "+%z"
for w in string.gmatch(data, pattern) doprint(w)
end
The program assumes that a string is any zero-terminated sequence of six or more valid characters, where a valid character is any character accepted by the pattern validchars. In our example, this pattern comprises the alphanumeric, the punctuation, and the space characters. We use string.rep and concatenation to create a pattern that captures all sequences of six or more validchars. The %z at the end of the pattern matches the byte zero at the end of a string.
As a last example, the following program makes a dump of a binary file:
vlocal f = assert(io.open(arg[1], "rb"))
local block = 16
while true dolocal bytes = f:read(block)if not bytes then break endfor _, b in pairs { string.byte(bytes, 1, -1) } doio.write(string.format("%02X ", b))endio.write(string.rep(" ", block - string.len(bytes)))io.write(" ", string.gsub(bytes, "%c", "."), "\n")
end
Again, the first program argument is the input file name; the output goes to the standard output. The program reads the file in chunks of 16 bytes. For each chunk, it writes the hexadecimal representation of each byte, and then it writes the chunk as text, changing control characters to dots. (Note the use of the idiom {string.byte(bytes,1,-1)} to create a table with all bytes of the string bytes.)
21.3 Other Operations on Files
The tmpfile function returns a handle for a temporary file, open in read/write mode. This file is automatically removed (deleted) when your program ends.
The flush function executes all pending writes to a file. Like the write function, you can call it as a function, io.flush(), to flush the current output file; or as a method, f:flush(), to flush a particular file f.
The seek function can both get and set the current position of a file. Its general form is f:seek(whence,offset). The whence parameter is a string that specifies how to interpret the offset. Its valid values are “set”, when offsets are interpreted from the beginning of the file; “cur”, when offsets are interpreted from the current position of the file; and “end”, when offsets are interpreted from the end of the file. Independently of the value of whence, the call returns the final current position of the file, measured in bytes from the beginning of the file.
The default value for whence is “cur” and for offset is zero. Therefore, the call file:seek() returns the current file position, without changing it; the call file:seek(“set”) resets the position to the beginning of the file (and returns zero); and the call file:seek(“end”) sets the position to the end of the file and returns its size. The following function gets the file size without changing its current position:
function fsize(file)local current = file:seek() -- get current positionlocal size = file:seek("end") -- get file sizefile:seek("set", current) -- restore positionreturn size
end
All these functions return nil plus an error message in case of error.
io.input ([file])
When called with a file name, it opens the named file (in text mode), and sets its handle as the default input file. When called with a file handle, it simply sets this file handle as the default input file. When called without parameters, it returns the current default input file.
In case of errors this function raises the error, instead of returning an error code.
io.read (···)
Equivalent to io.input():read
.
io.write (···)
Equivalent to io.output():write
.
io.output ([file])
Similar to io.input
, but operates over the default output file.
io.lines ([filename])
Opens the given file name in read mode and returns an iterator function that, each time it is called, returns a new line from the file. Therefore, the construction
for line in io.lines(filename) do body end
will iterate over all lines of the file. When the iterator function detects the end of file, it returns nil (to finish the loop) and automatically closes the file.
The call io.lines()
(with no file name) is equivalent to io.input():lines()
; that is, it iterates over the lines of the default input file. In this case it does not close the file when the loop ends.
io.flush ()
Equivalent to file:flush
over the default output file.
io.close ([file])
Equivalent to file:close()
. Without a file
, closes the default output file.
io.open (filename [, mode])
This function opens a file, in the mode specified in the string mode
. It returns a new file handle, or, in case of errors, nil plus an error message.
The mode
string can be any of the following:
- “r”: read mode (the default);
- “w”: write mode;
- “a”: append mode;
- “r+”: update mode, all previous data is preserved;
- “w+”: update mode, all previous data is erased;
- “a+”: append update mode, previous data is preserved, writing is only allowed at the end of file.
The mode
string can also have a ‘b
’ at the end, which is needed in some systems to open the file in binary mode. This string is exactly what is used in the standard C function fopen
.
io.popen (prog [, mode])
Starts program prog
in a separated process and returns a file handle that you can use to read data from this program (if mode
is "r"
, the default) or to write data to this program (if mode
is "w"
).
This function is system dependent and is not available on all platforms.
io.tmpfile ()
Returns a handle for a temporary file. This file is opened in update mode and it is automatically removed when the program ends.
io.type (ob)
Checks whether obj
is a valid file handle. Returns the string "file"
if obj
is an open file handle, "closed file"
if obj
is a closed file handle, or nil if obj
is not a file handle.
file:read (···)
Reads the file file
, according to the given formats, which specify what to read. For each format, the function returns a string (or a number) with the characters read, or nil if it cannot read data with the specified format. When called without formats, it uses a default format that reads the entire next line (see below).
The available formats are
- “*n”: reads a number; this is the only format that returns a number instead of a string.
- “*a”: reads the whole file, starting at the current position. On end of file, it returns the empty string.
- “*l”: reads the next line (skipping the end of line), returning nil on end of file. This is the default format.
- *number*: reads a string with up to this number of characters, returning nil on end of file. If number is zero, it reads nothing and returns an empty string, or nil on end of file.
file:lines ()
Returns an iterator function that, each time it is called, returns a new line from the file. Therefore, the construction
for line in file:lines() do body end
will iterate over all lines of the file. (Unlike io.lines
, this function does not close the file when the loop ends.)
file:write (···)
Writes the value of each of its arguments to the file
. The arguments must be strings or numbers. To write other values, use tostring
or string.format
before write
.
file:flush ()
Saves any written data to file
.
file:seek ([whence] [, offset])
Sets and gets the file position, measured from the beginning of the file, to the position given by offset
plus a base specified by the string whence
, as follows:
- “set”: base is position 0 (beginning of the file);
- “cur”: base is current position;
- “end”: base is end of file;
In case of success, function seek
returns the final file position, measured in bytes from the beginning of the file. If this function fails, it returns nil, plus a string describing the error.
The default value for whence
is "cur"
, and for offset
is 0. Therefore, the call file:seek()
returns the current file position, without changing it; the call file:seek("set")
sets the position to the beginning of the file (and returns 0); and the call file:seek("end")
sets the position to the end of the file, and returns its size.
file:setvbuf (mode [, size])
Sets the buffering mode for an output file. There are three available modes:
- “no”: no buffering; the result of any output operation appears immediately.
- “full”: full buffering; output operation is performed only when the buffer is full (or when you explicitly
flush
the file (seeio.flush
)). - “line”: line buffering; output is buffered until a newline is output or there is any input from some special files (such as a terminal device).
For the last two cases, size
specifies the size of the buffer, in bytes. The default is an appropriate size.
file:close ()
Closes file
. Note that files are automatically closed when their handles are garbage collected, but that takes an unpredictable amount of time to happen.
5.8 – Operating System Facilities
This library is implemented through table os
.
os.clock ()
Returns an approximation of the amount in seconds of CPU time used by the program.
os.date ([format [, time]])
Returns a string or a table containing date and time, formatted according to the given string format
.
If the time
argument is present, this is the time to be formatted (see the os.time
function for a description of this value). Otherwise, date
formats the current 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
.
When called without arguments, date
returns a reasonable date and time representation that depends on the host system and on the current locale (that is, os.date()
is equivalent to os.date("%c")
).
os.difftime (t2, t1)
Returns the number of seconds from time t1
to time t2
. In POSIX, Windows, and some other systems, this value is exactly t2
-t1
.
os.execute ([command])
This function is equivalent to the C function system
. It passes command
to be executed by an operating system shell. It returns a status code, which is system-dependent. If command
is absent, then it returns nonzero if a shell is available and zero otherwise.
os.exit ([code])
Calls the C function exit
, with an optional code
, to terminate the host program. The default value for code
is the success code.
os.getenv (varname)
Returns the value of the process environment variable varname
, or nil if the variable is not defined.
os.remove (filename)
Deletes the file or directory with the given name. Directories must be empty to be removed. If this function fails, it returns nil, plus a string describing the error.
os.rename (oldname, newname)
Renames file or directory named oldname
to newname
. If this function fails, it returns nil, plus a string describing the error.
os.setlocale (locale [, category])
Sets the current locale of the program. locale
is a string specifying a locale; category
is an optional string describing which category to change: "all"
, "collate"
, "ctype"
, "monetary"
, "numeric"
, or "time"
; the default category is "all"
. The function returns the name of the new locale, or nil if the request cannot be honored.
If locale
is the empty string, the current locale is set to an implementation-defined native locale. If locale
is the string “C
”, the current locale is set to the standard C locale.
When called with nil as the first argument, this function only returns the name of the current locale for the given category.
os.time ([table])
Returns the current time when called without arguments, or a time representing the date and time specified by the given table. This table must have fields year
, month
, and day
, and may have fields hour
, min
, sec
, and isdst
(for a description of these fields, see the os.date
function).
The returned value is a number, whose meaning depends on your system. In POSIX, Windows, and some other systems, this number counts the number of seconds since some given start time (the “epoch”). In other systems, the meaning is not specified, and the number returned by time
can be used only as an argument to date
and difftime
.
os.tmpname ()
Returns a string with a file name that can be used for a temporary file. The file must be explicitly opened before its use and explicitly removed when no longer needed.
On some systems (POSIX), this function also creates a file with that name, to avoid security risks. (Someone else might create the file with wrong permissions in the time between getting the name and creating the file.) You still have to open the file to use it and to remove it (even if you do not use it).
When possible, you may prefer to use io.tmpfile
, which automatically removes the file when the program ends.
5.9 – The Debug Library
This library provides the functionality of the debug interface to Lua programs. You should exert care when using this library. The functions provided here should be used exclusively for debugging and similar tasks, such as profiling. Please resist the temptation to use them as a usual programming tool: they can be very slow. Moreover, several of these functions violate some assumptions about Lua code (e.g., that variables local to a function cannot be accessed from outside or that userdata metatables cannot be changed by Lua code) and therefore can compromise otherwise secure code.
All functions in this library are provided inside the debug
table. All functions that operate over a thread have an optional first argument which is the thread to operate over. The default is always the current thread.
略
6 – Lua Stand-alone
略
7 – Incompatibilities with the Previous Version
略
8 – The Complete Syntax of Lua
Here is the complete syntax of Lua in extended BNF. (It does not describe operator precedences.)
chunk ::= {stat [`;´]} [laststat [`;´]]block ::= chunkstat ::= varlist `=´ explist | functioncall | do block end | while exp do block end | repeat block until exp | if exp then block {elseif exp then block} [else block] end | for Name `=´ exp `,´ exp [`,´ exp] do block end | for namelist in explist do block end | function funcname funcbody | local function Name funcbody | local namelist [`=´ explist] laststat ::= return [explist] | breakfuncname ::= Name {`.´ Name} [`:´ Name]varlist ::= var {`,´ var}var ::= Name | prefixexp `[´ exp `]´ | prefixexp `.´ Name namelist ::= Name {`,´ Name}explist ::= {exp `,´} expexp ::= nil | false | true | Number | String | `...´ | function | prefixexp | tableconstructor | exp binop exp | unop exp prefixexp ::= var | functioncall | `(´ exp `)´functioncall ::= prefixexp args | prefixexp `:´ Name args args ::= `(´ [explist] `)´ | tableconstructor | String function ::= function funcbodyfuncbody ::= `(´ [parlist] `)´ block endparlist ::= namelist [`,´ `...´] | `...´tableconstructor ::= `{´ [fieldlist] `}´fieldlist ::= field {fieldsep field} [fieldsep]field ::= `[´ exp `]´ `=´ exp | Name `=´ exp | expfieldsep ::= `,´ | `;´binop ::= `+´ | `-´ | `*´ | `/´ | `^´ | `%´ | `..´ | `<´ | `<=´ | `>´ | `>=´ | `==´ | `~=´ | and | orunop ::= `-´ | not | `#´
相关文章:

跟着 Lua 5.1 官方参考文档学习 Lua (12)
文章目录 5.7 – Input and Output Facilities补充内容io.input ([file])io.read ()io.write ()io.output ([file])io.lines ([filename])io.flush ()io.close ([file])io.open (filename [, mode])io.popen (prog [, mode])io.tmpfile ()io.type (ob)file:read ()file:lines (…...

大语言模型中的归一化技术:LayerNorm与RMSNorm的深入研究
在LLama等大规模Transformer架构的语言模型中,归一化模块是构建网络稳定性的关键组件。本文将系统分析归一化技术的必要性,并详细阐述为何原始Transformer架构中的LayerNorm在LLama模型中被RMSNorm所替代的技术原理。 归一化技术的基础原理 归一化的核…...

nodejs使用WebSocket实现聊天效果
在nodejs中使用WebSocket实现聊天效果(简易实现) 安装 npm i ws 实现 创建 server.js /*** 创建一个 WebSocket 服务器,监听指定端口,并处理客户端连接和消息。** param {Object} WebSocket - 引入的 WebSocket 模块,…...

【仿muduo库one thread one loop式并发服务器实现】
文章目录 一、项目介绍1-1、项目总体简介1-2、项目开发环境1-3、项目核心技术1-4、项目开发流程1-5、项目如何使用 二、框架设计2-1、功能模块划分2-1-1、SERVER模块2-1-2、协议模块 2-2、项目蓝图2-2-1、整体图2-2-2、模块关系图2-2-2-1、Connection 模块关系图2-2-2-2、Accep…...

10.2 继承与多态
文章目录 继承多态 继承 继承的作用是代码复用。派生类自动获得基类的除私有成员外的一切。基类描述一般特性,派生类提供更丰富的属性和行为。在构造派生类时,其基类构造函数先被调用,然后是派生类构造函数。在析构时顺序刚好相反。 // 基类…...

Go红队开发—格式导出
文章目录 输出功能CSV输出CSV 转 结构体结构体 转 CSV端口扫描结果使用CSV格式导出 HTML输出Sqlite输出nmap扫描 JSONmap转json结构体转jsonjson写入文件json编解码json转结构体json转mapjson转string练习:nmap扫描结果导出json格式 输出功能 在我们使用安全工具的…...

线性代数之矩阵特征值与特征向量的数值求解方法
文章目录 前言1. 幂迭代法(Power Iteration)幂法与反幂法求解矩阵特征值幂法求最大特征值编程实现补充说明 2. 逆幂迭代法(Inverse Iteration)移位反幂法 3. QR 算法(QR Algorithm)——稠密矩阵理论推导编程…...

Spring MVC源码分析のinit流程
文章目录 前言一、 init1.1、createWebApplicationContext1.2、onRefresh 二、请求处理器2.1、RequestMapping2.2、Controller接口2.3、HttpRequestHandler接口2.4、HandlerFunction 三、initHandlerMappings3.1、getDefaultStrategies3.1.1、RequestMappingHandlerMapping3.1.…...

【后端开发】go-zero微服务框架实践(goland框架对比,go-zero开发实践,文件上传问题优化等等)
【后端开发】go-zero微服务框架实践(goland框架对比,go-zero开发实践,文件上传问题优化等) 文章目录 1、go框架对比介绍2、go-zero 微服务开发实践3、go-zero 文件上传问题优化 1、go框架对比介绍 国内开源goland框架对比 1 go-…...

C#程序加密与解密Demo程序示例
目录 一、加密程序功能介绍 1、加密用途 2、功能 3、程序说明 4、加密过程 5、授权的注册文件保存方式 二、加密程序使用步骤 1、步骤一 编辑2、步骤二 3、步骤三 4、步骤四 三、核心代码说明 1、获取电脑CPU 信息 2、获取硬盘卷标号 3、机器码生成 3、 生成…...

小程序事件系统 —— 33 事件传参 - data-*自定义数据
事件传参:在触发事件时,将一些数据作为参数传递给事件处理函数的过程,就是事件传参; 在微信小程序中,我们经常会在组件上添加一些自定义数据,然后在事件处理函数中获取这些自定义数据,从而完成…...

深入解析 JavaScript 原型与原型链:从原理到应用
原型和原型链是 JavaScript 中实现对象继承和属性查找的核心机制。为了更深入地理解它们,我们需要从底层原理、实现机制以及实际应用等多个角度进行分析。 1. 原型(Prototype) 1.1 什么是原型? 每个 JavaScript 对象(…...

关于AI数据分析可行性的初步评估
一、结论:可在部分环节嵌入,无法直接处理大量数据 1.非本地部署的AI应用处理非机密文件没问题,内部文件要注意数据安全风险。 2.AI(指高规格大模型)十分适合探索性研究分析,对复杂报告无法全流程执行&…...

回归预测 | Matlab实现GWO-BP-Adaboost基于灰狼算法优化BP神经网络结合Adaboost思想的回归预测
回归预测 | Matlab实现GWO-BP-Adaboost基于灰狼算法优化BP神经网络结合Adaboost思想的回归预测 目录 回归预测 | Matlab实现GWO-BP-Adaboost基于灰狼算法优化BP神经网络结合Adaboost思想的回归预测回归效果基本介绍GWO-BP-Adaboost:基于灰狼算法优化BP神经网络结合Adaboost思想…...

ARM Cortex-M 内存映射详解:如何基于寄存器直接读写 寄存器映射方式编码程序 直接操作硬件寄存器来控制 MCU
ARM Cortex-M 的系统映射空间 在 STM32 等 ARM Cortex-M 系列 MCU 中,内存地址空间按照 存储功能 进行了严格划分,包括 Flash(程序存储)、RAM(数据存储)、外设寄存器(GPIO、UART、SPI 等&am…...

深度学习实战车辆目标跟踪与计数
本文采用YOLOv8作为核心算法框架,结合PyQt5构建用户界面,使用Python3进行开发。YOLOv8以其高效的实时检测能力,在多个目标检测任务中展现出卓越性能。本研究针对车辆目标数据集进行训练和优化,该数据集包含丰富的车辆目标图像样本…...

django中视图作用和视图功能 以及用法
在 Django REST Framework(DRF)中,视图(View)是处理 HTTP 请求并返回响应的核心组件。DRF 提供了多种视图类,适用于不同的场景和需求。以下是 DRF 中常见的视图类及其作用、使用方法的详细说明: 一、DRF 视图的分类 DRF 的视图可以分为以下几类: 基于函数的视图(Func…...

【每日学点HarmonyOS Next知识】输入框自动获取焦点、JS桥实现方式、Popup设置全屏蒙版、鼠标事件适配、Web跨域
1、HarmonyOS TextInput或TextArea如何自动获取焦点? 可以使用 focusControl.requestFocus 对需要获取焦点的组件设置焦点,具体可以参考文档: https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attribut…...

【学习思维模型】
学习思维模型 一、理解类模型二、记忆类模型三、解决问题类模型四、结构化学习模型五、效率与习惯类模型六、高阶思维模型七、实践建议八、新增学习思维模型**1. 波利亚问题解决四步法****2. 主动回忆(Active Recall)****3. 鱼骨图(因果图/Ishikawa Diagram)****4. MECE原则…...

MyBatis-Plus分页控件使用及使用过程发现的一个坑
最近维护一个旧项目的时候,出现了一个BUG,经排查后发现是Mybatis-plus分页控件使用的时候需要注意的一个问题,故在本地使用MybatisPlus模拟出现了一下这个问题。 首先,先说一下MyBatis-Plus的使用: 1)引入…...

STM32的APB1和APB2的区别
STM32微控制器中的APB1和APB2的区别 STM32微控制器中的APB1和APB2是两种不同的外设总线,主要区别在于时钟速度、连接的外设以及用途。以下是它们的详细对比: 1. 时钟速度 APB1 (Advanced Peripheral Bus 1): 低速总线,时钟频率通常为系统时钟…...

JS一些小知识点
一、|| 运算符 plain this.ctx.body { type: type || 0, // ||在此处用法用于默认值填充,判断是否传参或该值是否存在,如果不存在就使用||后买你的值作为默认值 code: code || 0, msg: msg || SUCCESS, data: data || {}, ...others }; 二、trim() 方…...

手写Tomcat:实现基本功能
首先,Tomcat是一个软件,所有的项目都能在Tomcat上加载运行,Tomcat最核心的就是Servlet集合,本身就是HashMap。Tomcat需要支持Servlet,所以有servlet底层的资源:HttpServlet抽象类、HttpRequest和HttpRespon…...

C#变量与变量作用域详解
一、变量基础 1. 声明与初始化 声明语法:<数据类型> <变量名>(如 int age; string name)初始化要求: 1、 类或结构体中的字段变量(全局变量)无需显式初始化,默认值…...

SV学习笔记——数组、队列
一、定宽数组 定宽数组是静态变量,编译时便已经确定其大小,其可以分为压缩定宽数组和非压缩定宽数组:压缩数组是定义在类型后面,名字前面;非压缩数组定义在名字后面。Bit [7:0][3:0] name; bit[7:0] name [3:0]; 1.1定宽数组声明 数组的声…...

API调试工具的无解困境:白名单、动态IP与平台设计问题
引言 你是否曾经在开发中遇到过这样的尴尬情形:你打开了平台的API调试工具,准备一番操作,结果却发现根本无法连接到平台?别急,问题出在调试工具本身。今天我们要吐槽的就是那些神奇的开放平台API调试工具,…...

Git清理本地残留的、但已经在服务器上被删除的分支
要筛选出已经被服务器删除的本地分支,并在本地删除这些分支,可以按照以下步骤进行操作: 步骤 1: 获取远程分支信息,确保本地的远程分支信息是最新的: git fetch -p步骤 2: 列出本地分支和远程分支: git …...

HTTPS实现内容加密的逻辑
加密过程 使用非对称加密,网站生成公钥和私钥浏览器获取到网站公钥(通过验证和解析CA证书),随即生成一串字符串,然后使用公钥加密,发送给网站。网站用私钥将加密内容解析,然后使用这串字符串对…...

使用vue3.0+electron搭建桌面应用并打包exe
使用vue3.0electron搭建桌面应用并打包exe_如何使用electron将vue3vite开发完的项目打包成exe应用程序-CSDN博客...

JSAR 基础 1.2.1 基础概念_空间小程序
JSAR 基础 1.2.1 基础概念_空间小程序 空间空间自由度可嵌入空间空间小程序 最新的技术进展表明,官网之前的文档准备废除了,基于xsml的开发将退出历史舞台,three.js和普通web结合的技术将成为主导。所以后续学习请移步three.js学习路径&#…...