Explorar o código

update: 完善repl库的说明文档

Wendal Chen %!s(int64=2) %!d(string=hai) anos
pai
achega
d1c1d915f6
Modificáronse 2 ficheiros con 50 adicións e 1 borrados
  1. 35 1
      components/repl/luat_lib_repl.c
  2. 15 0
      demo/repl/main.lua

+ 35 - 1
components/repl/luat_lib_repl.c

@@ -1,9 +1,43 @@
 
 /*
-@module  repl
+@module   
 @summary "读取-求值-输出" 循环
 @date    2023.06.16
 @tag LUAT_USE_REPL
+@usage
+--[[
+本功能支持的模块及对应的端口
+模块/芯片        端口     波特率及其他参数
+Air101/Air103    UART0   921600  8 None 1
+Air105           UART0   1500000 8 None 1
+ESP32C3          UART0   921600  8 None 1 -- 注意, 简约版(无CH343)不支持
+ESP32C2          UART0   921600  8 None 1
+ESP32S2          UART0   921600  8 None 1
+Air780E          虚拟串口 任意             -- 暂不支持从物理UART调用
+
+使用方法:
+1. 非Air780E系列可以使用任意串口工具, 打开对应的串口, 记得勾选"回车换行"
+2. Air780E请配合LuaTools使用, 菜单里有 "简易串口工具" 可发送, 记得勾选"回车换行"
+2. 发送lua语句, 并以回车换行结束
+
+语句支持情况:
+1. 单行lua语句, 以回车换行结束即可
+2. 多行语句, 用以下格式包裹起来发送, 例如
+
+<<EOF
+for k,v in pairs(_G) do
+  print(k, v)
+end
+EOF
+
+注意事项:
+1. 可通过repl.enable(false)语句禁用REPL
+2. 使用uart.setup/uart.close指定UART端口后, REPL自动失效
+3. 单行语句一般支持到510字节,更长的语句请使用"多行语句"的方式使用
+4. 若需要定义全局变量, 请使用 _G.xxx = yyy 形式
+
+若有任何疑问, 请到 chat.openluat.com 发帖反馈
+]]
 */
 #include "luat_base.h"
 #include "luat_repl.h"

+ 15 - 0
demo/repl/main.lua

@@ -0,0 +1,15 @@
+
+-- LuaTools需要PROJECT和VERSION这两个信息
+PROJECT = "repl"
+VERSION = "1.0.0"
+
+log.info("main", PROJECT, VERSION)
+
+-- 一定要添加sys.lua !!!!
+sys = require("sys")
+
+-- 用户代码已结束---------------------------------------------
+-- 结尾总是这一句
+sys.run()
+-- sys.run()之后后面不要加任何语句!!!!!
+