Просмотр исходного кода

Merge branches 'master' and 'master' of github.com:openLuat/LuatOS

Wendal Chen 5 лет назад
Родитель
Сommit
4ee5adc0b6
47 измененных файлов с 742 добавлено и 268 удалено
  1. 1 1
      luat/modules/luat_lib_adc.c
  2. 1 1
      luat/modules/luat_lib_crypto.c
  3. 1 1
      luat/modules/luat_lib_disp.c
  4. 1 1
      luat/modules/luat_lib_gpio.c
  5. 1 1
      luat/modules/luat_lib_i2c.c
  6. 1 1
      luat/modules/luat_lib_libcoap.c
  7. 1 1
      luat/modules/luat_lib_libgnss.c
  8. 1 1
      luat/modules/luat_lib_log.c
  9. 1 1
      luat/modules/luat_lib_mqtt.c
  10. 1 1
      luat/modules/luat_lib_mqttcore.c
  11. 1 1
      luat/modules/luat_lib_pm.c
  12. 1 1
      luat/modules/luat_lib_pwm.c
  13. 1 1
      luat/modules/luat_lib_rtos.c
  14. 1 1
      luat/modules/luat_lib_sensor.c
  15. 1 1
      luat/modules/luat_lib_socket.c
  16. 1 1
      luat/modules/luat_lib_spi.c
  17. 1 1
      luat/modules/luat_lib_timer.c
  18. 1 1
      luat/modules/luat_lib_uart.c
  19. 1 1
      luat/rtt/luat_lib_wlan.c
  20. 2 2
      tools/java/src/main/java/org/luatos/toolkit/api/FnSignParser.java
  21. 9 0
      tools/java/src/main/java/org/luatos/toolkit/api/LuDocParser.java
  22. 4 25
      tools/java/src/main/java/org/luatos/toolkit/bean/FnParam.java
  23. 61 0
      tools/java/src/main/java/org/luatos/toolkit/bean/FnReturn.java
  24. 31 26
      tools/java/src/main/java/org/luatos/toolkit/bean/FnSign.java
  25. 7 0
      tools/java/src/main/java/org/luatos/toolkit/bean/LuCmtType.java
  26. 171 0
      tools/java/src/main/java/org/luatos/toolkit/bean/LuComment.java
  27. 0 7
      tools/java/src/main/java/org/luatos/toolkit/bean/LuCommentType.java
  28. 0 135
      tools/java/src/main/java/org/luatos/toolkit/bean/LuDocComment.java
  29. 1 1
      tools/java/src/main/java/org/luatos/toolkit/bean/LuDocHeader.java
  30. 4 4
      tools/java/src/main/java/org/luatos/toolkit/bean/LuDocument.java
  31. 3 3
      tools/java/src/main/java/org/luatos/toolkit/bean/LuatDocSet.java
  32. 6 5
      tools/java/src/main/java/org/luatos/toolkit/impl/CFnSignParser.java
  33. 86 0
      tools/java/src/main/java/org/luatos/toolkit/impl/CLuDocParser.java
  34. 14 11
      tools/java/src/main/java/org/luatos/toolkit/impl/LuaDocFnSignParser.java
  35. 2 2
      tools/java/src/test/java/org/luatos/toolkit/LuatTookietTestAll.java
  36. 13 13
      tools/java/src/test/java/org/luatos/toolkit/bean/FnSignTest.java
  37. 23 8
      tools/java/src/test/java/org/luatos/toolkit/bean/LuCommentTest.java
  38. 23 0
      tools/java/src/test/java/org/luatos/toolkit/impl/CLuDocParserTest.java
  39. 3 1
      tools/java/src/test/resources/expec/c_sign_fn_0.json
  40. 3 1
      tools/java/src/test/resources/expec/c_sign_fn_1.json
  41. 3 1
      tools/java/src/test/resources/expec/c_sign_fn_2.json
  42. 4 0
      tools/java/src/test/resources/expec/cmt_c_single_1.txt
  43. 4 2
      tools/java/src/test/resources/expec/lua_cmt_fn_0.json
  44. 4 2
      tools/java/src/test/resources/expec/lua_cmt_fn_1.json
  45. 1 0
      tools/java/src/test/resources/expec/test_src_luat_lib_rtos.json
  46. 4 0
      tools/java/src/test/resources/input/cmt_c_single_1.txt
  47. 237 0
      tools/java/src/test/resources/input/test_src_luat_lib_rtos.c

+ 1 - 1
luat/modules/luat_lib_adc.c

@@ -3,7 +3,7 @@
 @module  adc
 @summary 数模转换
 @version 1.0
-@data    2020.07.03
+@date    2020.07.03
 */
 #include "luat_base.h"
 #include "luat_adc.h"

+ 1 - 1
luat/modules/luat_lib_crypto.c

@@ -3,7 +3,7 @@
 @module  crypto
 @summary 加解密和hash函数
 @version 1.0
-@data    2020.07.03
+@date    2020.07.03
 */
 #include "luat_base.h"
 #include "luat_crypto.h"

+ 1 - 1
luat/modules/luat_lib_disp.c

@@ -2,7 +2,7 @@
 @module  disp
 @summary 显示屏控制
 @version 1.0
-@data    2020.03.30
+@date    2020.03.30
 */
 #include "luat_base.h"
 #include "luat_malloc.h"

+ 1 - 1
luat/modules/luat_lib_gpio.c

@@ -3,7 +3,7 @@
 @module  gpio
 @summary GPIO操作
 @version 1.0
-@data    2020.03.30
+@date    2020.03.30
 */
 #include "luat_base.h"
 #include "luat_gpio.h"

+ 1 - 1
luat/modules/luat_lib_i2c.c

@@ -3,7 +3,7 @@
 @module  i2c
 @summary I2C操作
 @version 1.0
-@data    2020.03.30
+@date    2020.03.30
 */
 #include "luat_base.h"
 #include "luat_log.h"

+ 1 - 1
luat/modules/luat_lib_libcoap.c

@@ -2,7 +2,7 @@
 @module  libcoap
 @summary coap数据处理
 @version 1.0
-@data    2020.06.30
+@date    2020.06.30
 */
 #include "luat_base.h"
 #include "luat_timer.h"

+ 1 - 1
luat/modules/luat_lib_libgnss.c

@@ -3,7 +3,7 @@
 @module  libgnss
 @summary NMEA数据处理
 @version 1.0
-@data    2020.07.03
+@date    2020.07.03
 */
 #include "luat_base.h"
 #include "luat_msgbus.h"

+ 1 - 1
luat/modules/luat_lib_log.c

@@ -3,7 +3,7 @@
 @module  log
 @summary 日志库
 @version 1.0
-@data    2020.03.30
+@date    2020.03.30
 */
 #include "luat_base.h"
 #include "luat_log.h"

