diff --git a/interpreters/luamodules/luv/.gitignore b/interpreters/luamodules/luv/.gitignore new file mode 100644 index 000000000..8974fb2c0 --- /dev/null +++ b/interpreters/luamodules/luv/.gitignore @@ -0,0 +1,2 @@ +luv/ +*.tar.gz diff --git a/interpreters/luamodules/luv/0001-fix-compile-warnings.patch b/interpreters/luamodules/luv/0001-fix-compile-warnings.patch new file mode 100644 index 000000000..2e6003b7f --- /dev/null +++ b/interpreters/luamodules/luv/0001-fix-compile-warnings.patch @@ -0,0 +1,141 @@ +From 809314f3c818ddcfdc72e2b3adb4faf350bf201c Mon Sep 17 00:00:00 2001 +From: Xu Xingliang +Date: Fri, 2 Dec 2022 13:07:17 +0800 +Subject: [PATCH] fix compile warnings +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +luv/src/fs.c:431:14: warning: declaration of ‘data’ shadows a previous local [-Wshadow] +luv/src/private.h:114:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes] + +Signed-off-by: Xu Xingliang +--- + src/fs.c | 14 +++++++------- + src/luv.h | 2 +- + src/private.h | 2 +- + src/thread.c | 2 +- + src/work.c | 6 +++--- + 5 files changed, 13 insertions(+), 13 deletions(-) + +diff --git a/src/fs.c b/src/fs.c +index 344d602..ea2a80a 100644 +--- a/src/fs.c ++++ b/src/fs.c +@@ -428,14 +428,14 @@ static void luv_fs_cb(uv_fs_t* req) { + // variable 'nargs' to the number of return values + #define FS_CALL_NORETURN(func, req, ...) { \ + int ret, sync; \ +- luv_req_t* data = (luv_req_t*)req->data; \ +- sync = data->callback_ref == LUA_NOREF; \ +- ret = uv_fs_##func(data->ctx->loop, req, __VA_ARGS__, \ ++ luv_req_t* lreq = (luv_req_t*)req->data; \ ++ sync = lreq->callback_ref == LUA_NOREF; \ ++ ret = uv_fs_##func(lreq->ctx->loop, req, __VA_ARGS__, \ + sync ? NULL : luv_fs_cb); \ + if (req->fs_type != UV_FS_ACCESS && ret < 0) { \ + lua_pushnil(L); \ + if (fs_req_has_dest_path(req)) { \ +- lua_rawgeti(L, LUA_REGISTRYINDEX, data->data_ref); \ ++ lua_rawgeti(L, LUA_REGISTRYINDEX, lreq->data_ref); \ + const char* dest_path = lua_tostring(L, -1); \ + lua_pop(L, 1); \ + lua_pushfstring(L, "%s: %s: %s -> %s", \ +@@ -455,7 +455,7 @@ static void luv_fs_cb(uv_fs_t* req) { + } \ + lua_pushstring(L, uv_err_name(req->result)); \ + if(req->fs_type != UV_FS_SCANDIR) { \ +- luv_cleanup_req(L, data); \ ++ luv_cleanup_req(L, lreq); \ + req->data = NULL; \ + uv_fs_req_cleanup(req); \ + } \ +@@ -464,13 +464,13 @@ static void luv_fs_cb(uv_fs_t* req) { + else if (sync) { \ + nargs = push_fs_result(L, req); \ + if(req->fs_type != UV_FS_SCANDIR) { \ +- luv_cleanup_req(L, data); \ ++ luv_cleanup_req(L, lreq); \ + req->data = NULL; \ + uv_fs_req_cleanup(req); \ + } \ + } \ + else { \ +- lua_rawgeti(L, LUA_REGISTRYINDEX, data->req_ref); \ ++ lua_rawgeti(L, LUA_REGISTRYINDEX, lreq->req_ref); \ + nargs = 1; \ + } \ + } +diff --git a/src/luv.h b/src/luv.h +index 5921e15..ad02329 100644 +--- a/src/luv.h ++++ b/src/luv.h +@@ -147,7 +147,7 @@ LUALIB_API void luv_set_cthread(lua_State* L, luv_CFcpcall cpcall); + */ + LUALIB_API int luaopen_luv (lua_State *L); + +-typedef lua_State* (*luv_acquire_vm)(); ++typedef lua_State* (*luv_acquire_vm)(void); + typedef void (*luv_release_vm)(lua_State* L); + LUALIB_API void luv_set_thread_cb(luv_acquire_vm acquire, luv_release_vm release); + +diff --git a/src/private.h b/src/private.h +index 1e921a4..b4ea7fb 100644 +--- a/src/private.h ++++ b/src/private.h +@@ -111,7 +111,7 @@ static int luv_arg_type_error(lua_State* L, int index, const char* fmt); + static int luv_optboolean(lua_State*L, int idx, int defaultval); + + /* From thread.c */ +-static lua_State* luv_thread_acquire_vm(); ++static lua_State* luv_thread_acquire_vm(void); + + /* From process.c */ + static int luv_parse_signal(lua_State* L, int slot); +diff --git a/src/thread.c b/src/thread.c +index 36041af..5de5556 100644 +--- a/src/thread.c ++++ b/src/thread.c +@@ -24,7 +24,7 @@ typedef struct { + luv_thread_arg_t args; + } luv_thread_t; + +-static lua_State* luv_thread_acquire_vm() { ++static lua_State* luv_thread_acquire_vm(void) { + lua_State* L = luaL_newstate(); + + // Add in the lua standard libraries +diff --git a/src/work.c b/src/work.c +index 7e42641..b51bfd1 100644 +--- a/src/work.c ++++ b/src/work.c +@@ -127,7 +127,7 @@ static int luv_work_cb(lua_State* L) { + return LUA_OK; + } + +-static lua_State* luv_work_acquire_vm() ++static lua_State* luv_work_acquire_vm(void) + { + lua_State* L = uv_key_get(&tls_vmkey); + if (L == NULL) +@@ -245,7 +245,7 @@ static const luaL_Reg luv_work_ctx_methods[] = { + {NULL, NULL} + }; + +-static void luv_key_init_once() ++static void luv_key_init_once(void) + { + const char* val; + int status = uv_key_create(&tls_vmkey); +@@ -287,7 +287,7 @@ static void luv_key_init_once() + idx_vms = 0; + } + +-static void luv_work_cleanup() ++static void luv_work_cleanup(void) + { + unsigned int i; + +-- +2.25.1 + diff --git a/interpreters/luamodules/luv/Kconfig b/interpreters/luamodules/luv/Kconfig new file mode 100644 index 000000000..3b1693dd4 --- /dev/null +++ b/interpreters/luamodules/luv/Kconfig @@ -0,0 +1,30 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config LUA_LUV_MODULE + bool "Lua Luv module" + default n + depends on INTERPRETERS_LUA && LIBUV + select LIBC_EXECFUNCS + select NET + select NETDEV_IFINDEX + select NET_SOCKOPTS + select NET_TCP + select NET_UDP + select PSEUDOFS_SOFTLINKS + select SCHED_ATEXIT + select SCHED_HAVE_PARENT + ---help--- + Bare libuv bindings for Lua + +if LUA_LUV_MODULE + +config LUA_LUV_VERSION + string "Luv version" + default "1.44.2-1" + ---help--- + Luv release version to fetch and build. + +endif # LUA_LUV_MODULE diff --git a/interpreters/luamodules/luv/Make.defs b/interpreters/luamodules/luv/Make.defs new file mode 100644 index 000000000..c1af97de2 --- /dev/null +++ b/interpreters/luamodules/luv/Make.defs @@ -0,0 +1,24 @@ +############################################################################ +# apps/interpreters/luamodules/luv/Make.defs +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +ifneq ($(CONFIG_LUA_LUV_MODULE),) +CONFIGURED_APPS += $(APPDIR)/interpreters/luamodules/luv + +endif diff --git a/interpreters/luamodules/luv/Makefile b/interpreters/luamodules/luv/Makefile new file mode 100644 index 000000000..9eb011163 --- /dev/null +++ b/interpreters/luamodules/luv/Makefile @@ -0,0 +1,67 @@ +############################################################################ +# apps/interpreters/luamodules/luv/Makefile +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +# Luv library + +LUV_VERSION = $(patsubst "%",%,$(strip $(CONFIG_LUA_LUV_VERSION))) +LUV_TARBALL = luv-$(LUV_VERSION).tar.gz +LUV_UNPACK = luv +LUV_URL_BASE = https://github.com/luvit/luv/releases/download/ +LUV_URL = $(LUV_URL_BASE)/$(LUV_VERSION)/$(LUV_TARBALL) +LUV_SRC = $(LUV_UNPACK)$(DELIM)src + +VPATH += $(LUV_SRC) +CSRCS = luv.c + +# Luv download and unpack + +$(LUV_TARBALL): + $(Q) echo "Downloading $(LUV_TARBALL)" + $(Q) curl -O -L $(LUV_URL) + +$(LUV_UNPACK): $(LUV_TARBALL) + $(Q) echo "Unpacking $(LUV_TARBALL) to $(LUV_UNPACK)" + $(Q) tar -xvzf $(LUV_TARBALL) + $(Q) mv luv-$(LUV_VERSION) $(LUV_UNPACK) + $(Q) patch -d $(LUV_UNPACK) -p1 < 0001-fix-compile-warnings.patch + +$(LUV_UNPACK)/.patch: $(LUV_UNPACK) + touch $(LUV_UNPACK)/.patch + +# Download and unpack tarball if no git repo found +ifeq ($(wildcard $(LUV_UNPACK)/.git),) +distclean:: + $(call DELDIR, $(LUV_UNPACK)) + $(call DELFILE, $(LUV_TARBALL)) + +context:: $(LUV_UNPACK)/.patch +endif + +# Set LUAMODNAME and include Module.mk to add this module to the list of +# builtin modules for the Lua interpreter. LUAMODNAME should match the +# module's luaopen function. + +LUAMODNAME = luv + +include $(APPDIR)/interpreters/lua/Module.mk + +include $(APPDIR)/Application.mk