[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [ANN] safer - Paranoid Lua programming
- From: Hisham <h@...>
- Date: Wed, 23 Mar 2016 14:55:15 -0300
Hi,
Announcing yet another "strict-mode" style module: "safer".
* http://github.com/hishamhm/safer
Install with
luarocks install safer
# Safer - Paranoid Lua programming
Taking defensive programming to the next level. Use this module
to avoid unexpected globals creeping up in your code, and stopping
sub-modules from fiddling with fields of tables as you pass them
around.
## API
#### `safer.globals([exception_globals], [exception_nils])`
No new globals after this point.
`exception_globals` is an optional set (keys are strings, values are
`true`) specifying names to be exceptionally accepted as new globals.
Use this in case you have to declare a legacy module that declares a
global, for example. A few legacy modules are already handled by
default.
`exception_nils` is an optional set (keys are strings, values are
`true`) specifying names
to be exceptionally accepted to be accessed as nonexisting globals.
Use this in case code does feature-testing based on checking the
presence of globals. A few common feature-test nils such as `jit` and
`unpack` are already handled by default.
#### `t = safer.table(t)`
Block creation of new fields in this table.
#### `t = safer.readonly(t)`
Make table read-only: block creation of new fields in this table
and setting new values to existing fields.
Note that both `safer.table` and `safer.readonly` are implemented
creating a proxy table, so:
* Equality tests will fail: `safer.readonly(t) ~= t`
* If anyone still has a reference to this table prior
to creating the safer version, they can still mess
with the unsafe table and affect the safe one.
About
-----
Licensed under the terms of the MIT License, the same as Lua.
During its genesis, this module was called "safe", but I renamed it
to "safer" to remind us that we are never fully safe. ;)
-- Hisham
http://hisham.hm/ - @hisham_hm