这是一个Lua习语和技巧的集合,对于随意阅读代码的人来说,可能不会立即看到。
逻辑 | |
---|---|
not a == not b |
两者都满足或都不满足 |
数字 | |
math.min(math.max(x, min), max) |
把x限制在[min, max]区间内 |
x ~= x |
一个数是NaN |
这是一个Lua习语和技巧的集合,对于随意阅读代码的人来说,可能不会立即看到。
逻辑 | |
---|---|
not a == not b |
两者都满足或都不满足 |
数字 | |
math.min(math.max(x, min), max) |
把x限制在[min, max]区间内 |
x ~= x |
一个数是NaN |
if/else
或 and/or
来限定循环内核。...
和 select()
与非常量索引一起使用),因此使用复合函数函数限定循环内核是可行的。if/else
语句和使用and/or
表达式没有区别——它们会产生相同的破坏管道的分支代码(所以要避免在紧密循环中使用非常数and/or
运算符的表达式)。x / c
转换为 x * (1 / c)
——LuaJIT已经为2的幂常量做了这件事,其语义是等价的。local punct_space = lexer.punct + lexer.space | |
-- Handles flanking delimiters as described in | |
-- https://github.github.com/gfm/#emphasis-and-strong-emphasis in the cases | |
-- where simple delimited ranges are not sufficient. | |
local function flanked_range(s, not_inword) | |
local fl_char = lexer.any - s - lexer.space | |
local left_fl = lpeg.B(punct_space - s) * s * #fl_char + | |
s * #(fl_char - lexer.punct) | |
local right_fl = lpeg.B(lexer.punct) * s * #(punct_space - s) + |
require('zip') | |
require('xml_parse') | |
local excel = zip_open('excel/test.xlsx') | |
if not excel then return end | |
local flag | |
flag = excel:find('xl/workbook.xml') | |
if flag then | |
local str = excel:read('*a') |