mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 08:39:30 +00:00
Move anselme code into its own directory
This commit is contained in:
parent
404e7dd56e
commit
5dd971ff8f
179 changed files with 603 additions and 579 deletions
57
doc/api.md
57
doc/api.md
|
|
@ -45,35 +45,42 @@ while run_state:active() do
|
|||
end
|
||||
```
|
||||
|
||||
If `require("anselme")` fails with an error similar to `module 'anselme' not found`, you might need to redefine `package.path` before the require:
|
||||
```lua
|
||||
package.path = "path/?/init.lua;path/?.lua;" .. package.path -- where path is the directory where anselme is located
|
||||
require("anselme")
|
||||
```
|
||||
Anselme expects that `require("anselme.module")` will try loading both `anselme/module/init.lua` and `anselme/module.lua`, which may not be the case without the above code as `package.path`'s default value is system dependent, i.e. not my problem.
|
||||
|
||||
### .version
|
||||
|
||||
Global version string. Follow semver.
|
||||
|
||||
_defined at line 57 of [anselme.lua](../anselme.lua):_ `version = "2.0.0-alpha",`
|
||||
_defined at line 57 of [anselme/init.lua](../anselme/init.lua):_ `version = "2.0.0-alpha",`
|
||||
|
||||
### .versions
|
||||
|
||||
Table containing per-category version numbers. Incremented by one for any change that may break compatibility.
|
||||
|
||||
_defined at line 60 of [anselme.lua](../anselme.lua):_ `versions = {`
|
||||
_defined at line 60 of [anselme/init.lua](../anselme/init.lua):_ `versions = {`
|
||||
|
||||
#### .language
|
||||
|
||||
Version number for languages and standard library changes.
|
||||
|
||||
_defined at line 62 of [anselme.lua](../anselme.lua):_ `language = 27,`
|
||||
_defined at line 62 of [anselme/init.lua](../anselme/init.lua):_ `language = 27,`
|
||||
|
||||
#### .save
|
||||
|
||||
Version number for save/AST format changes.
|
||||
|
||||
_defined at line 64 of [anselme.lua](../anselme.lua):_ `save = 4,`
|
||||
_defined at line 64 of [anselme/init.lua](../anselme/init.lua):_ `save = 4,`
|
||||
|
||||
#### .api
|
||||
|
||||
Version number for Lua API changes.
|
||||
|
||||
_defined at line 66 of [anselme.lua](../anselme.lua):_ `api = 8`
|
||||
_defined at line 66 of [anselme/init.lua](../anselme/init.lua):_ `api = 8`
|
||||
|
||||
### .parse (code, source)
|
||||
|
||||
|
|
@ -87,17 +94,17 @@ local ast = anselme.parse("1 + 2", "test")
|
|||
ast:eval()
|
||||
```
|
||||
|
||||
_defined at line 78 of [anselme.lua](../anselme.lua):_ `parse = function(code, source)`
|
||||
_defined at line 78 of [anselme/init.lua](../anselme/init.lua):_ `parse = function(code, source)`
|
||||
|
||||
### .new ()
|
||||
|
||||
Return a new [State](#state).
|
||||
|
||||
_defined at line 82 of [anselme.lua](../anselme.lua):_ `new = function()`
|
||||
_defined at line 82 of [anselme/init.lua](../anselme/init.lua):_ `new = function()`
|
||||
|
||||
|
||||
---
|
||||
_file generated at 2023-12-28T16:41:42Z_
|
||||
_file generated at 2023-12-29T17:36:31Z_
|
||||
|
||||
# State
|
||||
|
||||
|
|
@ -109,7 +116,7 @@ Each State can run a single script at a time, and variable changes are isolated
|
|||
Load standard library.
|
||||
You will probably want to call this on every State right after creation.
|
||||
|
||||
_defined at line 41 of [state/State.lua](../state/State.lua):_ `load_stdlib = function(self)`
|
||||
_defined at line 50 of [anselme/state/State.lua](../anselme/state/State.lua):_ `load_stdlib = function(self)`
|
||||
|
||||
## Branching and merging
|
||||
|
||||
|
|
@ -117,13 +124,13 @@ _defined at line 41 of [state/State.lua](../state/State.lua):_ `load_stdlib = fu
|
|||
|
||||
Name of the branch associated to this State.
|
||||
|
||||
_defined at line 48 of [state/State.lua](../state/State.lua):_ `branch_id = "main",`
|
||||
_defined at line 57 of [anselme/state/State.lua](../anselme/state/State.lua):_ `branch_id = "main",`
|
||||
|
||||
### .source_branch_id
|
||||
|
||||
Name of the branch this State was branched from.
|
||||
|
||||
_defined at line 50 of [state/State.lua](../state/State.lua):_ `source_branch_id = "main",`
|
||||
_defined at line 59 of [anselme/state/State.lua](../anselme/state/State.lua):_ `source_branch_id = "main",`
|
||||
|
||||
### :branch ()
|
||||
|
||||
|
|
@ -132,7 +139,7 @@ Return a new branch of this State.
|
|||
Branches act as indepent copies of this State where any change will not be reflected in the source State until it is merged back into the source branch.
|
||||
Note: probably makes the most sense to create branches from the main State only.
|
||||
|
||||
_defined at line 56 of [state/State.lua](../state/State.lua):_ `branch = function(self)`
|
||||
_defined at line 65 of [anselme/state/State.lua](../anselme/state/State.lua):_ `branch = function(self)`
|
||||
|
||||
### :merge ()
|
||||
|
||||
|
|
@ -142,7 +149,7 @@ Recommendation: only merge if you know that the state of the variables is consis
|
|||
If your script errored or was interrupted at an unknown point in the script, you might be in the middle of a calculation and variables won't contain
|
||||
values you want to merge.
|
||||
|
||||
_defined at line 65 of [state/State.lua](../state/State.lua):_ `merge = function(self)`
|
||||
_defined at line 74 of [anselme/state/State.lua](../anselme/state/State.lua):_ `merge = function(self)`
|
||||
|
||||
## Variable definition
|
||||
|
||||
|
|
@ -159,13 +166,13 @@ Define a value in the global scope, converting it from Lua to Anselme if needed.
|
|||
If `raw_mode` is true, no anselme-to/from-lua conversion will be performed in the function.
|
||||
The function will receive the state followed by AST nodes as arguments, and is expected to return an AST node.
|
||||
|
||||
_defined at line 83 of [state/State.lua](../state/State.lua):_ `define = function(self, name, value, func, raw_mode)`
|
||||
_defined at line 92 of [anselme/state/State.lua](../anselme/state/State.lua):_ `define = function(self, name, value, func, raw_mode)`
|
||||
|
||||
### :define_local (name, value, func, raw_mode)
|
||||
|
||||
Same as `:define`, but define the expression in the current scope.
|
||||
|
||||
_defined at line 89 of [state/State.lua](../state/State.lua):_ `define_local = function(self, name, value, func, raw_mode)`
|
||||
_defined at line 98 of [anselme/state/State.lua](../anselme/state/State.lua):_ `define_local = function(self, name, value, func, raw_mode)`
|
||||
|
||||
For anything more advanced, you can directly access the current scope stack stored in `state.scope`.
|
||||
See [state/ScopeStack.lua](../state/ScopeStack.lua) for details; the documentation is not as polished as this file but you should still be able to find your way around.
|
||||
|
|
@ -178,7 +185,7 @@ Return a serialized (string) representation of all persistent variables in this
|
|||
|
||||
This can be loaded back later using `:load`.
|
||||
|
||||
_defined at line 101 of [state/State.lua](../state/State.lua):_ `save = function(self)`
|
||||
_defined at line 110 of [anselme/state/State.lua](../anselme/state/State.lua):_ `save = function(self)`
|
||||
|
||||
### :load (save)
|
||||
|
||||
|
|
@ -186,7 +193,7 @@ Load a string generated by `:save`.
|
|||
|
||||
Variables that already exist will be overwritten with the loaded data.
|
||||
|
||||
_defined at line 108 of [state/State.lua](../state/State.lua):_ `load = function(self, save)`
|
||||
_defined at line 117 of [anselme/state/State.lua](../anselme/state/State.lua):_ `load = function(self, save)`
|
||||
|
||||
## Current script state
|
||||
|
||||
|
|
@ -194,7 +201,7 @@ _defined at line 108 of [state/State.lua](../state/State.lua):_ `load = function
|
|||
|
||||
Indicate if a script is currently loaded in this branch.
|
||||
|
||||
_defined at line 122 of [state/State.lua](../state/State.lua):_ `active = function(self)`
|
||||
_defined at line 131 of [anselme/state/State.lua](../anselme/state/State.lua):_ `active = function(self)`
|
||||
|
||||
### :state ()
|
||||
|
||||
|
|
@ -204,7 +211,7 @@ Returns `"active"` if a script is loaded but not currently running (i.e. the scr
|
|||
|
||||
Returns `"inactive"` if no script is loaded.
|
||||
|
||||
_defined at line 130 of [state/State.lua](../state/State.lua):_ `state = function(self)`
|
||||
_defined at line 139 of [anselme/state/State.lua](../anselme/state/State.lua):_ `state = function(self)`
|
||||
|
||||
### :run (code, source)
|
||||
|
||||
|
|
@ -214,7 +221,7 @@ Load a script in this branch. It will become the active script.
|
|||
|
||||
Note that this will only load the script; execution will only start by using the `:step` method. Will error if a script is already active in this State.
|
||||
|
||||
_defined at line 142 of [state/State.lua](../state/State.lua):_ `run = function(self, code, source)`
|
||||
_defined at line 151 of [anselme/state/State.lua](../anselme/state/State.lua):_ `run = function(self, code, source)`
|
||||
|
||||
### :step ()
|
||||
|
||||
|
|
@ -224,7 +231,7 @@ Will error if no script is active.
|
|||
|
||||
Returns `event type string, event data`.
|
||||
|
||||
_defined at line 155 of [state/State.lua](../state/State.lua):_ `step = function(self)`
|
||||
_defined at line 164 of [anselme/state/State.lua](../anselme/state/State.lua):_ `step = function(self)`
|
||||
|
||||
### :interrupt (code, source)
|
||||
|
||||
|
|
@ -235,7 +242,7 @@ Will error if no script is active.
|
|||
If `code` is given, the script will not be disabled but instead will be immediately replaced with this new script.
|
||||
The new script will then be started on the next `:step` and will preserve the current scope. This can be used to trigger an exit function or similar in the active script.
|
||||
|
||||
_defined at line 173 of [state/State.lua](../state/State.lua):_ `interrupt = function(self, code, source)`
|
||||
_defined at line 182 of [anselme/state/State.lua](../anselme/state/State.lua):_ `interrupt = function(self, code, source)`
|
||||
|
||||
### :eval (code, source)
|
||||
|
||||
|
|
@ -246,13 +253,13 @@ This can be called from outside a running script, but an error will be triggered
|
|||
* returns AST in case of success. Run `:to_lua(state)` on it to convert to a Lua value.
|
||||
* returns `nil, error message` in case of error.
|
||||
|
||||
_defined at line 194 of [state/State.lua](../state/State.lua):_ `eval = function(self, code, source)`
|
||||
_defined at line 203 of [anselme/state/State.lua](../anselme/state/State.lua):_ `eval = function(self, code, source)`
|
||||
|
||||
### :eval_local (code, source)
|
||||
|
||||
Same as `:eval`, but evaluate the expression in the current scope.
|
||||
|
||||
_defined at line 201 of [state/State.lua](../state/State.lua):_ `eval_local = function(self, code, source)`
|
||||
_defined at line 210 of [anselme/state/State.lua](../anselme/state/State.lua):_ `eval_local = function(self, code, source)`
|
||||
|
||||
If you want to perform more advanced manipulation of the resulting AST nodes, look at the `ast` modules.
|
||||
In particular, every Node inherits the methods from [ast.abstract.Node](../ast/abstract/Node.lua).
|
||||
|
|
@ -260,4 +267,4 @@ Otherwise, each Node has its own module file defined in the [ast/](../ast) direc
|
|||
|
||||
|
||||
---
|
||||
_file generated at 2023-12-28T16:41:42Z_
|
||||
_file generated at 2023-12-29T17:36:31Z_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue