1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
--[[ General info:
This file contains the main entry point for sued's Lua bindings. Visit
/src/lua.rs for the Rust code that imports this file.
This file is part of sued.
sued is free software licensed under the Apache License, Version 2.0.
]]
--[[ This file:
This file will be pulled into the Rust side of sued using `include_str!`,
so it'll be compiled into a string literal.
This means you SHOULD NOT require or dofile other Lua files in this file
unless you're including those Lua files alongside the sued executable, which
is almost certainly not what you want to deal with.
Use sued's `~script` command if you want to run Lua scripts from inside the
editor.
--]]
--[[ Globals:
sued exposes two globals, `sued_buffer` and `sued_file_path`.
- `sued_buffer: table<string>`, linked to `state.buffer.contents: Vec<String>`
- `sued_file_path: string`, linked to `state.buffer.file_path: Option<String>`
`sued_buffer` will be synchronised with sued's `state.buffer.contents`,
but `sued_file_path` will not be. This means you can modify `sued_buffer`
from the Lua side, but `sued_file_path` is effectively read-only.
--]]
--[[ Lua environment:
sued's Lua environment is lazy-loaded and will not be made available until
an `~eval` or `~script` command is issued, at which point this file will be
included.
This has no noticable impact on usage, but it's good to be informed.
--]]
--[[ The `print_buffer` function:
This function serves as a test function for sued's Lua bindings.
It simply prints the current contents of `sued_buffer`, which is practically
the same as the current buffer in sued itself.
This function prints a line for every line in the buffer, with line numbers,
featuring the same separation character (`│`) as sued's `~show` and `~point`
commands use.
To run this in sued, run `~eval print_buffer()`.
--]]
--[[ The `count_lines` function:
This function counts the number of lines in a file.
To run this in sued, run `~eval count_lines("<filename>")`.
To count the lines of the file opened in sued, run `~eval count_lines(sued_file_path)`.
]]
--[[ The `startup` function:
This will be run as soon as this file is loaded into sued's Lua environment.
You can think of it as the `main` entry point for the bindings.
--]]
startup