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

update: luat_zbuff加个_t,sdio库优化,lcd库支持draw(zbuff),io库支持fill(zbuff)

Wendal Chen 4 лет назад
Родитель
Сommit
fed8e3d0f6

+ 44 - 44
bsp/air101/demo/fatfs/main.lua → bsp/air101/demo/sdio/main.lua

@@ -1,44 +1,44 @@
-
--- LuaTools需要PROJECT和VERSION这两个信息
-PROJECT = "fatfsdemo"
-VERSION = "1.0.0"
-
--- sys库是标配
-_G.sys = require("sys")
-
-local function fatfs_test()
-    sdio.init(0)
-    sdio.mount(0,"/sd",0)
-    local f = io.open("/sd/boot_time", "rb")
-    local c = 0
-    if f then
-        local data = f:read("*a")
-        log.info("fs", "data", data, data:toHex())
-        c = tonumber(data)
-        f:close()
-    end
-    log.info("fs", "boot count", c)
-    c = c + 1
-    f = io.open("/sd/boot_time", "wb")
-    --if f ~= nil then
-    log.info("fs", "write c to file", c, tostring(c))
-    f:write(tostring(c))
-    f:close()
-    if fs then
-        log.info("fsstat", fs.fsstat("/"))
-        log.info("fsstat", fs.fsstat("/sd"))
-    end
-end
-
-fatfs_test() -- 每次开机,把记录的数值+1
-
-sys.taskInit(function()
-    while 1 do
-        sys.wait(500)
-    end
-end)
-
--- 用户代码已结束---------------------------------------------
--- 结尾总是这一句
-sys.run()
--- sys.run()之后后面不要加任何语句!!!!!
+
+-- LuaTools需要PROJECT和VERSION这两个信息
+PROJECT = "fatfsdemo"
+VERSION = "1.0.0"
+
+-- sys库是标配
+_G.sys = require("sys")
+
+local function fatfs_test()
+    sdio.init(0)
+    sdio.sd_mount(0, "/sd")
+    local f = io.open("/sd/boot_time", "rb")
+    local c = 0
+    if f then
+        local data = f:read("*a")
+        log.info("fs", "data", data, data:toHex())
+        c = tonumber(data)
+        f:close()
+    end
+    log.info("fs", "boot count", c)
+    c = c + 1
+    f = io.open("/sd/boot_time", "wb")
+    --if f ~= nil then
+    log.info("fs", "write c to file", c, tostring(c))
+    f:write(tostring(c))
+    f:close()
+    if fs then
+        log.info("fsstat", fs.fsstat("/"))
+        log.info("fsstat", fs.fsstat("/sd"))
+    end
+end
+
+fatfs_test() -- 每次开机,把记录的数值+1
+
+sys.taskInit(function()
+    while 1 do
+        sys.wait(500)
+    end
+end)
+
+-- 用户代码已结束---------------------------------------------
+-- 结尾总是这一句
+sys.run()
+-- sys.run()之后后面不要加任何语句!!!!!

+ 29 - 18
components/lcd/luat_lib_lcd.c

@@ -8,8 +8,9 @@
 #include "luat_base.h"
 #include "luat_lcd.h"
 #include "luat_malloc.h"
+#include "luat_zbuff.h"
 
-#define LUAT_LOG_TAG "lib_lcd"
+#define LUAT_LOG_TAG "lcd"
 #include "luat_log.h"
 
 extern uint32_t BACK_COLOR , FORE_COLOR ;
