lua第三方库

文章目录

luarocks

luarocks是一个用lua写的包管理工具,类似Mac的终端工具brew,Ubuntu的apt。可以通过luarocks config来查看当前的配置,可以通过Options中的选项修改配置,使用就看Commands

安装

$ wget https://luarocks.org/releases/luarocks-3.5.0.tar.gz
$ tar zxpf luarocks-3.5.0.tar.gz
$ cd luarocks-3.5.0
$ ./configure && make && sudo make install

使用例子

库的安装位置可以通过luarocks config来查看deploy_bin_dir、deploy_lib_dir、deploy_lua_dir。

安装第三方库penlight、luafilesystem
$ luarocks intall luafilesystem
$ luarocks intall penlight
显示已经安装的库
$ luarocks list
显示配置
$ luarocks config

luafilesystem

LuaFileSystem是一个Lua库,用于补充文件系统相关的功能集。它是用C来编写的,所以提供的是一个动态库。文件在这里,可以通过luarocks安装:luarocks install luafilesystem

函数 说明
attributes 获取文件属性
chdir 将当前工作目录更改为给定路径
lock_dir 创建一个文件锁,如果文件不存在则返回该文件,如果已经存在检查该文件的状态,使用lock:free()去释放该文件锁
currentdir 返回当前目录
lock 锁住一个文件,就是打开它
unlock 取消锁,就是关闭它
link 创建一个硬链接
mkdir 创建一个新目录
rmdir 删除一个已经存在的目录
setmode 设置文件模式
touch 创建一个文件

penlight

penlight是一个强大的工具库,它依赖luafilesystem,penlight的API文档在这里。可以通过luarocks安装:luarocks install penlight

模块 说明
pl Entry point for loading all PL libraries only on demand, into the global space.
pl.Set A Set class.
pl.app Application support functions.
pl.array2d Operations on two-dimensional arrays.
pl.class Provides a reuseable and convenient framework for creating classes in Lua.
pl.compat Lua 5.1/5.2/5.3 compatibility.
pl.comprehension List comprehensions implemented in Lua.
pl.config Reads configuration files into a Lua table.
pl.data Reading and querying simple tabular data.
pl.dir Listing files in directories and creating/removing directory paths.
pl.file File manipulation functions: reading, writing, moving and copying.
pl.func Functional helpers like composition, binding and placeholder expressions.
pl.import_into PL loader, for loading all PL libraries, only on demand.
pl.input Iterators for extracting words or numbers from an input source.
pl.lapp Simple command-line parsing using human-readable specification.
pl.lexer Lexical scanner for creating a sequence of tokens from text.
pl.luabalanced Extract delimited Lua sequences from strings.
pl.operator Lua operators available as functions.
pl.path Path manipulation and file queries.
pl.permute Permutation operations.
pl.pretty Pretty-printing Lua tables.
pl.seq Manipulating iterators as sequences.
pl.sip Simple Input Patterns (SIP).
pl.strict Checks uses of undeclared global variables.
pl.stringio Reading and writing strings using file-like objects.
pl.stringx Python-style extended string library.
pl.tablex Extended operations on Lua tables.
pl.template A template preprocessor.
pl.test Useful test utilities.
pl.text Text processing utilities.
pl.types Dealing with Detailed Type Information
pl.url Python-style URL quoting library.
pl.utils Generally useful routines.
pl.xml XML LOM Utilities.

ldoc

ldoc是一个用lua编写的lua的文档生成器,ldoc依赖penlightpenlight的文档是用ldoc生成的。可以通过luarocks安装:luarocks install ldoc

使用

例子来自LDoc/tests/md-test,配置文件config.ld如下:

project = 'md-test'
title = 'Markdown Docs'
format = 'markdown'
file = 'mod2.lua'

命令行生成一个文档:ldoc -c config.ld .,默认会在当前目录下生成一个doc文件夹,生成文件会放在doc文件中。我们也可以使用纯命令的形式:ldoc --project "md-test" --title 'Markdown Docs' format 'markdown' --file mod2.lua

规则

多看几个例子就大概能知道它的规则了,例子在这里,我们来看md-test中的这个例子,lua文件如下:

---------------------
-- Another test module.
-- This one uses _Markdown_ formating, and
-- so can include goodies such as `code`
-- and lists:
--
--  - one
--  - two
--  - three
--
-- @module mod2

--- really basic function. Can contain links such as
-- [this](http://lua-users.org/wiki/FindPage)
-- @bool first dd
-- @string second **bold** maybe? It can continue:
--
--  - another point
--  - finish the damn list
-- @param third as before
-- @return err msg_err
-- @usage
-- basic(x1,x2,x3)
function mod2.basic(first,second,third)
end
  • 注释是以---开头,下面的注释你换行生成的文档就换行,支持markdown语法。
  • 函数之间要有空行
  • 支持的参数类型有:bool,number,string,table,function,param,tparam,thread
  • 支持的标签有:return,usage,see,return,

生成的文档如下:
lua第三方库

上一篇:【luogu P7470】岛屿探险


下一篇:车载雷达板卡学习资料第520篇:基于ZU15EG和四路AWR1243的车载雷达板卡