mirror of
https://github.com/TangentFoxy/lua-sandbox.git
synced 2025-07-29 19:42:21 +00:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
1660780960 | |||
e0710a284d | |||
|
e04ddbe3ae | ||
|
0108834dd3 | ||
|
ee3285e2fd | ||
|
07a01090e7 | ||
|
35714d7a92 |
23
README.md
23
README.md
@@ -140,24 +140,29 @@ If you want to turn off the quota completely, pass `quota=false` instead.
|
|||||||
|
|
||||||
Use the `env` option to inject additional variables to the environment in which the sandboxed code is executed.
|
Use the `env` option to inject additional variables to the environment in which the sandboxed code is executed.
|
||||||
|
|
||||||
local msg = sandbox.run('return foo', {env = {foo = 'This is a global var on the the environment'}})
|
```lua
|
||||||
|
local msg = sandbox.run('return foo', {env = {foo = 'This is a global var on the the environment'}})
|
||||||
|
```
|
||||||
|
|
||||||
The `env` variable will be used as an "index" by the sandbox environment, but it will *not* be modified at all (changes
|
The `env` variable will be used as an "index" by the sandbox environment, but it will *not* be modified at all (changes
|
||||||
to the environment are thus lost). The only way to "get information out" from the sandboxed environments are:
|
to the environment are thus lost). The only way to "get information out" from the sandboxed environments are:
|
||||||
|
|
||||||
Through side effects, like writing to a database. You will have to provide the side-effects functions in `env`:
|
Through side effects, like writing to a database. You will have to provide the side-effects functions in `env`:
|
||||||
|
|
||||||
local val = 1
|
```lua
|
||||||
local env = { write_db = function(new_val) val = new_val end }
|
local val = 1
|
||||||
sandbox.run('write_db(2)')
|
local env = { write_db = function(new_val) val = new_val end }
|
||||||
assert(val = 2)
|
sandbox.run('write_db(2)', { env = env })
|
||||||
|
assert(val = 2)
|
||||||
|
```
|
||||||
|
|
||||||
Through returned values:
|
Through returned values:
|
||||||
|
|
||||||
local env = { amount = 1 }
|
```lua
|
||||||
local result = sandbox.run('return amount + 1', { env = env })
|
local env = { amount = 1 }
|
||||||
assert(result = 2)
|
local result = sandbox.run('return amount + 1', { env = env })
|
||||||
|
assert(result = 2)
|
||||||
|
```
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
============
|
============
|
||||||
|
@@ -1,15 +1,15 @@
|
|||||||
package = "sandbox"
|
package = "sandbox"
|
||||||
|
|
||||||
version = "1.0.0-0"
|
version = "1.0.1-4"
|
||||||
|
|
||||||
source = {
|
source = {
|
||||||
url = "git://github.com/kikito/sandbox.lua.git",
|
url = "git+https://github.com/kikito/lua-sandbox",
|
||||||
tag = "v1.0.0"
|
tag = "v1.0.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
description = {
|
description = {
|
||||||
summary = "A pure-lua solution for running untrusted Lua code.",
|
summary = "A pure-lua solution for running untrusted Lua code.",
|
||||||
homepage = "https://github.com/kikito/sandbox.lua",
|
homepage = "https://github.com/kikito/lua-sandbox",
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies = {
|
dependencies = {
|
Reference in New Issue
Block a user