@@ -162,7 +163,7 @@ lcd.close()
 static int l_lcd_close(lua_State* L) {
     int ret = luat_lcd_close(default_conf);
     lua_pushboolean(L, ret == 0 ? 1 : 0);
-    return 0;
+    return 1;
 }
 
 /*
@@ -175,7 +176,7 @@ lcd.on()
 static int l_lcd_display_on(lua_State* L) {
     int ret = luat_lcd_display_on(default_conf);
     lua_pushboolean(L, ret == 0 ? 1 : 0);
-    return 0;
+    return 1;
 }
 
 /*
@@ -188,7 +189,7 @@ lcd.off()
 static int l_lcd_display_off(lua_State* L) {
     int ret = luat_lcd_display_off(default_conf);
     lua_pushboolean(L, ret == 0 ? 1 : 0);
-    return 0;
+    return 1;
 }
 
 /*
@@ -201,7 +202,7 @@ lcd.sleep()
 static int l_lcd_sleep(lua_State* L) {
     int ret = luat_lcd_sleep(default_conf);
     lua_pushboolean(L, ret == 0 ? 1 : 0);
-    return 0;
+    return 1;
 }
 
 /*
@@ -214,7 +215,7 @@ lcd.wakeup()
 static int l_lcd_wakeup(lua_State* L) {
     int ret = luat_lcd_wakeup(default_conf);
     lua_pushboolean(L, ret == 0 ? 1 : 0);
-    return 0;
+    return 1;
 }
 
 /*
@@ -232,7 +233,7 @@ static int l_lcd_set_color(lua_State* L) {
     fore = (uint32_t)luaL_checkinteger(L, 2);
     int ret = luat_lcd_set_color(back, fore);
     lua_pushboolean(L, ret == 0 ? 1 : 0);
-    return 0;
+    return 1;
 }
 
 /*
@@ -242,7 +243,7 @@ lcd颜色填充
 @int 左上边缘的Y位置.
 @int 右上边缘的X位置.
 @int 右上边缘的Y位置.
-@int 绘画颜色
+@string 字符串或zbuff对象
 @usage
 -- lcd颜色填充
 buff:writeInt32(0x001F)
@@ -250,15 +251,25 @@ lcd.draw(20,30,220,30,buff)
 */
 static int l_lcd_draw(lua_State* L) {
     uint16_t x1, y1, x2, y2;
-    uint32_t *color = NULL;
+    luat_color_t *color = NULL;
+    luat_zbuff_t *buff;
     x1 = luaL_checkinteger(L, 1);
     y1 = luaL_checkinteger(L, 2);
     x2 = luaL_checkinteger(L, 3);
     y2 = luaL_checkinteger(L, 4);
-    color = (uint32_t*)lua_touserdata(L, 5);
+    if (lua_isstring(L, 5)) {
+        color = (luat_color_t *)luaL_checkstring(L, 5);
+    }
+    else if (lua_isuserdata(L, 5)) {
+        buff = luaL_checkudata(L, 5, LUAT_ZBUFF_TYPE);
+        color = (luat_color_t *)buff->addr;
+    }
+    else {
+        return 0;
+    }
     int ret = luat_lcd_draw(default_conf, x1, y1, x2, y2, color);
     lua_pushboolean(L, ret == 0 ? 1 : 0);
-    return 0;
+    return 1;
 }
 
 /*
@@ -270,13 +281,13 @@ lcd清屏
 lcd.clear()
 */
 static int l_lcd_clear(lua_State* L) {
-    size_t len = 0;
+    //size_t len = 0;
     uint32_t color = BACK_COLOR;
     if (lua_gettop(L) > 0)
         color = (uint32_t)luaL_checkinteger(L, 1);
     int ret = luat_lcd_clear(default_conf, color);
     lua_pushboolean(L, ret == 0 ? 1 : 0);
-    return 0;
+    return 1;
 }
 
 /*
@@ -297,7 +308,7 @@ static int l_lcd_draw_point(lua_State* L) {
         color = (uint32_t)luaL_checkinteger(L, 3);
     int ret = luat_lcd_draw_point(default_conf, x, y, color);
     lua_pushboolean(L, ret == 0 ? 1 : 0);
-    return 0;
+    return 1;
 }
 
 /*
@@ -322,7 +333,7 @@ static int l_lcd_draw_line(lua_State* L) {
         color = (uint32_t)luaL_checkinteger(L, 5);
     int ret = luat_lcd_draw_line(default_conf, x1,  y1,  x2,  y2, color);
     lua_pushboolean(L, ret == 0 ? 1 : 0);
-    return 0;
+    return 1;
 }
 
 /*
@@ -347,7 +358,7 @@ static int l_lcd_draw_rectangle(lua_State* L) {
         color = (uint32_t)luaL_checkinteger(L, 5);
     int ret = luat_lcd_draw_rectangle(default_conf, x1,  y1,  x2,  y2, color);
     lua_pushboolean(L, ret == 0 ? 1 : 0);
-    return 0;
+    return 1;
 }
 
 /*
@@ -370,7 +381,7 @@ static int l_lcd_draw_circle(lua_State* L) {
         color = (uint32_t)luaL_checkinteger(L, 4);
     int ret = luat_lcd_draw_circle(default_conf, x0,  y0,  r, color);
     lua_pushboolean(L, ret == 0 ? 1 : 0);
-    return 0;
+    return 1;
 }
 
 static int l_lcd_set_default(lua_State *L) {
@@ -379,7 +390,7 @@ static int l_lcd_set_default(lua_State *L) {
         lua_pushboolean(L, 1);
         return 1;
     }
-    return 0;
+    return 1;
 }
 
 #include "rotable.h"

+ 1 - 1
components/lvgl/binding/luat_lib_lvgl7.c

@@ -59,7 +59,7 @@ int luat_lv_init(lua_State *L) {
     LLOGD("w %d h %d buff %d", w, h, fbuff_size);
 
     if (lua_isuserdata(L, 3)) {
-        luat_zbuff *zbuff = tozbuff(L);
+        luat_zbuff_t *zbuff = tozbuff(L);
         fbuffer = (lv_color_t *)zbuff->addr;
         fbuff_size = zbuff->len / sizeof(lv_color_t);
     }

+ 1 - 1
components/lvgl/binding/luat_lib_lvgl_img.c

@@ -12,7 +12,7 @@ int luat_lv_img_set_src(lua_State *L) {
     if (lua_isstring(L, 2))
         src_img = (void*)luaL_checkstring(L, 2);
     else if (lua_isuserdata(L, 2)) {
-        luat_zbuff* buff = (luat_zbuff *)luaL_checkudata(L, 1, "ZBUFF*");
+        luat_zbuff_t* buff = (luat_zbuff_t *)luaL_checkudata(L, 1, "ZBUFF*");
         src_img = buff->addr;
     }
     else {

+ 1 - 1
components/lvgl/binding/luat_lib_lvgl_imgbtn.c

@@ -14,7 +14,7 @@ int luat_lv_imgbtn_set_src(lua_State *L) {
     if (lua_isstring(L, 3))
         src = (void*)luaL_checkstring(L, 3);
     else if (lua_isuserdata(L, 3)) {
-        luat_zbuff* buff = (luat_zbuff *)luaL_checkudata(L, 1, "ZBUFF*");
+        luat_zbuff_t* buff = (luat_zbuff_t *)luaL_checkudata(L, 1, "ZBUFF*");
         src = buff->addr;
     }
     else {

+ 1 - 1
components/lvgl/binding/luat_lib_lvgl_struct.c

@@ -409,7 +409,7 @@ int _lvgl_struct_img_dsc_t_newindex(lua_State *L) {
         img_dsc_t->data_size = luaL_optinteger(L, 3, 0);
     }
     else if (!strcmp("data", key)) {
-        luat_zbuff* cbuff = (luat_zbuff *)luaL_checkudata(L, 3, "ZBUFF*");
+        luat_zbuff_t* cbuff = (luat_zbuff_t *)luaL_checkudata(L, 3, "ZBUFF*");
         img_dsc_t->data = cbuff->addr;
     }
     else if (!strcmp("header_cf", key)) {

+ 4 - 4
components/sfd/luat_sfd_mem.c

@@ -34,7 +34,7 @@ static int sfd_mem_init (void* userdata) {
         return -1;
     }
     sfd_drv_t *drv = (sfd_drv_t*)userdata;
-    luat_zbuff* zbuff = drv->cfg.zbuff;
+    luat_zbuff_t* zbuff = drv->cfg.zbuff;
     if (zbuff->len < 16*1024) {
         LLOGE("zbuff for sfd_mem is too small");
         return -1;
@@ -54,7 +54,7 @@ static int sfd_mem_read (void* userdata, char* buff, size_t offset, size_t len)
         return -1;
     }
     sfd_drv_t *drv = (sfd_drv_t*)userdata;
-    luat_zbuff* zbuff = drv->cfg.zbuff;
+    luat_zbuff_t* zbuff = drv->cfg.zbuff;
     if (offset > zbuff->len) {
         // LLOGD("over read");
         return 0;
@@ -73,7 +73,7 @@ static int sfd_mem_write (void* userdata, const char* buff, size_t offset, size_
         return -1;
     }
     sfd_drv_t *drv = (sfd_drv_t*)userdata;
-    luat_zbuff* zbuff = drv->cfg.zbuff;
+    luat_zbuff_t* zbuff = drv->cfg.zbuff;
     if (offset > zbuff->len) {
         // LLOGD("over read");
         return 0;
@@ -92,7 +92,7 @@ static int sfd_mem_erase (void* userdata, size_t offset, size_t len) {
         return -1;
     }
     sfd_drv_t *drv = (sfd_drv_t*)userdata;
-    luat_zbuff* zbuff = drv->cfg.zbuff;
+    luat_zbuff_t* zbuff = drv->cfg.zbuff;
     if (offset > zbuff->len) {
         // LLOGD("over read");
         return 0;

+ 49 - 0
lua/src/liolib.c

@@ -795,6 +795,55 @@ static int io_writeFile (lua_State *L) {
   return 1;
 }
 
+#ifdef LUAT_USE_ZBUFF
+#include "luat_zbuff.h"
+/*
+读取文件并填充到zbuff内
+@api io.fill(buff, offset, len)
+@userdata zbuff实体
+@int 写入的位置,默认是0
+@int 写入的长度,默认是zbuff的len减去offset
+@return 成功返回true,否则返回false
+@usage
+local buff = zbuff.create(1024)
+local f = io.open("/sd/test.txt")
+if f then
+  f:fill(buff)
+end
+*/
+static int f_fill(lua_State *L) {
+  FILE* f = tofile(L);
+  luat_zbuff_t* buff;
+  int offset;
+  int len;
+  if (!lua_isuserdata(L, 2)) {
+    return 0;
+  }
+  if (f == NULL)
+    return 0;
+  buff = luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE);
+  if (lua_isinteger(L, 3)) {
+    offset = luaL_checkinteger(L, 3);
+  }
+  else {
+    offset = 0;
+  }
+  if (lua_isinteger(L, 4)) {
+    len = luaL_checkinteger(L, 4);
+    if (len > buff->len)
+      len = buff->len;
+    if (offset + len > buff->len)
+      len = len - offset;
+  }
+  else {
+    len = buff->len - offset;
+  }
+  len = fread(buff->addr + offset, 1, len, f);
+  lua_pushboolean(L, len >= 0 ? 1 : 0);
+  return 1;
+}
+#endif
+
 /*
 ** functions for 'io' library
 */