+ 1 - 1
luat/modules/luat_lib_mqtt.c

@@ -2,7 +2,7 @@
 @module  mqtt
 @summary mqtt操作库
 @version 1.0
-@data    2020.03.30
+@date    2020.03.30
 */
 #include "luat_base.h"
 #include "luat_log.h"

+ 1 - 1
luat/modules/luat_lib_mqttcore.c

@@ -2,7 +2,7 @@
 @module  libmqtt
 @summary mqtt协议处理
 @version 1.0
-@data    2020.07.03
+@date    2020.07.03
 */
 #include "luat_base.h"
 #include "luat_log.h"

+ 1 - 1
luat/modules/luat_lib_pm.c

@@ -3,7 +3,7 @@
 @module  pm
 @summary 电源管理
 @version 1.0
-@data    2020.07.02
+@date    2020.07.02
 */
 #include "lua.h"
 #include "lauxlib.h"

+ 1 - 1
luat/modules/luat_lib_pwm.c

@@ -2,7 +2,7 @@
 @module  pwm
 @summary PWM模块
 @version 1.0
-@data    2020.07.03
+@date    2020.07.03
 */
 #include "luat_base.h"
 #include "luat_pwm.h"

+ 1 - 1
luat/modules/luat_lib_rtos.c

@@ -2,7 +2,7 @@
 @module  rtos
 @summary RTOS底层操作库
 @version 1.0
-@data    2020.03.30
+@date    2020.03.30
 */
 #include "luat_base.h"
 #include "luat_sys.h"

+ 1 - 1
luat/modules/luat_lib_sensor.c

@@ -3,7 +3,7 @@
 @module  sensor
 @summary 传感器操作库
 @version 1.0
-@data    2020.03.30
+@date    2020.03.30
 */
 #include "luat_base.h"
 #include "luat_timer.h"

+ 1 - 1
luat/modules/luat_lib_socket.c

@@ -2,7 +2,7 @@
 @module  socket
 @summary socket操作库
 @version 1.0
-@data    2020.03.30
+@date    2020.03.30
 */
 #include "luat_base.h"
 #include "luat_timer.h"

+ 1 - 1
luat/modules/luat_lib_spi.c

@@ -2,7 +2,7 @@
 @module  spi
 @summary spi操作库
 @version 1.0
-@data    2020.04.23
+@date    2020.04.23
 */
 #include "luat_base.h"
 #include "luat_log.h"

+ 1 - 1
luat/modules/luat_lib_timer.c

@@ -2,7 +2,7 @@
 @module  timer
 @summary 操作底层定时器
 @version 1.0
-@data    2020.03.30
+@date    2020.03.30
 */
 #include "luat_base.h"
 #include "luat_log.h"

+ 1 - 1
luat/modules/luat_lib_uart.c

@@ -2,7 +2,7 @@
 @module  uart
 @summary 串口操作库
 @version 1.0
-@data    2020.03.30
+@date    2020.03.30
 */
 #include "luat_base.h"
 #include "luat_uart.h"

+ 1 - 1
luat/rtt/luat_lib_wlan.c

@@ -2,7 +2,7 @@
 @module  wlan
 @summary wifi操作库
 @version 1.0
-@data    2020.03.30
+@date    2020.03.30
 */
 #include "luat_base.h"
 #include "luat_log.h"

+ 2 - 2
tools/java/src/main/java/org/luatos/toolkit/api/FnSignGenerating.java → tools/java/src/main/java/org/luatos/toolkit/api/FnSignParser.java

@@ -2,8 +2,8 @@ package org.luatos.toolkit.api;
 
 import org.luatos.toolkit.bean.FnSign;
 
