Metalint 0.2 - README.TXT
=========================
Metalint is a utility that checks Lua and Metalua source files for global
variables usage. Beyond checking toplevel global variables, it also checks
fields in modules: for instance, it will catch typos such as taable.insert(),
both also table.iinsert().
Metalint works with declaration files, which list which globals are declared,
and what can be done with them. The syntax is:
DECL ::= (DECL_ELEM ";"?) *
DECL_ELEM ::= NAME | "module" NAME DECL "end" | "free" NAME | "private" DECL_ELEM
NAME ::= <identifier> | <string>
Identifiers and strings are the same as in Lua, except that the only reserved
keywords are "free", "module", "end" and "private". A variable name can be
equivalently specified as a string or as an identifier. Lua comments are allowed
in declaration files, short and long. Check for *.dlua files in the distribution
for examples.
Meaning of declaration elements:
- Standalone names declare the existence of a variable. This variable is not a
module, i.e. people must not extract fields from it. For instance, the
function ipairs() will simply be declared as: "ipairs". With this declaration,
it's an error to write, for instance, "ipairs.some_field".
- Names preceded with "free" can be used as you want, including arbitrary
sub-indexing. This is useful for global tables not used as modules, and for
modules you're too lazy to fully declare. For instance, the declaration "free
_G" allows you to bypass all checkings, as long as you access stuff through _G
rather than directly (i.e. "table.iinsert" will fail, but "_G.table.iinsert"
will be accepted).
- modules contain field declarations. For instance, the contents of the standard
"os" module will be declared as "module os exit ; setlocale; date; [...]
execute end".
Declaration files are loaded:
- manually, by passing "-f filename", "-l libname" or "-e
decl_literal_expression" as options to the checking program. Options are
processed in order, i.e. if you load a library after a file name to check,
this library won't be accessible while checking the dource file.
- automatically, when a call to "require()" is found in the code.
- declaration library "base" is automatically loaded.
Declaration library files are retrieved with the same algorithm as for Lua
libraries, except that the pattern string is taken from environment variable
LUA_DPATH rather than LUA_PATH or LUA_CPATH. For instance, if
LUA_DPATH="./?.dlua" and a "require 'walk.id'" is found, the checker will
attempt to load "./walk/id.dlua". It won't fail if it can't find it, but then,
attempts to use globals declared by walk.id are likely to fail.
The metalua base libraries, which include Lua base libraries, can be found in
base.dlua. They're automatically loaded when you run metalint.
Limitations: if you try to affect custom names to modules, e.g. "local
wi=require 'walk.id'", the checker won't be able to check your usage of
subfields of "wi". Similarly, if you redefine require() or module(), or create
custom versions of these, metalint will be lost. Finally, computed access to
modules are obviously not checked, i.e. "local x, y = 'iinsert', { };
table[x](y, 1)" will be accepted.
Future: Metalint is intended to support richer static type checkings, including
function argument types. The idea is not to formally prove type soundness, but
to accelerate the discovery of many silly bugs when using a (possibly third
party) library. However, to perform interesting checks, the type declaration
system must support a couple of non-trivial stuff like union types and higher
order functions. Moreover, runtime checking code could optionally be inserted to
check that a function API is respected when it's called (check the types
extension in Metalua). Stay tuned.
Notice that metalint can easily be turned into a smarter variable localizer,
which would change references to module elements into local variables.
For instance, it would add "local _table_insert = table.insert" at the beginning
of the file, and change every instance of "table.insert" into a reference to the
local variable. This would be much more efficient than simply adding a "local
table=table".
Finally, to accelerate the migration of existing codebases, a decl_dump()
function is provided with metalint, which attempts to generate a declaration for
a module currently loaded in RAM. The result is not always perfect, but remains
a serious time saver:
~/src/metalua/src/sandbox$ metalua
Metalua, interactive REPLoop.
(c) 2006-2008 <metalua@gmail.com>
M> require "metalint"
M> require "walk"
M> decl_dump ("walk", "decl/walk.dlua")
M> ^D
~/src/metalua/src/sandbox$ cat decl/walk.dlua
module walk
debug;
module tags
module stat
Forin;
Do;
Set;
Fornum;
Invoke;
While;
Break;
Call;
Label;
Goto;
Local;
If;
Repeat;
Localrec;
Return;
end;
module expr
True;
String;
Index;
Paren;
Id;
False;
Invoke;
Function;
Op;
Number;
Table;
Dots;
Nil;
Stat;
Call;
end;
end;
expr_list;
binder_list;
guess;
expr;
block;
module traverse
expr;
block;
stat;
expr_list;
end;
stat;
end;
NEW SINCE 0.1:
==============
Feature-wise, option -a replaces all references to declared fields with locals
and stores the compiled result in a .luac compiled file
Architecture-wise, the system now remembers where (i.e. by which require()
statement, if applicable) a given field has been declared. This is necessary for
the autolocal feature to work correctly.
没有合适的资源?快使用搜索试试~ 我知道了~
Lua实例代码大全
共650个文件
lua:308个
wlua:132个
json:45个
4星 · 超过85%的资源 需积分: 45 166 下载量 17 浏览量
2013-07-15
11:27:17
上传
评论 4
收藏 1.27MB ZIP 举报
温馨提示
很全面的实例代码,luacurl网络连接、luafilesystem、luajson、luasocket、luasql、luatask、luaxml、md5
资源推荐
资源详情
资源评论
收起资源包目录
Lua实例代码大全 (650个子文件)
horse3.ani 17KB
horse.bmp 59KB
alientest.c 7KB
ftest.c 4KB
fdemo.c 4KB
dlldatax.c 1KB
run.c 954B
dlldata.c 809B
Test.cls 2KB
Test.cpp 7KB
main.cpp 4KB
main.cpp 3KB
TestSafeArray.cpp 3KB
hello.cpp 1KB
oilaccess.cpp 643B
StdAfx.cpp 306B
hello.cpp 247B
TextBox.cs 934B
horse.cur 326B
TestSafeArray.def 225B
PruebaSafeArrayVB.dll 24KB
alientest.dll 10KB
TextBox.dll 4KB
compiler.dlua 6KB
base.dlua 2KB
metalint.dlua 209B
id.dlua 56B
walk.dlua 53B
clopts.dlua 12B
TestSafeArray.dsp 13KB
TestSafeArray.dsw 606B
execute 878B
execute 736B
execute 683B
execute 593B
execute 487B
execute 424B
execute 333B
execute 327B
execute 317B
execute 305B
execute 282B
execute 282B
execute 266B
execute 266B
execute 264B
execute 264B
execute 69B
alientest.exp 6KB
b2.ext2 203B
a3.ext3 299B
Form1.frm 4KB
form.frm 780B
horse.gif 45KB
testdir.tar.gz 347B
TestSafeArray.h 8KB
StdAfx.h 938B
Test.h 736B
dlldatax.h 729B
resource.h 489B
oilaccess.hpp 7KB
hello.hpp 944B
hello.hpp 411B
horse.ico 1KB
msppt9.IDL 272KB
dragon.idl 86KB
MSWINSCK.IDL 9KB
CosNaming.idl 2KB
CosEvent.idl 2KB
TestSafeArray.idl 1006B
philo.idl 731B
control.idl 217B
hello.idl 117B
hello.idl 117B
cmyk.jpg 22KB
flower.jpg 17KB
bugs.jpg 12KB
lena.jpg 7KB
horse.jpg 6KB
pass1.json 1KB
pass3.json 148B
mustBeArrayOrObject.json 60B
extraValueAfterClose.json 58B
deepArray.json 52B
simpleArrayInObject.json 50B
extremeNesting.json 50B
octalNumber.json 43B
tabInString-escaped.json 38B
unquotedKey.json 37B
tabInString.json 36B
octalEscape.json 34B
hexEscape.json 34B
colonInArray.json 33B
whitespace_before_object.json 33B
missingColon2.json 32B
singleQuoteEscape.json 32B
functionExpression.json 31B
hexNumber.json 31B
mathExpression.json 29B
commaAfterValue.json 26B
共 650 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
- loseh2018-11-08一般吧 就是源码里的一些实例
- u0100413852018-10-09很不错的源码,谢谢分享。
- loveingeding2222019-06-15有一部分代码还是挺好用的,有一定的借鉴意义。
- guojie8407032018-08-02比较基础的。
- boboaixiazai2015-01-05还行吧.最近要做一个LUA的在线开发平台,这些东西还是有用的
cfeng12
- 粉丝: 7
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功