+ 1 - 1
luat/include/luat_sdio.h

@@ -13,4 +13,4 @@ int luat_sdio_sd_read(int id, int rca, char* buff, size_t offset, size_t len);
 int luat_sdio_sd_write(int id, int rca, char* buff, size_t offset, size_t len);
 int luat_sdio_sd_mount(int id, int *rca, char* path,int auto_format);
 int luat_sdio_sd_unmount(int id, int rca);
-int luat_sdio_sd_format(int id, int rca);
+int luat_sdio_sd_format(int id, int rca);

+ 1 - 1
luat/include/luat_sfd.h

@@ -22,7 +22,7 @@ typedef struct sfd_drv {
             int id;
             int cs;
         } spi;
-        luat_zbuff* zbuff;
+        luat_zbuff_t* zbuff;
     } cfg;
     size_t sector_size;
     size_t sector_count;

+ 2 - 2
luat/include/luat_zbuff.h

@@ -4,7 +4,7 @@
 #include "luat_msgbus.h"
 
 #define LUAT_ZBUFF_TYPE "ZBUFF*"
-#define tozbuff(L) ((luat_zbuff *)luaL_checkudata(L, 1, LUAT_ZBUFF_TYPE))
+#define tozbuff(L) ((luat_zbuff_t *)luaL_checkudata(L, 1, LUAT_ZBUFF_TYPE))
 
 #define ZBUFF_SEEK_SET 0
 #define ZBUFF_SEEK_CUR 1
