diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-12-13 16:10:08 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-12-13 16:10:08 +1100 |
| commit | 64b106c13e18c33be0f2b0de532054e0ed3f731d (patch) | |
| tree | b54b1c90d941bc456b4d51e864970720bdf2d648 /lib/lua-linenoise/example.lua | |
| parent | 5a2f0b08e0e3f20cda977b510b680d5843ae7283 (diff) | |
| download | tangara-fw-64b106c13e18c33be0f2b0de532054e0ed3f731d.tar.gz | |
add a cool lua repl
Diffstat (limited to 'lib/lua-linenoise/example.lua')
| -rw-r--r-- | lib/lua-linenoise/example.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/lua-linenoise/example.lua b/lib/lua-linenoise/example.lua new file mode 100644 index 00000000..8b8ba173 --- /dev/null +++ b/lib/lua-linenoise/example.lua @@ -0,0 +1,32 @@ +local L = require 'linenoise' +-- L.clearscreen() +print '----- Testing lua-linenoise! ------' +local prompt, history = '? ', 'history.txt' +L.historyload(history) -- load existing history +L.setcompletion(function(c,s) + if s == 'h' then + c:add('help') -- same as L.addcompletion(c,'help) + L.addcompletion(c,'halt') -- same as c:add('halt') + end +end) +L.sethints(function(s) + if s == 'h' then + return ' test hint' + end +end) + +L.enableutf8() + +local line, err = L.linenoise(prompt) +while line do + if #line > 0 then + print(line:upper()) + L.historyadd(line) + L.historysave(history) -- save every new line + end + line, err = L.linenoise(prompt) +end + +if err then + print('An error occurred: ' .. err) +end |
