Lua 5.1中如何读取直到给定的字符?
在lua 2.4之前,曾经有一个readuntil
函数可以读取直到第一次出现指定字符;在 2.5 中,此功能被删除,您必须将适当的模式传递给 file:read
;在 5.1 中,read
的可用格式化选项似乎进一步减少,并且 2.5 版本中有效的模式不再可用。
如何从输入流中读取数据,直到第一次出现给定字符(例如 TAB)?尝试编写带有制表符补全功能的增强型 REPL。
Up to lua 2.4, there used to be an readuntil
function that can read until the first occurence of a specified character; in 2.5 this is removed and you have to pass an appropriate pattern to file:read
instead; and in 5.1 it seems that the available formatting option for read
has been further reduced, and the patterns valid in version 2.5 are no longer available.
How do I read from an input stream until the first occurence of a given character, say TAB? Trying to write an enhanced REPL with tab-completion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于制表符完成,您需要以原始模式读取输入,即无需等待换行符。这在 ANSI C 中无法完成。
例如,尝试使用curses 绑定: https://github.com/rrthomas/luaposix< /a>.
For tab-completion you need to read input in raw mode, that is, without waiting for a newline. This cannot be done in ANSI C.
Try a curses binding for instance: https://github.com/rrthomas/luaposix.