@@ -16,6 +16,6 @@ typedef struct luat_zbuff {
     uint32_t width; //宽度
     uint32_t height;//高度
     uint8_t bit;    //色深度
-} luat_zbuff;
+} luat_zbuff_t;
 
 #endif

+ 76 - 25
luat/modules/luat_lib_sdio.c

@@ -7,6 +7,7 @@
 */
 #include "luat_base.h"
 #include "luat_sdio.h"
+#include "luat_malloc.h"
 
 #define SDIO_COUNT 2
 static luat_sdio_t sdio_t[SDIO_COUNT];
@@ -14,11 +15,11 @@ static luat_sdio_t sdio_t[SDIO_COUNT];
 /**
 初始化sdio
 @api sdio.init(id)
-@int 通道id,与具体设备有关,通常从0开始
+@int 通道id,与具体设备有关,通常从0开始,默认0
 @return boolean 打开结果
  */
 static int l_sdio_init(lua_State *L) {
-    if (luat_sdio_init(luaL_checkinteger(L, 1)) == 0) {
+    if (luat_sdio_init(luaL_optinteger(L, 1, 0)) == 0) {
         lua_pushboolean(L, 1);
     }
     else {
@@ -27,10 +28,25 @@ static int l_sdio_init(lua_State *L) {
     return 1;
 }
 
+/*
+直接读写sd卡上的数据
+@api sdio.sd_read(id, offset, len)
+@int sdio总线id
+@int 偏移量,必须是512的倍数
+@int 长度,必须是512的倍数
+@return string 若读取成功,返回字符串,否则返回nil
+@usage
+-- 初始化sdio并直接读取sd卡数据
+sdio.init(0)
+local t = sdio.sd_read(0, 0, 1024)
+if t then
+    --- xxx
+end
+*/
 static int l_sdio_read(lua_State *L) {
     int id = luaL_checkinteger(L, 1);
-    int len = luaL_checkinteger(L, 2);
-    int offset = luaL_checkinteger(L, 3);
+    int offset = luaL_checkinteger(L, 2);
+    int len = luaL_checkinteger(L, 3);
     char* recv_buff = luat_heap_malloc(len);
     if(recv_buff == NULL)
         return 0;
@@ -44,16 +60,28 @@ static int l_sdio_read(lua_State *L) {
     return 0;
 }
 
+/*
+直接写sd卡
+@api sdio.sd_write(id, data, offset)
+@int sdio总线id
+@string 待写入的数据,长度必须是512的倍数
+@int 偏移量,必须是512的倍数
+@return bool 若读取成功,返回true,否则返回false
+@usage
+-- 初始化sdio并直接读取sd卡数据
+sdio.init(0)
+local t = sdio.sd_write(0, data, 0)
+if t then
+    --- xxx
+end
+*/
 static int l_sdio_write(lua_State *L) {
     int id = luaL_checkinteger(L, 1);
     size_t len;
     const char* send_buff;
     send_buff = lua_tolstring(L, 2, &len);
     int offset = luaL_checkinteger(L, 3);
-    int ret = luat_sdio_sd_write(id, sdio_t[id].rca, send_buff, offset, len);
-    char* recv_buff = luat_heap_malloc(len);
-    if(recv_buff == NULL)
-        return 0;
+    int ret = luat_sdio_sd_write(id, sdio_t[id].rca, (char*)send_buff, offset, len);
     if (ret > 0) {
         lua_pushboolean(L, 1);
     }
@@ -61,38 +89,61 @@ static int l_sdio_write(lua_State *L) {
     return 1;
 }
 
-
+/*
+挂载SD卡, 使用FATFS文件系统
+@api sdio.sd_mount(id, path, auto_format)
+@int sdio总线id
+@string 挂载路径, 默认"/sd", 不允许以"/"结尾
+@bool 是否自动格式化,默认是true
+@return bool 挂载成功返回true,否则返回false
+*/
 static int l_sdio_sd_mount(lua_State *L) {
-    int id = luaL_checkinteger(L, 1);
-    char* path = luaL_checkstring(L, 2);
-    int auto_format = luaL_checkinteger(L, 3);
-    luat_sdio_sd_mount(id, sdio_t[id].rca, path,auto_format);
-    return 0;
+    int id = luaL_optinteger(L, 1, 0);
+    const char* path = luaL_optstring(L, 2, "/sd");
+    int auto_format = luaL_optinteger(L, 3, 1);
+    int ret = luat_sdio_sd_mount(id, &sdio_t[id].rca, (char*)path, auto_format);
+    lua_pushboolean(L, ret == 0 ? 1: 0);
+    return 1;
 }
 
+/*
+卸载SD卡(视硬件情况, 不一定支持)
+@api sdio.sd_unmount(id, path)
+@int sdio总线id
+@string 挂载路径, 默认"/sd", 不允许以"/"结尾
+@return bool 挂载成功返回true,否则返回false
+*/
 static int l_sdio_sd_umount(lua_State *L) {
     int id = luaL_checkinteger(L, 1);
-    int auto_format = luaL_checkinteger(L, 2);
-    luat_sdio_sd_unmount(id, sdio_t[id].rca);
-    return 0;
+    //int auto_format = luaL_checkinteger(L, 2);
+    int ret = luat_sdio_sd_unmount(id, sdio_t[id].rca);
+    lua_pushboolean(L, ret == 0 ? 1: 0);
+    return 1;
 }
 
+/*
+格式化SD卡
+@api sdio.sd_format(id)
+@int sdio总线id
+@return bool 挂载成功返回true,否则返回false
+*/
 static int l_sdio_sd_format(lua_State *L) {
     int id = luaL_checkinteger(L, 1);
-    int auto_format = luaL_checkinteger(L, 2);
-    luat_sdio_sd_format(id, sdio_t[id].rca);
-    return 0;
+    //int auto_format = luaL_checkinteger(L, 2);
+    int ret = luat_sdio_sd_format(id, sdio_t[id].rca);
+    lua_pushboolean(L, ret == 0 ? 1: 0);
+    return 1;
 }
 
 #include "rotable.h"
 static const rotable_Reg reg_sdio[] =
 {
     { "init" ,       l_sdio_init , 0},
-    { "read" ,       l_sdio_read , 0},
-    { "write" ,      l_sdio_write, 0},
-    { "mount" ,      l_sdio_sd_mount, 0},
-    { "umount" ,     l_sdio_sd_umount, 0},
-    { "format" ,     l_sdio_sd_format, 0},
+    { "sd_read" ,       l_sdio_read , 0},
+    { "sd_write" ,      l_sdio_write, 0},
+    { "sd_mount" ,      l_sdio_sd_mount, 0},
+    { "sd_umount" ,     l_sdio_sd_umount, 0},
+    { "sd_format" ,     l_sdio_sd_format, 0},
 	{ NULL,          NULL ,       0}
 };
 

+ 1 - 1
luat/modules/luat_lib_sensor.c

@@ -435,7 +435,7 @@ static int l_sensor_ws2812b(lua_State *L)
   int pin = luaL_checkinteger(L, 1);
   if (lua_isuserdata(L, 2))
   {
-    luat_zbuff *buff = ((luat_zbuff *)luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE));
+    luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE));
     send_buff = buff->addr;
     len = buff->len;
   }

+ 2 - 2
luat/modules/luat_lib_spi.c

@@ -85,7 +85,7 @@ static int l_spi_transfer(lua_State *L) {
     size_t len;
     const char* send_buff;
     if(lua_isuserdata(L, 2)){//zbuff对象特殊处理
-        luat_zbuff *buff = ((luat_zbuff *)luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE));
+        luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE));
         send_buff = buff->addr+buff->cursor;
         len = buff->len - buff->cursor;
     }else{
@@ -161,7 +161,7 @@ static int l_spi_send(lua_State *L) {
     size_t len;
     const char* send_buff;
     if(lua_isuserdata(L, 2)){//zbuff对象特殊处理
-        luat_zbuff *buff = ((luat_zbuff *)luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE));
+        luat_zbuff_t *buff = ((luat_zbuff_t *)luaL_checkudata(L, 2, LUAT_ZBUFF_TYPE));
         send_buff = buff->addr+buff->cursor;
         len = buff->len - buff->cursor;
     }else{

+ 25 - 23
luat/modules/luat_lib_zbuff.c

@@ -12,7 +12,7 @@
 #include "luat_log.h"
 
 //在buff对象后添加数据,返回增加的字节数
-int add_bytes(luat_zbuff *buff, const char *source, size_t len)
+int add_bytes(luat_zbuff_t *buff, const char *source, size_t len)
 {
     if (buff->len - buff->cursor < len)
         len = buff->len - buff->cursor;
@@ -74,7 +74,7 @@ int add_bytes(luat_zbuff *buff, const char *source, size_t len)
         return GET_POINT_##n(buff, point); \
         break
 //获取某点的颜色
-uint32_t get_framebuffer_point(luat_zbuff *buff,uint32_t point)
+uint32_t get_framebuffer_point(luat_zbuff_t *buff,uint32_t point)
 {
     switch (buff->bit)
     {
@@ -87,6 +87,7 @@ uint32_t get_framebuffer_point(luat_zbuff *buff,uint32_t point)
     default:
         break;
     }
+    return 0;
 }
 
 /**
@@ -133,7 +134,7 @@ static int l_zbuff_create(lua_State *L)
     if (len <= 0)
         return 0;
 
-    luat_zbuff *buff = (luat_zbuff *)lua_newuserdata(L, sizeof(luat_zbuff));
+    luat_zbuff_t *buff = (luat_zbuff_t *)lua_newuserdata(L, sizeof(luat_zbuff_t));
     if (buff == NULL)
     {
         return 0;
@@ -203,8 +204,9 @@ static int l_zbuff_write(lua_State *L)
 {
     if (lua_isinteger(L, 2))
     {
-        int len = 0, data;
-        luat_zbuff *buff = tozbuff(L);
+        int len = 0;
+        int data = 0;
+        luat_zbuff_t *buff = tozbuff(L);
         while (lua_isinteger(L, 2 + len) && buff->cursor < buff->len)
         {
             data = luaL_checkinteger(L, 2 + len);
@@ -219,7 +221,7 @@ static int l_zbuff_write(lua_State *L)
     {
         size_t len;
         const char *data = luaL_checklstring(L, 2, &len);
-        luat_zbuff *buff = tozbuff(L);
+        luat_zbuff_t *buff = tozbuff(L);
         if (len + buff->cursor > buff->len) //防止越界
         {
             len = buff->len - buff->cursor;
@@ -242,7 +244,7 @@ local str = buff:read(3)
  */
 static int l_zbuff_read(lua_State *L)
 {
-    luat_zbuff *buff = tozbuff(L);
+    luat_zbuff_t *buff = tozbuff(L);
     int read_num = luaL_optinteger(L, 2, 1);
     if (read_num > buff->len - buff->cursor) //防止越界
     {
@@ -277,7 +279,7 @@ buff:seek(-3,zbuff.SEEK_END)
  */
 static int l_zbuff_seek(lua_State *L)
 {
-    luat_zbuff *buff = tozbuff(L);
+    luat_zbuff_t *buff = tozbuff(L);
 
     int offset = luaL_checkinteger(L, 2);
     int whence = luaL_optinteger(L, 3, ZBUFF_SEEK_SET);
@@ -395,7 +397,7 @@ buff:pack(">IIHA", 0x1234, 0x4567, 0x12,"abcdefg") -- 按格式写入几个数
 
 static int l_zbuff_pack(lua_State *L)
 {
-    luat_zbuff *buff = tozbuff(L);
+    luat_zbuff_t *buff = tozbuff(L);
     int i = 3;
     char *f = (char *)luaL_checkstring(L, 2);
     int swap = 0;
@@ -497,7 +499,7 @@ local cnt,a,b,c,s = buff:unpack(">IIHA10") -- 按格式读取几个数据
  */
 static int l_zbuff_unpack(lua_State *L)
 {
-    luat_zbuff *buff = tozbuff(L);
+    luat_zbuff_t *buff = tozbuff(L);
     char *f = (char *)luaL_checkstring(L, 2);
     size_t len = buff->len - buff->cursor;
     const char *s = buff->addr + buff->cursor;
@@ -580,7 +582,7 @@ local data = buff:readU32()
 #define zread(n, t, f)                                       \
     static int l_zbuff_read_##n(lua_State *L)                \
     {                                                        \
-        luat_zbuff *buff = tozbuff(L);                       \
+        luat_zbuff_t *buff = tozbuff(L);                       \
         if (buff->len - buff->cursor < sizeof(t))            \
             return 0;                                        \
         lua_push##f(L, *((t *)(buff->addr + buff->cursor))); \
@@ -611,7 +613,7 @@ local len = buff:writeU32(1024)
 #define zwrite(n, t, f)                                               \
     static int l_zbuff_write_##n(lua_State *L)                        \
     {                                                                 \
-        luat_zbuff *buff = tozbuff(L);                                \
+        luat_zbuff_t *buff = tozbuff(L);                                \
         if (buff->len - buff->cursor < sizeof(t))                     \
         {                                                             \
             lua_pushinteger(L, 0);                                    \
@@ -644,7 +646,7 @@ local s = buff:toStr(0,5)--读取开头的五个字节数据
  */
 static int l_zbuff_toStr(lua_State *L)
 {
-    luat_zbuff *buff = tozbuff(L);
+    luat_zbuff_t *buff = tozbuff(L);
     int start = luaL_optinteger(L, 2, 0);
     if (start > buff->len)
         start = buff->len;
@@ -665,7 +667,7 @@ len = #buff
  */
 static int l_zbuff_len(lua_State *L)
 {
-    luat_zbuff *buff = tozbuff(L);
+    luat_zbuff_t *buff = tozbuff(L);
     lua_pushinteger(L, buff->len);
     return 1;
 }
@@ -683,7 +685,7 @@ result = buff:setFrameBuffer(320,240,16,0xffff)
  */
 static int l_zbuff_set_frame_buffer(lua_State *L)
 {
-    luat_zbuff *buff = tozbuff(L);
+    luat_zbuff_t *buff = tozbuff(L);
     //检查空间够不够
     if((luaL_checkinteger(L, 2) * luaL_checkinteger(L, 3) * luaL_checkinteger(L, 4) - 1) / 8 + 1 > buff->len)
         return 0;
@@ -714,7 +716,7 @@ color = buff:pixel(0,3)
  */
 static int l_zbuff_pixel(lua_State *L)
 {
-    luat_zbuff *buff = tozbuff(L);
+    luat_zbuff_t *buff = tozbuff(L);
     uint32_t x = luaL_checkinteger(L,2);
     uint32_t y = luaL_checkinteger(L,3);
     if(x>=buff->width||y>=buff->height)
@@ -748,7 +750,7 @@ rerult = buff:drawLine(0,0,2,3,0xffff)
 #define abs(n) (n>0?n:-n)
 static int l_zbuff_draw_line(lua_State *L)
 {
-    luat_zbuff *buff = tozbuff(L);
+    luat_zbuff_t *buff = tozbuff(L);
     if(buff->width<=0) return 0;//不是framebuffer数据
     uint32_t x0 = luaL_checkinteger(L,2);
     uint32_t y0 = luaL_checkinteger(L,3);
@@ -794,7 +796,7 @@ rerult = buff:drawRect(0,0,2,3,0xffff)
 #define CHECK0(n,max) if(n<0)n=0;if(n>=max)n=max-1
 static int l_zbuff_draw_rectangle(lua_State *L)
 {
-    luat_zbuff *buff = tozbuff(L);
+    luat_zbuff_t *buff = tozbuff(L);
     if(buff->width<=0) return 0;//不是framebuffer数据
     uint32_t x1 = luaL_checkinteger(L,2);  CHECK0(x1,buff->width);
     uint32_t y1 = luaL_checkinteger(L,3);  CHECK0(y1,buff->height);
@@ -856,7 +858,7 @@ rerult = buff:drawCircle(15,5,3,0xC,true)
     }
 static int l_zbuff_draw_circle(lua_State *L)
 {
-    luat_zbuff *buff = tozbuff(L);
+    luat_zbuff_t *buff = tozbuff(L);
     if(buff->width<=0) return 0;//不是framebuffer数据
     uint32_t xc = luaL_checkinteger(L,2);
     uint32_t yc = luaL_checkinteger(L,3);
@@ -909,7 +911,7 @@ local data = buff[0]
  */
 static int l_zbuff_index(lua_State *L)
 {
-    luat_zbuff **pp = luaL_checkudata(L, 1, LUAT_ZBUFF_TYPE);
+    luat_zbuff_t **pp = luaL_checkudata(L, 1, LUAT_ZBUFF_TYPE);
     int i;
 
     luaL_getmetatable(L, LUAT_ZBUFF_TYPE);
@@ -919,7 +921,7 @@ static int l_zbuff_index(lua_State *L)
     if (lua_isnil(L, -1))
     {
         /* found no method, so get value from userdata. */
-        luat_zbuff *buff = tozbuff(L);
+        luat_zbuff_t *buff = tozbuff(L);
         int o = luaL_checkinteger(L, 2);
         if (o > buff->len)
             return 0;
@@ -933,7 +935,7 @@ static int l_zbuff_newindex(lua_State *L)
 {
     if (lua_isinteger(L, 2))
     {
-        luat_zbuff *buff = tozbuff(L);
+        luat_zbuff_t *buff = tozbuff(L);
         if (lua_isinteger(L, 2))
         {
             int o = luaL_checkinteger(L, 2);
@@ -949,7 +951,7 @@ static int l_zbuff_newindex(lua_State *L)
 // __gc
 static int l_zbuff_gc(lua_State *L)
 {
-    luat_zbuff *buff = tozbuff(L);
+    luat_zbuff_t *buff = tozbuff(L);
     luat_heap_free(buff->addr);
     return 0;
 }