-public interface FnSignGenerating {
+public interface FnSignParser {
 
-    FnSign gen(String block);
+    FnSign parse(String block);
 
 }

+ 9 - 0
tools/java/src/main/java/org/luatos/toolkit/api/LuDocParser.java

@@ -0,0 +1,9 @@
+package org.luatos.toolkit.api;
+
+import org.luatos.toolkit.bean.LuDocument;
+
+public interface LuDocParser {
+
+    LuDocument parse(String input);
+
+}

+ 4 - 25
tools/java/src/main/java/org/luatos/toolkit/bean/FnParam.java

@@ -3,22 +3,10 @@ package org.luatos.toolkit.bean;
 import org.luatos.toolkit.Luats;
 import org.nutz.lang.Strings;
 
-public class FnParam {
-
-    private String type;
+public class FnParam extends FnReturn {
 
     private String name;
 
-    private String comment;
-
-    public String getType() {
-        return type;
-    }
-
-    public void setType(String type) {
-        this.type = type;
-    }
-
     public String getName() {
         return name;
     }
@@ -31,14 +19,6 @@ public class FnParam {
         }
     }
 
-    public String getComment() {
-        return comment;
-    }
-
-    public void setComment(String comment) {
-        this.comment = comment;
-    }
-
     public String toString() {
         String str = type;
         if (str.endsWith(" *")) {
@@ -55,13 +35,12 @@ public class FnParam {
     public boolean equals(Object o) {
         if (o instanceof FnParam) {
             FnParam fp = (FnParam) o;
-            if (!Luats.isSame(this.type, fp.type))
-                return false;
 
-            if (!Luats.isSame(this.name, fp.name))
+            if (!super.equals(fp)) {
                 return false;
+            }
 
-            if (!Luats.isSame(this.comment, fp.comment))
+            if (!Luats.isSame(this.name, fp.name))
                 return false;
 
             return true;

+ 61 - 0
tools/java/src/main/java/org/luatos/toolkit/bean/FnReturn.java

@@ -0,0 +1,61 @@
+package org.luatos.toolkit.bean;
+
+import org.luatos.toolkit.Luats;
+import org.nutz.lang.Strings;
+
+public class FnReturn {
+
+    protected String type;
+
+    protected String comment;
+
+    public FnReturn() {}
+
+    public FnReturn(String type) {
+        this.type = type;
+    }
+
+    public FnReturn(String type, String comment) {
+        this.type = type;
+        this.comment = comment;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getComment() {
+        return comment;
+    }
+
+    public void setComment(String comment) {
+        this.comment = comment;
+    }
+
+    public String toString() {
+        String str = type;
+        if (!Strings.isBlank(comment)) {
+            str += "/* " + comment + " */";
+        }
+        return str;
+    }
+
+    public boolean equals(Object o) {
+        if (o instanceof FnReturn) {
+            FnReturn fr = (FnReturn) o;
+            if (!Luats.isSame(this.type, fr.type))
+                return false;
+
+            if (!Luats.isSame(this.comment, fr.comment))
+                return false;
+
+            return true;
+        }
+        return false;
+    }
+
+}

+ 31 - 26
tools/java/src/main/java/org/luatos/toolkit/bean/FnSign.java

@@ -18,12 +18,10 @@ public class FnSign {
 
     private FnModifier modifier;
 
-    private String returnType;
-
-    private String returnComment;
-
     private String name;
 
+    private List<FnReturn> returns;
+
     private List<FnParam> params;
 
     private List<FnExample> examples;
@@ -39,6 +37,7 @@ public class FnSign {
         if (null != modifier) {
             str += this.modifier.toString().toLowerCase() + " ";
         }
+
         String pmStr = "";
         if (null != params) {
             List<String> pms = new ArrayList<>(params.size());
@@ -47,7 +46,17 @@ public class FnSign {
             }
             pmStr = Strings.join(", ", pms);
         }
-        str += String.format("%s %s(%s)", returnType, name, pmStr);
+
+        String res = "";
+        if (null != returns) {
+            List<String> reList = new ArrayList<>(this.returns.size());
+            for (FnReturn re : returns) {
+                reList.add(re.getType());
+            }
+            res = Strings.join(",", reList);
+        }
+
+        str += String.format("%s %s(%s)", res, name, pmStr);
 
         return str;
     }
@@ -69,13 +78,10 @@ public class FnSign {
         if (!Luats.isSame(this.modifier, fn.modifier))
             return false;
 
-        if (!Luats.isSame(this.returnType, fn.returnType))
-            return false;
-
-        if (!Luats.isSame(this.returnComment, fn.returnComment))
+        if (!Luats.isSame(this.name, fn.name))
             return false;
 
-        if (!Luats.isSame(this.name, fn.name))
+        if (!Luats.isSameList(this.returns, fn.returns))
             return false;
 
         if (!Luats.isSameList(this.params, fn.params))
@@ -119,28 +125,27 @@ public class FnSign {
         this.modifier = modifier;
     }
 
-    public String getReturnType() {
-        return returnType;
+    public String getName() {
+        return name;
     }
 
-    public void setReturnType(String returnType) {
-        this.returnType = returnType;
+    public void setName(String name) {
+        this.name = name;
     }
 
-    public String getReturnComment() {
-        return returnComment;
+    public List<FnReturn> getReturns() {
+        return returns;
     }
 
-    public void setReturnComment(String returnComment) {
-        this.returnComment = returnComment;
+    public void setReturns(List<FnReturn> returns) {
+        this.returns = returns;
     }
 
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
+    public void addReturn(FnReturn fr) {
+        if (null == this.returns) {
+            this.returns = new LinkedList<>();
+        }
+        this.returns.add(fr);
     }
 
     public List<FnParam> getParams() {
@@ -151,7 +156,7 @@ public class FnSign {
         this.params = params;
     }
 
-    public void addParams(FnParam param) {
+    public void addParam(FnParam param) {
         if (null == this.params) {
             this.params = new LinkedList<>();
         }
@@ -166,7 +171,7 @@ public class FnSign {
         this.examples = examples;
     }
 
-    public void addExamples(FnExample example) {
+    public void addExample(FnExample example) {
         if (null == this.examples) {
             this.examples = new LinkedList<>();
         }

+ 7 - 0
tools/java/src/main/java/org/luatos/toolkit/bean/LuCmtType.java

@@ -0,0 +1,7 @@
+package org.luatos.toolkit.bean;
+
+public enum LuCmtType {
+
+    LUA_HEAD, LUA_SIGN, BLOCK, LINES
+
+}

+ 171 - 0
tools/java/src/main/java/org/luatos/toolkit/bean/LuComment.java

@@ -0,0 +1,171 @@
+package org.luatos.toolkit.bean;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.regex.Matcher;
+
+import org.nutz.lang.Strings;
+import org.nutz.lang.util.Regex;
+
+public class LuComment {
+
+    private int space;
+
+    private LuCmtType type;
+
+    private List<String> lines;
+
+    public LuComment() {}
+
+    public LuComment(String block) {
+        this.parse(block);
+    }
+
+    public void clear() {
+        this.type = null;
+        this.lines = null;
+    }
+
+    public boolean isLuaHead() {
+        return LuCmtType.LUA_HEAD == this.type;
+    }
+
+    public boolean isLuaSign() {
+        return LuCmtType.LUA_SIGN == this.type;
+    }
+
+    public boolean isBlock() {
+        return LuCmtType.BLOCK == this.type;
+    }
+
+    public boolean isLines() {
+        return LuCmtType.LINES == this.type;
+    }
+
+    public boolean isEmpty() {
+        return null == lines || lines.isEmpty();
+    }
+
+    public int getSpace() {
+        return space;
+    }
+
+    public void setSpace(int space) {
+        this.space = space;
+    }
+
+    public LuCmtType getType() {
+        return type;
+    }
+
+    public void setType(LuCmtType type) {
+        this.type = type;
+    }
+
+    public List<String> getLines() {
+        return lines;
+    }
+
+    public void setLines(List<String> lines) {
+        this.lines = lines;
+    }
+
+    private static final String BLK_BEGIN = "^(\\s*)(/[*]|[*]{1,2} ) ?(.*)$";
+    private static final String BLK_END = "^(.*) *([*]/)\\s*$";
+    private static final String LIN_CMT = "^(\\s*)(// ?)(.*)$";
+
+    /**
+     * @param line
+     * @return true 还可以再尝试接受输入。 false 已经关闭了
+     */
+    public boolean appendLine(String line) {
+        if (null == lines) {
+            lines = new LinkedList<>();
+        }
+        Matcher m;
+
+        // 单行注释
+        m = Regex.getPattern(LIN_CMT).matcher(line);
+        if (m.find()) {
+            if (null == this.type) {
+                this.type = LuCmtType.LINES;
+                this.space = m.group(1).length();
+            }
+            // 必须自己也是单行注释
+            else if (!this.isLines()) {
+                return false;
+            }
+
+            // 成功加入
+            lines.add(m.group(3));
+            return true;
+        }
+
+        // 多行注释:
+        // -> /*
+        // -> **
+        // -> *
+        m = Regex.getPattern(BLK_BEGIN).matcher(line);
+        if (m.find()) {
+            if (null == this.type) {
+                this.type = LuCmtType.BLOCK;
+                this.space = m.group(1).length();
+            }
+            // 必须自己也是块注释
+            else if (!this.isBlock()) {
+                return false;
+            }
+            // 成功加入
+            String str = m.group(3);
+            // 计入(如果已经开始计入注释行了,那么空行也加进来,当然最后一行除外
+            if (!Strings.isBlank(str) || !this.isEmpty()) {
+                lines.add(str);
+            }
+            return true;
+        }
+
+        // 多行注释: 结尾
+        m = Regex.getPattern(BLK_END).matcher(line);
+        if (m.find()) {
+            if (this.isBlock()) {
+                String str = m.group(1);
+                if (!Strings.isBlank(str))
+                    lines.add(str);
+            }
+            return false;
+        }
+
+        // 其他的普通行,只有多行注释才能接受
+        if (this.isBlock() || this.isLuaSign() || this.isLuaHead()) {
+            lines.add(line);
+            // 如果这个行是一个函数声明,那么切换特殊类型
+            if (this.isBlock()) {
+                if (line.startsWith("@function")) {
+                    this.setType(LuCmtType.LUA_SIGN);
+                } else if (line.startsWith("@module")) {
+                    this.setType(LuCmtType.LUA_HEAD);
+                }
+            }
+            return true;
+        }
+
+        return false;
+    }
+
+    public void parse(String block) {
+        String[] ss = block.split("\r?\n");
+        for (String s : ss) {
+            if (!this.appendLine(s)) {
+                return;
+            }
+        }
+    }
+
+    public String toString() {
+        if (this.isEmpty()) {
+            return "";
+        }
+        return Strings.join(System.lineSeparator(), lines);
+    }
+
+}

+ 0 - 7
tools/java/src/main/java/org/luatos/toolkit/bean/LuCommentType.java

@@ -1,7 +0,0 @@
-package org.luatos.toolkit.bean;
-
-public enum LuCommentType {
-
-    LUA_SIGN, TEXT, DISABLED
-    
-}

+ 0 - 135
tools/java/src/main/java/org/luatos/toolkit/bean/LuDocComment.java

@@ -1,135 +0,0 @@
-package org.luatos.toolkit.bean;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.regex.Matcher;
-
-import org.nutz.lang.Strings;
-import org.nutz.lang.util.Regex;
-
-public class LuDocComment {
-
-    private LuCommentType type;
-
-    private List<String> lines;
-
-    public LuDocComment() {}
-
-    public LuDocComment(String block) {
-        this.parse(block);
-    }
-
-    public void clear() {
-        this.type = null;
-        this.lines = null;
-    }
-
-    public boolean isLuaSign() {
-        return LuCommentType.LUA_SIGN == this.type;
-    }
-
-    public boolean isText() {
-        return LuCommentType.TEXT == this.type;
-    }
-
-    public boolean isDisabled() {
-        return LuCommentType.DISABLED == this.type;
-    }
-
-    public boolean isEmpty() {
-        return null == lines || lines.isEmpty();
-    }
-
-    public LuCommentType getType() {
-        return type;
-    }
-
-    public void setType(LuCommentType type) {
-        this.type = type;
-    }
-
-    public List<String> getLines() {
-        return lines;
-    }
-
-    public void setLines(List<String> lines) {
-        this.lines = lines;
-    }
-
-    public void appendLine(String line) {
-        if (null == lines) {
-            lines = new LinkedList<>();
-        }
-        this.lines.add(line);
-    }
-
-    private static final String REG_BEGIN = "^\\s*(/[*]|[*]{1,2} ) *(.*)$";
-    private static final String REG_END = "^(.*) *([*]/)\\s*$";
-
-    public void parse(String block) {
-        String[] ss = block.split("\r?\n");
-        // 有可能是多重
-        if (ss.length >= 2) {
-            // 或者是多行或者是 Lua 的 doxygen 注释
-            if (ss[0].startsWith("/*") && ss[ss.length - 1].endsWith("*/")) {
-                LuCommentType type = null;
-                int lastI = ss.length - 1;
-                for (int i = 0; i <= lastI; i++) {
-                    String s = ss[i];
-                    String str = null;
-                    Matcher m = Regex.getPattern(REG_BEGIN).matcher(s);
-                    // 可能是普通注释第一行
-                    // -> /*
-                    // -> **
-                    // -> *
-                    if (m.find()) {
-                        str = m.group(2);
-                    }
-                    // 看看是否是结尾
-                    else {
-                        m = Regex.getPattern(REG_END).matcher(s);
-                        if (m.find()) {
-                            str = m.group(1);
-                        }
-                        // 那么就是普通行咯
-                        else {
-                            str = s;
-                        }
-                    }
-
-                    // 计入(如果已经开始计入注释行了,那么空行也加进来,当然最后一行除外
-                    if (!Strings.isBlank(str) || (!this.isEmpty() && i < lastI)) {
-                        this.appendLine(str);
-                        // 如果声明了 docxygen 的注释,标识一下类型
-                        if (null == type && str.startsWith("@function")) {
-                            type = LuCommentType.LUA_SIGN;
-                        }
-                    }
-                }
-
-                // 最后设置一下类型
-                if (null == type) {
-                    type = LuCommentType.TEXT;
-                }
-                this.setType(type);
-
-                return;
-            }
-        }
-        // 看看是不是单行注释
-        for (String s : ss) {
-            if (s.startsWith("//")) {
-                this.appendLine(s.substring(2).trim());
-            }
-        }
-        this.setType(LuCommentType.TEXT);
-    }
-
-    public String toString() {
-        if (this.isEmpty()) {
-            return "";
-        }
-        return Strings.join(System.lineSeparator(), lines);
-    }
-
-}

+ 1 - 1
tools/java/src/main/java/org/luatos/toolkit/bean/LuatDocHeader.java → tools/java/src/main/java/org/luatos/toolkit/bean/LuDocHeader.java

@@ -1,6 +1,6 @@
 package org.luatos.toolkit.bean;
 
-public class LuatDocHeader {
+public class LuDocHeader {
 
     private String module;
 

+ 4 - 4
tools/java/src/main/java/org/luatos/toolkit/bean/LuatDocument.java → tools/java/src/main/java/org/luatos/toolkit/bean/LuDocument.java

@@ -3,11 +3,11 @@ package org.luatos.toolkit.bean;
 import java.util.LinkedList;
 import java.util.List;
 
-public class LuatDocument {
+public class LuDocument {
 
     private String path;
 
-    private LuatDocHeader title;
+    private LuDocHeader title;
 
     private List<FnSign> functions;
 
@@ -19,11 +19,11 @@ public class LuatDocument {
         this.path = path;
     }
 
-    public LuatDocHeader getTitle() {
+    public LuDocHeader getTitle() {
         return title;
     }
 
-    public void setTitle(LuatDocHeader title) {
+    public void setTitle(LuDocHeader title) {
         this.title = title;
     }
 

+ 3 - 3
tools/java/src/main/java/org/luatos/toolkit/bean/LuatDocSet.java

@@ -7,14 +7,14 @@ public class LuatDocSet {
 
     private String name;
 
-    private List<LuatDocument> docs;
+    private List<LuDocument> docs;
 
     public LuatDocSet(String name) {
         this.name = name;
         this.docs = new LinkedList<>();
     }
 
-    public void addDoc(LuatDocument doc) {
+    public void addDoc(LuDocument doc) {
         this.docs.add(doc);
     }
 
@@ -26,7 +26,7 @@ public class LuatDocSet {
         this.name = name;
     }
 
-    public List<LuatDocument> getDocs() {
+    public List<LuDocument> getDocs() {
         return docs;
     }
 

+ 6 - 5
tools/java/src/main/java/org/luatos/toolkit/impl/CFnSignGenerating.java → tools/java/src/main/java/org/luatos/toolkit/impl/CFnSignParser.java

@@ -4,15 +4,16 @@ import java.util.ArrayList;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.luatos.toolkit.api.FnSignGenerating;
+import org.luatos.toolkit.api.FnSignParser;
 import org.luatos.toolkit.bean.FnModifier;
 import org.luatos.toolkit.bean.FnParam;
+import org.luatos.toolkit.bean.FnReturn;
 import org.luatos.toolkit.bean.FnSign;
 import org.nutz.lang.Lang;
 import org.nutz.lang.Strings;
 import org.nutz.lang.util.Regex;
 
-public class CFnSignGenerating implements FnSignGenerating {
+public class CFnSignParser implements FnSignParser {
 
     private static String _r0 = "^\\s*((static)\\s+)?(\\w+(\\s*[*])?)\\s*(\\w+)\\s*\\(([^)]*)\\).*$";
     private static Pattern PT = Regex.getPattern(_r0);
@@ -21,7 +22,7 @@ public class CFnSignGenerating implements FnSignGenerating {
     private static Pattern PM = Regex.getPattern(_r1);
 
     @Override
-    public FnSign gen(String block) {
+    public FnSign parse(String block) {
         // 变成一行
         String str = block.replaceAll("\r?\n", " ");
 
@@ -46,7 +47,7 @@ public class CFnSignGenerating implements FnSignGenerating {
         if ("static".equals(mod)) {
             fn.setModifier(FnModifier.STATIC);
         }
-        fn.setReturnType(retp);
+        fn.addReturn(new FnReturn(retp));
         fn.setName(name);
 
         // 分析参数
@@ -66,7 +67,7 @@ public class CFnSignGenerating implements FnSignGenerating {
                 FnParam pm = new FnParam();
                 pm.setType(pmtp);
                 pm.setName(pmnm);
-                fn.addParams(pm);
+                fn.addParam(pm);
             }
         }
 

+ 86 - 0
tools/java/src/main/java/org/luatos/toolkit/impl/CLuDocParser.java

@@ -0,0 +1,86 @@
+package org.luatos.toolkit.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.luatos.toolkit.api.LuDocParser;
+import org.luatos.toolkit.bean.LuComment;
+import org.luatos.toolkit.bean.LuDocument;
+import org.nutz.lang.Strings;
+import org.nutz.lang.util.Regex;
+
+public class CLuDocParser implements LuDocParser {
+
+    @Override
+    public LuDocument parse(String input) {
+        String[] lines = input.split("\r?\n");
+
+        List<Object> entities = new ArrayList<>(lines.length / 2);
+
+        // 当前注释
+        LuComment cmt = null;
+        Matcher m;
+
+        // 准备注释行的判断
+        Pattern P_CMT = Regex.getPattern("^\\s*(/[/*]).*$");
+        Pattern P_FNC = Regex.getPattern("^\\s*static [\\w\\d ]+\\(.*\\).*$");
+
+        // 逐行循环
+        for (String line : lines) {
+            // 嗯单行注释行
+            // 嗯多行注释
+            m = P_CMT.matcher(line);
+            if (m.find()) {
+                if (null == cmt) {
+                    cmt = new LuComment();
+                }
+                if (!cmt.appendLine(line)) {
+                    entities.add(cmt);
+                    cmt = null;
+                }
+                continue;
+            }
+            // 嗯,看看是不是可以加入注释
+            if (null != cmt) {
+                if (cmt.appendLine(line)) {
+                    continue;
+                }
+                if (!cmt.isEmpty() && cmt.getSpace() == 0) {
+                    // 看看是不是水平线
+                    String str = cmt.toString();
+                    String lin = Strings.dup(str.charAt(0), str.length());
+                    if (!str.equals(lin)) {
+                        entities.add(cmt);
+                    }
+                }
+                cmt = null;
+            }
+
+            // 嗯 静态函数
+            m = P_FNC.matcher(line);
+            if (m.find()) {
+                entities.add(line.trim());
+            }
+
+            // 嗯,无视
+        }
+
+        // 测试打印一下
+        String hr = Strings.dup('-', 40);
+        for (Object en : entities) {
+            System.out.println(hr);
+            if (en instanceof LuComment) {
+                System.out.printf("- {%s}\n", ((LuComment) en).getType());
+            } else {
+                System.out.println("- <CFunction>");
+            }
+            System.out.println(hr);
+            System.out.println(en.toString());
+        }
+
+        return null;
+    }
+
+}

+ 14 - 11
tools/java/src/main/java/org/luatos/toolkit/impl/LuaDocFnSignGenerating.java → tools/java/src/main/java/org/luatos/toolkit/impl/LuaDocFnSignParser.java

@@ -5,15 +5,16 @@ import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.luatos.toolkit.api.FnSignGenerating;
+import org.luatos.toolkit.api.FnSignParser;
 import org.luatos.toolkit.bean.FnExample;
 import org.luatos.toolkit.bean.FnParam;
+import org.luatos.toolkit.bean.FnReturn;
 import org.luatos.toolkit.bean.FnSign;
 import org.nutz.lang.Lang;
 import org.nutz.lang.Strings;
 import org.nutz.lang.util.Regex;
 
-public class LuaDocFnSignGenerating implements FnSignGenerating {
+public class LuaDocFnSignParser implements FnSignParser {
 
     private static final int IN_SUMMARY = 0;
     private static final int IN_FUNC = 1;
@@ -23,7 +24,7 @@ public class LuaDocFnSignGenerating implements FnSignGenerating {
     private static Pattern P2 = Regex.getPattern(_r2);
 
     @Override
-    public FnSign gen(String block) {
+    public FnSign parse(String block) {
         String[] lines = block.split("\r?\n");
         List<String> summaries = new ArrayList<>(lines.length);
         String func;
@@ -69,7 +70,7 @@ public class LuaDocFnSignGenerating implements FnSignGenerating {
                 // 进入例子部分了
                 else if (line.startsWith("--")) {
                     if (null != exmLast && exmLast.hasCode()) {
-                        fn.addExamples(exmLast);
+                        fn.addExample(exmLast);
                     }
 
                     exmLast = new FnExample();
@@ -99,7 +100,7 @@ public class LuaDocFnSignGenerating implements FnSignGenerating {
                 // 追加说明
                 if (line.startsWith("--")) {
                     if (null != exmLast && exmLast.hasCode()) {
-                        fn.addExamples(exmLast);
+                        fn.addExample(exmLast);
                     }
                     if (null == exmLast) {
                         exmLast = new FnExample();
@@ -131,12 +132,12 @@ public class LuaDocFnSignGenerating implements FnSignGenerating {
                 param = new FnParam();
             }
             param.setName(pmnm);
-            fn.addParams(param);
+            fn.addParam(param);
         }
 
         // 最后一个例子
         if (null != exmLast && exmLast.hasCode()) {
-            fn.addExamples(exmLast);
+            fn.addExample(exmLast);
         }
 
         // 搞定
@@ -147,13 +148,15 @@ public class LuaDocFnSignGenerating implements FnSignGenerating {
         // 返回值
         if ("return".equals(feType)) {
             int pos = feCmt.indexOf(' ');
+            FnReturn fr = new FnReturn();
             if (pos > 0) {
-                fn.setReturnType(feCmt.substring(0, pos).trim());
-                fn.setReturnComment(feCmt.substring(pos + 1).trim());
+                fr.setType(feCmt.substring(0, pos).trim());
+                fr.setComment(feCmt.substring(pos + 1).trim());
             } else {
-                fn.setReturnType("??");
-                fn.setReturnComment(feCmt);
+                fr.setType("??");
+                fr.setComment(feCmt);
             }
+            fn.addReturn(fr);
         }
         // 参数
         else {

+ 2 - 2
tools/java/src/test/java/org/luatos/toolkit/LuatTookietTestAll.java

@@ -3,8 +3,8 @@ package org.luatos.toolkit;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 import org.luatos.toolkit.bean.FnSignTest;
-import org.luatos.toolkit.bean.LuDocCommentTest;
+import org.luatos.toolkit.bean.LuCommentTest;
 
 @RunWith(Suite.class)
-@Suite.SuiteClasses({FnSignTest.class, LuDocCommentTest.class})
+@Suite.SuiteClasses({FnSignTest.class, LuCommentTest.class})
 public class LuatTookietTestAll {}

+ 13 - 13
tools/java/src/test/java/org/luatos/toolkit/bean/FnSignTest.java

@@ -3,9 +3,9 @@ package org.luatos.toolkit.bean;
 import static org.junit.Assert.*;
 
 import org.junit.Test;
-import org.luatos.toolkit.api.FnSignGenerating;
-import org.luatos.toolkit.impl.CFnSignGenerating;
-import org.luatos.toolkit.impl.LuaDocFnSignGenerating;
+import org.luatos.toolkit.api.FnSignParser;
+import org.luatos.toolkit.impl.CFnSignParser;
+import org.luatos.toolkit.impl.LuaDocFnSignParser;
 import org.nutz.json.Json;
 import org.nutz.lang.Files;
 
@@ -17,8 +17,8 @@ public class FnSignTest {
         String expec = Files.read("expec/lua_cmt_fn_0.json");
         FnSign expFn = Json.fromJson(FnSign.class, expec);
 
-        FnSignGenerating fsg = new LuaDocFnSignGenerating();
-        FnSign axuFn = fsg.gen(input);
+        FnSignParser fsg = new LuaDocFnSignParser();
+        FnSign axuFn = fsg.parse(input);
         assertTrue(axuFn.equals(expFn));
     }
 
@@ -28,8 +28,8 @@ public class FnSignTest {
         String expec = Files.read("expec/lua_cmt_fn_1.json");
         FnSign expFn = Json.fromJson(FnSign.class, expec);
 
-        FnSignGenerating fsg = new LuaDocFnSignGenerating();
-        FnSign axuFn = fsg.gen(input);
+        FnSignParser fsg = new LuaDocFnSignParser();
+        FnSign axuFn = fsg.parse(input);
         assertTrue(axuFn.equals(expFn));
     }
 
@@ -39,8 +39,8 @@ public class FnSignTest {
         String expec = Files.read("expec/c_sign_fn_0.json");
         FnSign expFn = Json.fromJson(FnSign.class, expec);
 
-        FnSignGenerating fsg = new CFnSignGenerating();
-        FnSign axuFn = fsg.gen(input);
+        FnSignParser fsg = new CFnSignParser();
+        FnSign axuFn = fsg.parse(input);
         assertTrue(axuFn.equals(expFn));
     }
 
@@ -50,8 +50,8 @@ public class FnSignTest {
         String expec = Files.read("expec/c_sign_fn_1.json");
         FnSign expFn = Json.fromJson(FnSign.class, expec);
 
-        FnSignGenerating fsg = new CFnSignGenerating();
-        FnSign axuFn = fsg.gen(input);
+        FnSignParser fsg = new CFnSignParser();
+        FnSign axuFn = fsg.parse(input);
         assertTrue(axuFn.equals(expFn));
     }
 
@@ -61,8 +61,8 @@ public class FnSignTest {
         String expec = Files.read("expec/c_sign_fn_2.json");
         FnSign expFn = Json.fromJson(FnSign.class, expec);
 
-        FnSignGenerating fsg = new CFnSignGenerating();
-        FnSign axuFn = fsg.gen(input);
+        FnSignParser fsg = new CFnSignParser();
+        FnSign axuFn = fsg.parse(input);
         assertTrue(axuFn.equals(expFn));
     }
 

+ 23 - 8
tools/java/src/test/java/org/luatos/toolkit/bean/LuDocCommentTest.java → tools/java/src/test/java/org/luatos/toolkit/bean/LuCommentTest.java

@@ -5,15 +5,16 @@ import static org.junit.Assert.*;
 import org.junit.Test;
 import org.nutz.lang.Files;
 
-public class LuDocCommentTest {
+public class LuCommentTest {
 
     @Test
     public void test_lua_0() {
         String input = Files.read("input/cmt_lua_0.txt");
         String expec = Files.read("expec/cmt_lua_0.txt");
 
-        LuDocComment dc = new LuDocComment(input);
+        LuComment dc = new LuComment(input);
         assertTrue(dc.isLuaSign());
+        assertEquals(0, dc.getSpace());
         assertEquals(expec, dc.toString());
     }
 
@@ -22,8 +23,9 @@ public class LuDocCommentTest {
         String input = Files.read("input/cmt_c_multi_0.txt");
         String expec = Files.read("expec/cmt_c_multi_0.txt");
 
-        LuDocComment dc = new LuDocComment(input);
-        assertTrue(dc.isText());
+        LuComment dc = new LuComment(input);
+        assertTrue(dc.isBlock());
+        assertEquals(0, dc.getSpace());
         assertEquals(expec, dc.toString());
     }
 
@@ -32,8 +34,9 @@ public class LuDocCommentTest {
         String input = Files.read("input/cmt_c_multi_1.txt");
         String expec = Files.read("expec/cmt_c_multi_1.txt");
 
-        LuDocComment dc = new LuDocComment(input);
-        assertTrue(dc.isText());
+        LuComment dc = new LuComment(input);
+        assertTrue(dc.isBlock());
+        assertEquals(0, dc.getSpace());
         assertEquals(expec, dc.toString());
     }
 
@@ -42,8 +45,20 @@ public class LuDocCommentTest {
         String input = Files.read("input/cmt_c_single_0.txt");
         String expec = Files.read("expec/cmt_c_single_0.txt");
 
-        LuDocComment dc = new LuDocComment(input);
-        assertTrue(dc.isText());
+        LuComment dc = new LuComment(input);
+        assertTrue(dc.isLines());
+        assertEquals(0, dc.getSpace());
+        assertEquals(expec, dc.toString());
+    }
+
+    @Test
+    public void test_single_1() {
+        String input = Files.read("input/cmt_c_single_1.txt");
+        String expec = Files.read("expec/cmt_c_single_1.txt");
+
+        LuComment dc = new LuComment(input);
+        assertTrue(dc.isLines());
+        assertEquals(2, dc.getSpace());
         assertEquals(expec, dc.toString());
     }
 

+ 23 - 0
tools/java/src/test/java/org/luatos/toolkit/impl/CLuDocParserTest.java

@@ -0,0 +1,23 @@
+package org.luatos.toolkit.impl;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.luatos.toolkit.api.LuDocParser;
+import org.luatos.toolkit.bean.LuComment;
+import org.luatos.toolkit.bean.LuDocument;
+import org.nutz.lang.Files;
+
+public class CLuDocParserTest {
+
+    @Test
+    public void testParse() {
+        String input = Files.read("input/test_src_luat_lib_rtos.c");
+        String expec = Files.read("expec/test_src_luat_lib_rtos.json");
+
+        LuDocParser pas = new CLuDocParser();
+        LuDocument doc = pas.parse(input);
+        assertNotNull(doc);
+    }
+
+}

+ 3 - 1
tools/java/src/test/resources/expec/c_sign_fn_0.json

@@ -2,7 +2,9 @@
   "rawText": "static int socket_ntp_sync(lua_State *L)",
   "summary": null,
   "modifier": "STATIC",
-  "returnType": "int",
+  "returns": [{
+      "type": "int"
+    }],
   "name": "socket_ntp_sync",
   "params": [{
       "type": "lua_State *",

+ 3 - 1
tools/java/src/test/resources/expec/c_sign_fn_1.json

@@ -2,7 +2,9 @@
   "rawText": "void  luat_heap_init(void)",
   "summary": null,
   "modifier": null,
-  "returnType": "void",
+  "returns": [{
+      "type": "void"
+    }],
   "name": "luat_heap_init",
   "params": [{
       "type": "void",

+ 3 - 1
tools/java/src/test/resources/expec/c_sign_fn_2.json

@@ -2,7 +2,9 @@
   "rawText": "static int socket_ntp_sync(lua_State *L)",
   "summary": null,
   "modifier": null,
-  "returnType": "void *",
+  "returns": [{
+      "type": "void *"
+    }],
   "name": "luat_rt_realloc",
   "params": [{
       "type": "void *",

+ 4 - 0
tools/java/src/test/resources/expec/cmt_c_single_1.txt

@@ -0,0 +1,4 @@
+Erase a block. A block must be erased before being programmed.
+The state of an erased block is undefined. Negative error codes
+are propogated to the user.
+May return LFS_ERR_CORRUPT if the block should be considered bad.

+ 4 - 2
tools/java/src/test/resources/expec/lua_cmt_fn_0.json

@@ -2,8 +2,10 @@
   "rawText": "=INPUT",
   "summary": "ntp时间同步",
   "modifier": null,
-  "returnType": "int",
-  "returnComment": "启动成功返回0, 失败返回1或者2",
+  "returns": [{
+      "type": "int",
+      "comment": "启动成功返回0, 失败返回1或者2"
+    }],
   "name": "socket.ntpSync",
   "params": [{
       "type": "string",

+ 4 - 2
tools/java/src/test/resources/expec/lua_cmt_fn_1.json

@@ -2,8 +2,10 @@
   "rawText": "=INPUT",
   "summary": "启动一个定时器",
   "modifier": null,
-  "returnType": "id",
-  "returnComment": "如果是定时器消息,会返回定时器消息id及附加信息, 其他消息由底层决定,不向lua层进行任何保证.",
+  "returns": [{
+      "type": "id",
+      "comment": "如果是定时器消息,会返回定时器消息id及附加信息, 其他消息由底层决定,不向lua层进行任何保证."
+    }],
   "name": "rtos.timer_start",
   "params": [{
       "type": "int",

+ 1 - 0
tools/java/src/test/resources/expec/test_src_luat_lib_rtos.json

@@ -0,0 +1 @@
+{}

+ 4 - 0
tools/java/src/test/resources/input/cmt_c_single_1.txt

@@ -0,0 +1,4 @@
+  // Erase a block. A block must be erased before being programmed.
+  // The state of an erased block is undefined. Negative error codes
+  // are propogated to the user.
+  // May return LFS_ERR_CORRUPT if the block should be considered bad.

+ 237 - 0
tools/java/src/test/resources/input/test_src_luat_lib_rtos.c

@@ -0,0 +1,237 @@
+/*
+@module  rtos
+@summary RTOS底层操作库
+@version 1.0
+@date    2020.03.30
+*/
+#include "luat_base.h"
+#include "luat_sys.h"
+#include "luat_msgbus.h"
+#include "luat_timer.h"
+#include "luat_malloc.h"
+
+#define LUAT_LOG_TAG "luat.rtos"
+#include "luat_log.h"
+
+/*
+接受并处理底层消息队列.
+@function    rtos.receive(timeout)   
+@int  超时时长,通常是-1,永久等待
+@return msgid          如果是定时器消息,会返回定时器消息id及附加信息, 其他消息由底层决定,不向lua层进行任何保证.
+--  本方法通过sys.run()调用, 普通用户不要使用
+rtos.receive(-1)
+*/
+static int l_rtos_receive(lua_State *L) {
+    rtos_msg_t msg;
+    int re;
+    re = luat_msgbus_get(&msg, luaL_checkinteger(L, 1));
+    if (!re) {
+        //LLOGD("rtos_msg got, invoke it handler=%08X", msg.handler);
+        lua_pushlightuserdata(L, (void*)(&msg));
+        return msg.handler(L, msg.ptr);
+    }
+    else {
+        //LLOGD("rtos_msg get timeout");
+        lua_pushinteger(L, -1);
+        return 1;
+    }
+}
+
+//------------------------------------------------------------------
+static int l_timer_handler(lua_State *L, void* ptr) {
+    luat_timer_t *timer = (luat_timer_t *)ptr;
+    // LLOGD(("l_timer_handler id=%ld\n", timer->id);
+    lua_pushinteger(L, MSG_TIMER);
+    lua_pushinteger(L, timer->id);
+    lua_pushinteger(L, timer->repeat);
+    //lua_pushinteger(L, timer->timeout);
+    if (timer->repeat == 0) {
+        luat_timer_stop(timer);
+        luat_heap_free(timer);
+    }
+    else if (timer->repeat > 0) {
+        timer->repeat --;
+    }
+    return 3;
+}
+
+/*
+启动一个定时器
+@function    rtos.timer_start(id,timeout,_repeat)   
+@int  定时器id
+@int  超时时长,单位毫秒
+@int  重复次数,默认是0
+@return id 如果是定时器消息,会返回定时器消息id及附加信息, 其他消息由底层决定,不向lua层进行任何保证.
+@usage
+-- 用户代码请使用 sys.timerStart
+-- 启动一个3秒的循环定时器
+rtos.timer_start(10000, 3000, -1)
+*/
+static int l_rtos_timer_start(lua_State *L) {
+    lua_gettop(L);
+    size_t id = (size_t)luaL_checkinteger(L, 1) / 1;
+    size_t timeout = (size_t)luaL_checkinteger(L, 2);
+    int repeat = (size_t)luaL_optinteger(L, 3, 0);
+    // LLOGD(("timer id=%ld\n", id);
+    // LLOGD(("timer timeout=%ld\n", timeout);
+    // LLOGD(("timer repeat=%ld\n", repeat);
+    if (timeout < 1) {
+        lua_pushinteger(L, 0);
+        return 1;
+    }
+    luat_timer_t *timer = (luat_timer_t*)luat_heap_malloc(sizeof(luat_timer_t));
+    timer->id = id;
+    timer->timeout = timeout;
+    timer->repeat = repeat;
+    timer->func = &l_timer_handler;
+
+    int re = luat_timer_start(timer);
+    if (re == 0) {
+        lua_pushinteger(L, 1);
+    }
+    else {
+        lua_pushinteger(L, 0);
+    }
+    return 1;
+}
+
+/*
+关闭并释放一个定时器
+@function    rtos.timer_stop(id)   
+@int  定时器id
+@return nil            无返回值
+@usage
+-- 用户代码请使用sys.timerStop
+rtos.timer_stop(100000)
+*/
+static int l_rtos_timer_stop(lua_State *L) {
+    luat_timer_t *timer = NULL;
+    if (lua_islightuserdata(L, 1)) {
+        timer = (luat_timer_t *)lua_touserdata(L, 1);
+    }
+    else if (lua_isinteger(L, 1)) {
+        timer = luat_timer_get(lua_tointeger(L, 1));
+    }
+    if (timer != NULL) {
+        luat_timer_stop(timer);
+        luat_heap_free(timer);
+    }
+    return 0;
+}
+
+/*
+设备重启
+@function    rtos.reboot()   
+@return nil          无返回值
+-- 立即重启设备
+rtos.reboot()
+*/
+static int l_rtos_reboot(lua_State *L) {
+    luat_os_reboot(luaL_optinteger(L, 1, 0));
+    return 0;
+}
+
+//-----------------------------------------------------------------
+
+/*
+获取固件编译日期
+@function    rtos.buildDate()
+@return string 固件编译日期
+@usage
+-- 获取编译日期
+local d = rtos.buildDate()
+*/
+static int l_rtos_build_date(lua_State *L) {
+    lua_pushstring(L, __DATE__);
+    return 1;
+}
+
+/*
+获取硬件bsp型号
+@function    rtos.bsp()
+@return string 硬件bsp型号
+@usage
+-- 获取编译日期
+local bsp = rtos.bsp()
+*/
+static int l_rtos_bsp(lua_State *L) {
+    lua_pushstring(L, luat_os_bsp());
+    return 1;
+}
+
+/*
+ 获取固件版本号
+@function    rtos.version()        
+@return string  固件版本号,例如"1.0.2"
+@usage
+-- 读取版本号
+local luatos_version = rtos.version()
+*/
+static int l_rtos_version(lua_State *L) {
+    lua_pushstring(L, LUAT_VERSION);
+    return 1;
+}
+
+/*
+进入待机模式(部分设备可用,例如w60x)
+@function    rtos.standy(timeout)
+@int    休眠时长,单位毫秒     
+@return nil  无返回值
+@usage
+-- 读取版本号
+local luatos_version = rtos.version()
+*/
+static int l_rtos_standy(lua_State *L) {
+    int timeout = luaL_checkinteger(L, 1);
+    luat_os_standy(timeout);
+    return 0;
+}
+
+static int l_rtos_meminfo(lua_State *L) {
+    size_t len = 0;
+    size_t total = 0;
+    size_t used = 0;
+    size_t max_used = 0;
+    const char * str = luaL_optlstring(L, 1, "lua", &len);
+    if (strcmp("sys", str) == 0) {
+        //lua_gc(L, LUA_GCCOLLECT, 0);
+        //lua_gc(L, LUA_GCCOLLECT, 0);
+        luat_meminfo_sys(&total, &used, &max_used);
+    }
+    else {
+        luat_meminfo_luavm(&total, &used, &max_used);
+    }
+    lua_pushinteger(L, total);
+    lua_pushinteger(L, used);
+    lua_pushinteger(L, max_used);
+    return 3;
+}
+
+//------------------------------------------------------------------
+#include "rotable.h"
+static const rotable_Reg reg_rtos[] =
+{
+    { "timer_start" ,      l_rtos_timer_start, 0},
+    { "timer_stop",        l_rtos_timer_stop,  0},
+    { "receive",           l_rtos_receive,     0},
+    { "reboot",            l_rtos_reboot,      0},
+    { "standy",            l_rtos_standy,      0},
+
+    { "buildDate",         l_rtos_build_date,  0},
+    { "bsp",               l_rtos_bsp,         0},
+    { "version",           l_rtos_version,     0},
+    { "meminfo",           l_rtos_meminfo,     0},
+
+    { "INF_TIMEOUT",        NULL,              -1},
+
+    { "MSG_TIMER",          NULL,              MSG_TIMER},
+    // { "MSG_GPIO",           NULL,              MSG_GPIO},
+    // { "MSG_UART_RX",        NULL,              MSG_UART_RX},
+    // { "MSG_UART_TXDONE",    NULL,              MSG_UART_TXDONE},
+    { NULL,                 NULL,              0}
+};
+
+LUAMOD_API int luaopen_rtos( lua_State *L ) {
+    rotable_newlib(L, reg_rtos);
+    return 1;
+}