Browse Source

fix: macOS build support (x64/arm64) and compatibility improvements

dcboy 3 months ago
parent
commit
b2748e60e9

+ 5 - 0
bsp/pc/build_macos.sh

@@ -0,0 +1,5 @@
+xmake clean -a
+export VM_64bit=1
+export LUAT_USE_GUI=n
+xmake f -p macosx -y
+xmake -w -y

+ 5 - 0
bsp/pc/build_macos_gui.sh

@@ -0,0 +1,5 @@
+xmake clean -a
+export VM_64bit=1
+export LUAT_USE_GUI=y
+xmake f -p macosx -y
+xmake -w -y

+ 15 - 5
bsp/pc/ffmpeg_x86/ffmpeg.c

@@ -1,4 +1,5 @@
-#include "ffmpeg.h"
+#include "ffmpeg.h"
+#include <libavutil/opt.h>
 
 #ifdef _WIN32
 // FFmpeg DLL句柄定义 (仅Windows)
@@ -202,7 +203,12 @@ int luat_ffmpeg_play_file(const char *path) {
 
     // 确保 channel_layout 已设置
     if (!codec_ctx->channel_layout) {
+#ifdef _WIN32
         codec_ctx->channel_layout = av_get_default_channel_layout(codec_ctx->channels);
+#else
+        if (codec_ctx->channels == 1) codec_ctx->channel_layout = AV_CH_LAYOUT_MONO;
+        else codec_ctx->channel_layout = AV_CH_LAYOUT_STEREO;
+#endif
     }
 
     // 打开解码器
@@ -217,15 +223,19 @@ int luat_ffmpeg_play_file(const char *path) {
     enum AVSampleFormat out_sample_fmt = AV_SAMPLE_FMT_S16;
     int out_sample_rate = 44100;
 
-    swr_ctx = swr_alloc_set_opts(NULL,
-                                  out_ch_layout, out_sample_fmt, out_sample_rate,
-                                  codec_ctx->channel_layout, codec_ctx->sample_fmt, codec_ctx->sample_rate,
-                                  0, NULL);
+    swr_ctx = swr_alloc();
     if (!swr_ctx) {
         avcodec_free_context(&codec_ctx);
         avformat_close_input(&fmt_ctx);
         return -1;
     }
+    
+    av_opt_set_int(swr_ctx, "in_channel_layout",    codec_ctx->channel_layout, 0);
+    av_opt_set_int(swr_ctx, "in_sample_rate",       codec_ctx->sample_rate, 0);
+    av_opt_set_sample_fmt(swr_ctx, "in_sample_fmt", codec_ctx->sample_fmt, 0);
+    av_opt_set_int(swr_ctx, "out_channel_layout",   out_ch_layout, 0);
+    av_opt_set_int(swr_ctx, "out_sample_rate",      out_sample_rate, 0);
+    av_opt_set_sample_fmt(swr_ctx, "out_sample_fmt", out_sample_fmt, 0);
 
     // 初始化重采样器
     if (swr_init(swr_ctx) < 0) {

+ 2 - 1
bsp/pc/port/luat_cmds.c

@@ -5,6 +5,7 @@
 #include "lundump.h"
 #include "luat_mock.h"
 #include "luat_luadb2.h"
+#include <stdlib.h>
 
 #define LUAT_LOG_TAG "fs"
 #include "luat_log.h"
@@ -444,7 +445,7 @@ void *check_file_path(const char *path)
 		memcpy(buff, path, strlen(path));
 		#else
 		memcpy(buff, path, strlen(path) - 1);
-		#endif;
+		#endif
 		dp = opendir(buff);
 		// LLOGD("目录打开 %p", dp);
 		if (dp != NULL)

+ 32 - 31
bsp/pc/port/network/luat_network_adapter_libuv.c

@@ -148,7 +148,7 @@ static void cb_nw_task_async(uv_async_t *async) {
     free_uv_handle(async);
 }
 
-static void cb_to_nw_task(uint32_t event_id, uint32_t param1, uint32_t param2, uint32_t param3)
+static void cb_to_nw_task(uint32_t event_id, size_t param1, size_t param2, size_t param3)
 {
     int ret = 0;
     task_event_async_t *e = luat_heap_malloc(sizeof(task_event_async_t));
@@ -170,7 +170,7 @@ static void cb_to_nw_task(uint32_t event_id, uint32_t param1, uint32_t param2, u
     luat_network_cb_param_t param = {.tag = 0, .param = NULL};
     if ((e->event.ID > EV_NW_DNS_RESULT))
     {
-        e->event.Param3 = sockets[e->event.Param1].param;
+        e->event.Param3 = (size_t)sockets[e->event.Param1].param;
         param.tag = sockets[e->event.Param1].tag;
     }
     memcpy(&e->param, &param, sizeof(luat_network_cb_param_t));
@@ -181,7 +181,7 @@ static void cb_to_nw_task(uint32_t event_id, uint32_t param1, uint32_t param2, u
 
 static int libuv_set_dns_server(uint8_t server_index, luat_ip_addr_t *ip, void *user_data);
 
-static void libuv_callback_to_nw_task(uint8_t adapter_index, uint32_t event_id, uint32_t param1, uint32_t param2, uint32_t param3);
+static void libuv_callback_to_nw_task(uint8_t adapter_index, uint32_t event_id, size_t param1, size_t param2, size_t param3);
 
 static int libuv_socket_check(int socket_id, uint64_t tag, void *user_data)
 {
@@ -254,7 +254,7 @@ static void on_recv(uv_stream_t *handler,
                     ssize_t nread,
                     const uv_buf_t *buf)
 {
-    int32_t socket_id = (int32_t)handler->data;
+    int32_t socket_id = (int32_t)(intptr_t)handler->data;
     int ret = 0;
     LLOGD("socket[%d] on_recv %d", socket_id, nread);
     // if (sockets[socket_id].state == SC_CLOSED)
@@ -276,7 +276,7 @@ static void on_recv(uv_stream_t *handler,
             if (sockets[socket_id].state != SC_CLOSING && sockets[socket_id].state != SC_CLOSED) {
                 set_socket_state(socket_id, SC_CLOSING);
                 // LLOGD("发送EV_NW_SOCKET_REMOTE_CLOSE消息");
-                cb_to_nw_task(EV_NW_SOCKET_REMOTE_CLOSE, socket_id, 0, sockets[socket_id].param);
+                cb_to_nw_task(EV_NW_SOCKET_REMOTE_CLOSE, socket_id, 0, (size_t)sockets[socket_id].param);
             }
         }
         else
@@ -285,7 +285,7 @@ static void on_recv(uv_stream_t *handler,
             // uv_shutdown()
             set_socket_state(socket_id, SC_CLOSING);
             // LLOGD("发送EV_NW_SOCKET_ERROR消息");
-            cb_to_nw_task(EV_NW_SOCKET_ERROR, socket_id, 0, sockets[socket_id].param);
+            cb_to_nw_task(EV_NW_SOCKET_ERROR, socket_id, 0, (size_t)sockets[socket_id].param);
         }
         // uv_close(handler, on_close);
         return;
@@ -309,7 +309,7 @@ static void on_recv(uv_stream_t *handler,
         if (ptr == NULL)
         {
             LLOGD("socket[%d] 内存不足, 无法存放更多接收到的数据", socket_id);
-            cb_to_nw_task(EV_NW_SOCKET_ERROR, socket_id, 0, sockets[socket_id].param);
+            cb_to_nw_task(EV_NW_SOCKET_ERROR, socket_id, 0, (size_t)sockets[socket_id].param);
             return;
         }
         sockets[socket_id].recv_buff = ptr;
@@ -317,7 +317,7 @@ static void on_recv(uv_stream_t *handler,
         sockets[socket_id].recv_size += nread;
     }
     luat_heap_free(buf->base);
-    cb_to_nw_task(EV_NW_SOCKET_RX_NEW, socket_id, nread, sockets[socket_id].param);
+    cb_to_nw_task(EV_NW_SOCKET_RX_NEW, socket_id, nread, (size_t)sockets[socket_id].param);
     return;
 }
 
@@ -327,7 +327,7 @@ static void on_recv_udp(uv_udp_t *udp,
                         const struct sockaddr *addr,
                         unsigned flags)
 {
-    int32_t socket_id = (int32_t)udp->data;
+    int32_t socket_id = (int32_t)(intptr_t)udp->data;
     LLOGD("socket[%d] UDP接收回调 %d", socket_id, nread);
     if (nread < 0)
     {
@@ -374,14 +374,14 @@ static void on_recv_udp(uv_udp_t *udp,
             head = head->next;
         }
     }
-    cb_to_nw_task(EV_NW_SOCKET_RX_NEW, socket_id, nread, sockets[socket_id].param);
+    cb_to_nw_task(EV_NW_SOCKET_RX_NEW, socket_id, nread, (size_t)sockets[socket_id].param);
     // LLOGD("完成on_recv_udp函数");
 }
 
 static void on_connect(uv_connect_t *req, int status)
 {
     // LLOGD("on_connect %d", status);
-    int32_t socket_id = (int32_t)req->data;
+    int32_t socket_id = (int32_t)(intptr_t)req->data;
     int ret = 0;
     if (status != 0)
     {
@@ -432,7 +432,7 @@ static void udp_connect_async(uv_async_t *async)
     int socket_id = c->socket_id;
     // ret = uv_udp_connect(&sockets[socket_id].udp, (const struct sockaddr *)&c->addr);
     // memcpy(&sockets[socket_id].remote, (const struct sockaddr *)&c->addr, sizeof(const struct sockaddr));
-    on_connect(&sockets[socket_id].udp, ret);
+    on_connect((uv_connect_t*)&sockets[socket_id].udp, ret);
     free_uv_handle(async);
 }
 
@@ -453,7 +453,7 @@ static int libuv_socket_connect(int socket_id, uint64_t tag, uint16_t local_port
     char addr[17] = {'\0'};
     uv_ip4_name(&saddr, addr, 16);
     LLOGI("socket[%d] connect to %s:%d %s", socket_id, addr, remote_port, sockets[socket_id].is_tcp ? "TCP" : "UDP");
-    sockets[socket_id].c.data = (void *)socket_id;
+    sockets[socket_id].c.data = (void *)(intptr_t)socket_id;
     if (sockets[socket_id].is_tcp)
     {
         ret = uv_tcp_connect(&sockets[socket_id].c, &sockets[socket_id].tcp, (const struct sockaddr *)&saddr, on_connect);
@@ -507,7 +507,7 @@ static int libuv_socket_accept(int socket_id, uint64_t tag, luat_ip_addr_t *remo
 
 static void on_close(uv_handle_t *handle)
 {
-    int32_t socket_id = (int32_t)handle->data;
+    int32_t socket_id = (int32_t)(intptr_t)handle->data;
     // LLOGD("on_close %d", socket_id);
     if (socket_id < 0 || socket_id >= MAX_SOCK_NUM)
     {
@@ -521,13 +521,14 @@ static void on_close(uv_handle_t *handle)
     }
     // sockets[socket_id].state = SC_CLOSED;
     set_socket_state(socket_id, SC_CLOSED);
-    cb_to_nw_task(EV_NW_SOCKET_CLOSE_OK, socket_id, 0, sockets[socket_id].param);
+    cb_to_nw_task(EV_NW_SOCKET_CLOSE_OK, socket_id, 0, (size_t)sockets[socket_id].param);
     sockets[socket_id].tag = 0;
 }
 
-static void on_shutdown(uv_shutdown_t *handle)
+static void on_shutdown(uv_shutdown_t *handle, int status)
 {
-    int32_t socket_id = (int32_t)handle->data;
+    (void)status;
+    int32_t socket_id = (int32_t)(intptr_t)handle->data;
     LLOGD("socket[%d] on_shutdown", socket_id);
     if (socket_id < 0 || socket_id >= MAX_SOCK_NUM)
     {
@@ -542,14 +543,14 @@ static void on_shutdown(uv_shutdown_t *handle)
     }
     // sockets[socket_id].state = SC_CLOSED;
     set_socket_state(socket_id, SC_CLOSED);
-    cb_to_nw_task(EV_NW_SOCKET_CLOSE_OK, socket_id, 0, sockets[socket_id].param);
+    cb_to_nw_task(EV_NW_SOCKET_CLOSE_OK, socket_id, 0, (size_t)sockets[socket_id].param);
     sockets[socket_id].tag = 0;
     luat_heap_free(handle);
 }
 
 static void udp_async_close(uv_async_t *handle)
 {
-    int socket_id = (int)handle->data;
+    int socket_id = (int)(intptr_t)handle->data;
     free_uv_handle(handle);
     on_close(&sockets[socket_id].udp);
 }
@@ -575,7 +576,7 @@ static int close_socket(int socket_id, const char *tag)
         if (ret)
             LLOGI("socket[%d] uv_udp_recv_stop %d %s", socket_id, ret, uv_err_name(ret));
         uv_async_t *async = luat_heap_malloc(sizeof(uv_async_t));
-        async->data = (void *)socket_id;
+        async->data = (void *)(intptr_t)socket_id;
         uv_async_init(main_loop, async, udp_async_close);
         ret = uv_async_send(async);
         if (ret) {
@@ -655,7 +656,7 @@ static int libuv_socket_receive(int socket_id, uint64_t tag, uint8_t *buf, uint3
         }
         memcpy(buf, sockets[socket_id].recv_buff, len);
         size_t newsize = sockets[socket_id].recv_size - len;
-        if (newsize == NULL)
+        if (newsize == 0)
         {
             luat_heap_free(sockets[socket_id].recv_buff);
             sockets[socket_id].recv_buff = NULL;
@@ -707,19 +708,19 @@ static void on_sent(uv_write_t *req, int status)
     tmp += sizeof(uv_write_t);
     uint32_t len = 0;
     memcpy(&len, tmp, 4);
-    int socket_id = (int32_t)req->data;
+    int socket_id = (int32_t)(intptr_t)req->data;
     LLOGD("socket[%d] tcp sent %d %d", socket_id, status, len);
     luat_heap_free(req);
 
     if (status == 0)
     {
         // LLOGD("发送成功, 执行TX_OK消息");
-        cb_to_nw_task(EV_NW_SOCKET_TX_OK, socket_id, len, sockets[socket_id].param);
+        cb_to_nw_task(EV_NW_SOCKET_TX_OK, socket_id, len, (size_t)sockets[socket_id].param);
     }
     else
     {
         // LLOGD("发送失败, 执行ERROR消息");
-        cb_to_nw_task(EV_NW_SOCKET_ERROR, socket_id, 0, sockets[socket_id].param);
+        cb_to_nw_task(EV_NW_SOCKET_ERROR, socket_id, 0, (size_t)sockets[socket_id].param);
     }
 }
 
@@ -735,12 +736,12 @@ static void on_sent_udp(uv_udp_send_t *req, int status)
     if (status == 0)
     {
         // LLOGD("发送成功, 执行TX_OK消息");
-        cb_to_nw_task(EV_NW_SOCKET_TX_OK, socket_id, len, sockets[socket_id].param);
+        cb_to_nw_task(EV_NW_SOCKET_TX_OK, socket_id, len, (size_t)sockets[socket_id].param);
     }
     else
     {
         // LLOGD("发送成功, 执行ERROR消息");
-        cb_to_nw_task(EV_NW_SOCKET_ERROR, socket_id, 0, sockets[socket_id].param);
+        cb_to_nw_task(EV_NW_SOCKET_ERROR, socket_id, 0, (size_t)sockets[socket_id].param);
     }
     luat_heap_free(req);
 }
@@ -778,7 +779,7 @@ static int libuv_socket_send(int socket_id, uint64_t tag, const uint8_t *buf, ui
         tmp = (char *)req;
         tmp += sizeof(uv_write_t);
         memcpy(tmp, &len, 4);
-        req->data = (void *)socket_id;
+        req->data = (void *)(intptr_t)socket_id;
         ret = uv_write(req, (uv_stream_t *)&sockets[socket_id].tcp, &buff, 1, on_sent);
         if (ret) {
             luat_heap_free(req);
@@ -792,7 +793,7 @@ static int libuv_socket_send(int socket_id, uint64_t tag, const uint8_t *buf, ui
         tmp = (char *)send_req;
         tmp += sizeof(uv_udp_send_t);
         memcpy(tmp, &len, 4);
-        send_req->data = (void *)socket_id;
+        send_req->data = (void *)(intptr_t)socket_id;
         #ifdef LUAT_USE_LWIP
         send_addr.sin_addr.s_addr = ip_2_ip4(remote_ip)->addr;
         #else
@@ -909,7 +910,7 @@ static void on_resolved(uv_getaddrinfo_t *resolver, int status, struct addrinfo
     if (status < 0)
     {
         LLOGI("dns query failed %s", query->domain);
-        cb_to_nw_task(EV_NW_DNS_RESULT, 0, 0, query->param);
+        cb_to_nw_task(EV_NW_DNS_RESULT, 0, 0, (size_t)query->param);
         luat_heap_free(query);
         return;
     }
@@ -920,7 +921,7 @@ static void on_resolved(uv_getaddrinfo_t *resolver, int status, struct addrinfo
     luat_dns_ip_result *ip_result = zalloc(sizeof(luat_dns_ip_result));
     network_set_ip_ipv4(&ip_result->ip, ((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr);
     ip_result->ttl_end = 60;
-    cb_to_nw_task(EV_NW_DNS_RESULT, 1, (int)ip_result, query->param);
+    cb_to_nw_task(EV_NW_DNS_RESULT, 1, (size_t)ip_result, (size_t)query->param);
     luat_heap_free(query);
     uv_freeaddrinfo(res);
 }
@@ -951,7 +952,7 @@ static int libuv_dns(const char *domain_name, uint32_t len, void *param, void *u
     {
         LLOGI("uv_getaddrinfo %d", r);
         luat_heap_free(query);
-        cb_to_nw_task(EV_NW_DNS_RESULT, 0, 0, param);
+        cb_to_nw_task(EV_NW_DNS_RESULT, 0, 0, (size_t)param);
     }
     return r;
 }

+ 9 - 1
bsp/pc/xmake.lua

@@ -57,6 +57,7 @@ elseif is_host("macos") then
 end
 
 
+add_includedirs(luatos.."components/mbedtls3/include",{public = true})
 add_includedirs("include",{public = true})
 add_includedirs(luatos.."lua/include",{public = true})
 add_includedirs(luatos.."luat/include",{public = true})
@@ -79,10 +80,15 @@ target("luatos-lua")
     -- add_files(luatos.."luat/modules/*.c")
 
     if is_plat("linux", "macosx") then
+        add_linkdirs("/opt/homebrew/lib", "/usr/local/lib")
         add_links("pthread", "m", "dl")
         add_links("avformat", "avcodec", "avutil", "swresample")    -- FFmpeg
     end
 
+    -- i2c-tools
+    add_includedirs(luatos.."components/i2c-tools")
+    add_files(luatos.."components/i2c-tools/*.c")
+    
     add_files(luatos.."luat/modules/luat_base.c"
             ,luatos.."luat/modules/luat_lib_fs.c"
             ,luatos.."luat/modules/luat_lib_rtos.c"
@@ -99,7 +105,9 @@ target("luatos-lua")
             ,luatos.."luat/modules/luat_lib_rtc.c"
             ,luatos.."luat/modules/luat_lib_gpio.c"
             ,luatos.."luat/modules/luat_lib_spi.c"
+            ,luatos.."luat/modules/luat_lib_softspi.c"
             ,luatos.."luat/modules/luat_lib_i2c.c"
+            ,luatos.."luat/modules/luat_lib_softi2c.c"
             ,luatos.."luat/modules/luat_lib_i2s.c"
             ,luatos.."luat/modules/luat_lib_wdt.c"
             ,luatos.."luat/modules/luat_lib_pm.c"
@@ -197,7 +205,7 @@ target("luatos-lua")
     add_files(luatos.."components/mobile/*.c")
 
     --ffmpeg
-    add_includedirs("ffmpeg_x86/include")
+    -- add_includedirs("ffmpeg_x86/include")
     add_includedirs("ffmpeg_x86")
     add_files("ffmpeg_x86/ffmpeg.c")
 

+ 3 - 3
components/common/c_common.h

@@ -285,9 +285,9 @@ typedef uint64_t LongInt;
 typedef struct
 {
 	uint32_t ID;
-	uint32_t Param1;
-	uint32_t Param2;
-	uint32_t Param3;
+	size_t Param1;
+	size_t Param2;
+	size_t Param3;
 }OS_EVENT;
 
 typedef struct

+ 4 - 4
components/i2c-tools/i2c_tools.c

@@ -13,14 +13,14 @@ void i2c_tools(const char * data,size_t len){
     if (memcmp("send", command, 4) == 0){
         int i2c_id = atoi(strtok(NULL, " "));
         i2c_init(i2c_id,0);
-        uint8_t address = strtonum(strtok(NULL, " "));
+        uint8_t address = i2c_tools_strtonum(strtok(NULL, " "));
         uint8_t send_buff[16];
         uint8_t len = 0;
         while (1){
             char* buff = strtok(NULL, " ");
             if (buff == NULL)
                 break;
-            send_buff[len] = strtonum(buff);
+            send_buff[len] = i2c_tools_strtonum(buff);
             len++;
         }
         if(i2c_write(address, send_buff, len)!=1){
@@ -29,8 +29,8 @@ void i2c_tools(const char * data,size_t len){
     }else if(memcmp("recv",command,4) == 0){
         int i2c_id = atoi(strtok(NULL, " "));
         i2c_init(i2c_id,0);
-        uint8_t address = strtonum(strtok(NULL, " "));
-        uint8_t reg = strtonum(strtok(NULL, " "));
+        uint8_t address = i2c_tools_strtonum(strtok(NULL, " "));
+        uint8_t reg = i2c_tools_strtonum(strtok(NULL, " "));
         uint8_t len = atoi(strtok(NULL, " "));
         if (len == 0)len = 1;
         uint8_t *buffer = (uint8_t *)luat_heap_malloc(len);

+ 1 - 1
components/i2c-tools/i2c_utils.c

@@ -10,7 +10,7 @@
 
 static uint8_t i2c_tools_id = 0;
 
-uint8_t strtonum(const char* str){
+uint8_t i2c_tools_strtonum(const char* str){
     uint8_t data;
     if (strcmp(str, "0x")){
         data = (uint8_t)strtol(str, NULL, 0);

+ 1 - 1
components/i2c-tools/i2c_utils.h

@@ -6,7 +6,7 @@
 
 #define I2C_TOOLS_BUFFER_SIZE 64
 
-uint8_t strtonum(const char* str);
+uint8_t i2c_tools_strtonum(const char* str);
 
 void i2c_help(void);
 uint8_t i2c_init(const uint8_t i2c_id, int speed);

+ 1 - 0
components/mobile/luat_mobile_common.c

@@ -1,4 +1,5 @@
 #include "luat_base.h"
+#include "luat_malloc.h"
 #include "luat_mobile.h"
 #include "luat_rtos.h"
 #include "luat_fs.h"

+ 1 - 1
components/network/adapter/luat_lib_socket.c

@@ -1305,7 +1305,7 @@ static int l_socket_remote_ip(lua_State *L)
 		lua_pushfstring(L, "%s", ipaddr_ntoa(&ctrl->netc->dns_ip[i].ip));
 #else
 		PV_Union uPV;
-		uPV.u32 = &ctrl->netc->dns_ip[i].ip.ipv4;
+		uPV.u32 = ctrl->netc->dns_ip[i].ip.ipv4;
 		lua_pushfstring(L, "%d.%d.%d.%d", uPV.u8[0], uPV.u8[1], uPV.u8[2], uPV.u8[3]);
 #endif
 	}

+ 1 - 1
components/network/adapter/luat_network_adapter.c

@@ -625,7 +625,7 @@ static int network_state_wait_dns(network_ctrl_t *ctrl, OS_EVENT *event, network
 		if (event->Param1)
 		{
 			//更新dns cache
-			ctrl->dns_ip = event->Param2;
+			ctrl->dns_ip = (luat_dns_ip_result *)event->Param2;
 			ctrl->dns_ip_nums = event->Param1;
 #ifdef LUAT_USE_LWIP
 			for(int i = 0; i < ctrl->dns_ip_nums; i++)

+ 14 - 14
components/network/libemqtt/luat_lib_mqtt.c

@@ -74,7 +74,7 @@ int32_t luatos_mqtt_callback(lua_State *L, void* ptr){
     switch (msg->arg1) {
 //		case MQTT_MSG_TCP_TX_DONE:
 //			if (mqtt_ctrl->mqtt_cb) {
-//				lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+//				lua_geti(L, LUA_REGISTRYINDEX, (lua_Integer)mqtt_ctrl->mqtt_cb);
 //				if (lua_isfunction(L, -1)) {
 //					lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref);
 //					lua_pushstring(L, "tcp_ack");
@@ -92,7 +92,7 @@ int32_t luatos_mqtt_callback(lua_State *L, void* ptr){
 			luat_netdrv_fire_socket_event_netctrl(EV_NW_TIMEOUT, mqtt_ctrl->netc, 4);
 			#endif
 			if (mqtt_ctrl->mqtt_ref) {
-				lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+				lua_geti(L, LUA_REGISTRYINDEX, (lua_Integer)mqtt_ctrl->mqtt_cb);
 				if (lua_isfunction(L, -1)) {
 					lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref);
 					lua_pushstring(L, "error");
@@ -106,7 +106,7 @@ int32_t luatos_mqtt_callback(lua_State *L, void* ptr){
 		}
 		case MQTT_MSG_PINGRESP : {
 			if (mqtt_ctrl->mqtt_cb) {
-				lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+				lua_geti(L, LUA_REGISTRYINDEX, (lua_Integer)mqtt_ctrl->mqtt_cb);
 				if (lua_isfunction(L, -1)) {
 					lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref);
 					lua_pushstring(L, "pong");
@@ -129,7 +129,7 @@ int32_t luatos_mqtt_callback(lua_State *L, void* ptr){
 			luat_mqtt_msg_t *mqtt_msg =(luat_mqtt_msg_t *)msg->arg2;
 			if (mqtt_ctrl->mqtt_cb) {
 //				luat_mqtt_msg_t *mqtt_msg =(luat_mqtt_msg_t *)msg->arg2;
-				lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+				lua_geti(L, LUA_REGISTRYINDEX, (lua_Integer)mqtt_ctrl->mqtt_cb);
 				if (lua_isfunction(L, -1)) {
 					lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref);
 					lua_pushstring(L, "recv");
@@ -171,7 +171,7 @@ int32_t luatos_mqtt_callback(lua_State *L, void* ptr){
         }
         case MQTT_MSG_CONNACK: {
 			if (mqtt_ctrl->mqtt_cb) {
-				lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+				lua_geti(L, LUA_REGISTRYINDEX, (lua_Integer)mqtt_ctrl->mqtt_cb);
 				if (lua_isfunction(L, -1)) {
 					lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref);
 					lua_pushstring(L, "conack");
@@ -189,7 +189,7 @@ int32_t luatos_mqtt_callback(lua_State *L, void* ptr){
 		case MQTT_MSG_PUBACK:
 		case MQTT_MSG_PUBCOMP: {
 			if (mqtt_ctrl->mqtt_cb) {
-				lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+				lua_geti(L, LUA_REGISTRYINDEX, (lua_Integer)mqtt_ctrl->mqtt_cb);
 				if (lua_isfunction(L, -1)) {
 					lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref);
 					lua_pushstring(L, "sent");
@@ -208,7 +208,7 @@ int32_t luatos_mqtt_callback(lua_State *L, void* ptr){
         }
 		case MQTT_MSG_CLOSE: {
 			if (mqtt_ctrl->mqtt_ref) {
-				lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+				lua_geti(L, LUA_REGISTRYINDEX, (lua_Integer)mqtt_ctrl->mqtt_cb);
 				if (lua_isfunction(L, -1)) {
 					lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref);
 					lua_pushstring(L, "close");
@@ -219,7 +219,7 @@ int32_t luatos_mqtt_callback(lua_State *L, void* ptr){
         }
 		case MQTT_MSG_DISCONNECT: {
 			if (mqtt_ctrl->mqtt_cb) {
-				lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+				lua_geti(L, LUA_REGISTRYINDEX, (lua_Integer)mqtt_ctrl->mqtt_cb);
 				if (lua_isfunction(L, -1)) {
 					lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref);
 					lua_pushstring(L, "disconnect");
@@ -238,7 +238,7 @@ int32_t luatos_mqtt_callback(lua_State *L, void* ptr){
         }
 		case MQTT_MSG_SUBACK:
 			if (mqtt_ctrl->mqtt_cb) {
-				lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+				lua_geti(L, LUA_REGISTRYINDEX, (lua_Integer)mqtt_ctrl->mqtt_cb);
 				if (lua_isfunction(L, -1)) {
 					lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref);
 					lua_pushstring(L, "suback");
@@ -250,7 +250,7 @@ int32_t luatos_mqtt_callback(lua_State *L, void* ptr){
 			break;
 		case MQTT_MSG_UNSUBACK:
 			if (mqtt_ctrl->mqtt_cb) {
-				lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+				lua_geti(L, LUA_REGISTRYINDEX, (lua_Integer)mqtt_ctrl->mqtt_cb);
 				if (lua_isfunction(L, -1)) {
 					lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref);
 					lua_pushstring(L, "unsuback");
@@ -263,7 +263,7 @@ int32_t luatos_mqtt_callback(lua_State *L, void* ptr){
 		case MQTT_MSG_CONACK_ERROR:
 		case MQTT_MSG_NET_ERROR:
 			if (mqtt_ctrl->mqtt_ref) {
-				lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+				lua_geti(L, LUA_REGISTRYINDEX, (lua_Integer)mqtt_ctrl->mqtt_cb);
 				if (lua_isfunction(L, -1)) {
 					lua_geti(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_ref);
 					lua_pushstring(L, "error");
@@ -631,12 +631,12 @@ event可能出现的值有
 static int l_mqtt_on(lua_State *L) {
 	luat_mqtt_ctrl_t * mqtt_ctrl = get_mqtt_ctrl(L);
 	if (mqtt_ctrl->mqtt_cb != 0) {
-		luaL_unref(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+		luaL_unref(L, LUA_REGISTRYINDEX, (int)(intptr_t)mqtt_ctrl->mqtt_cb);
 		mqtt_ctrl->mqtt_cb = 0;
 	}
 	if (lua_isfunction(L, 2)) {
 		lua_pushvalue(L, 2);
-		mqtt_ctrl->mqtt_cb = luaL_ref(L, LUA_REGISTRYINDEX);
+		mqtt_ctrl->mqtt_cb = (void*)(intptr_t)luaL_ref(L, LUA_REGISTRYINDEX);
 	}
 	return 0;
 }
@@ -755,7 +755,7 @@ static int l_mqtt_close(lua_State *L) {
 	mqtt_disconnect(&(mqtt_ctrl->broker));
 	luat_mqtt_close_socket(mqtt_ctrl);
 	if (mqtt_ctrl->mqtt_cb != 0) {
-		luaL_unref(L, LUA_REGISTRYINDEX, mqtt_ctrl->mqtt_cb);
+		luaL_unref(L, LUA_REGISTRYINDEX, (int)(intptr_t)mqtt_ctrl->mqtt_cb);
 		mqtt_ctrl->mqtt_cb = 0;
 	}
 	luat_mqtt_release_socket(mqtt_ctrl);