Added validate method, and docs.
This commit is contained in:
parent
e80a7fd61f
commit
17a8ae6988
|
@ -11,10 +11,28 @@ ms.run("2F")
|
||||||
|
|
||||||
Runs the given `script` string as a movescript, and optionally a `settings` table can be provided. Otherwise, [default settings](settings.md) will be used.
|
Runs the given `script` string as a movescript, and optionally a `settings` table can be provided. Otherwise, [default settings](settings.md) will be used.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local ms = require("movescript")
|
||||||
|
ms.run("3F2R3B2LUD", {debug=true})
|
||||||
|
```
|
||||||
|
|
||||||
## `runFile(filename, settings)`
|
## `runFile(filename, settings)`
|
||||||
|
|
||||||
Reads content from the given filename and executes it as a script. Just like with `run`, an optional `settings` table can be provided.
|
Reads content from the given filename and executes it as a script. Just like with `run`, an optional `settings` table can be provided.
|
||||||
|
|
||||||
|
## `validate(script, settings)`
|
||||||
|
|
||||||
|
Validates the given `script`, by parsing its instructions in a wrapped [`pcall`](https://www.lua.org/pil/8.4.html). It returns `true` if the script is valid, or `false` and an error message describing why the script is not valid.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local ms = require("movescript")
|
||||||
|
local status, message = ms.validate("not a valid script.")
|
||||||
|
```
|
||||||
|
|
||||||
## `defaultSettings`
|
## `defaultSettings`
|
||||||
|
|
||||||
A table containing the default settings for any script executed by the movescript module.
|
A table containing the default [settings](./settings.md) for any script executed by the movescript module.
|
|
@ -207,4 +207,8 @@ function movescript.runFile(filename, settings)
|
||||||
movescript.run(script, settings)
|
movescript.run(script, settings)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function movescript.validate(script, settings)
|
||||||
|
return pcall(function () parseScript(script, settings) end)
|
||||||
|
end
|
||||||
|
|
||||||
return movescript
|
return movescript
|
||||||
|
|
Loading…
Reference in New Issue