https://github.com/hishamhm/safer
Paranoid Lua programming
https://github.com/hishamhm/safer
Last synced: 2 months ago
JSON representation
Paranoid Lua programming
- Host: GitHub
- URL: https://github.com/hishamhm/safer
- Owner: hishamhm
- License: mit
- Created: 2016-03-21T21:07:00.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-03-04T14:44:46.000Z (almost 2 years ago)
- Last Synced: 2025-02-02T08:42:05.224Z (11 months ago)
- Language: Lua
- Size: 3.91 KB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome-lua - Safer - Paranoid Lua programming (Resources / Programming Paradigms)
README
# 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.
Note that this is implemented creating a proxy table, so:
* Equality tests will fail: `safer.table(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.
#### `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 this is 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
-----
This module was created by [Hisham Muhammad](http://hisham.hm/) - [@hisham_hm](http://twitter.com/hisham_hm)
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. ;)