diff --git a/pkg/lua/Makefile b/pkg/lua/Makefile new file mode 100644 index 0000000000..d2f1a775de --- /dev/null +++ b/pkg/lua/Makefile @@ -0,0 +1,12 @@ +PKG_NAME=lua +PKG_URL=https://github.com/lua/lua.git +PKG_VERSION=e354c6355e7f48e087678ec49e340ca0696725b1 +PKG_LICENSE=MIT + +.PHONY: all + +all: + @cp Makefile.lua $(PKG_BUILDDIR) + "$(MAKE)" -C $(PKG_BUILDDIR) -f Makefile.lua + +include $(RIOTBASE)/pkg/pkg.mk diff --git a/pkg/lua/Makefile.include b/pkg/lua/Makefile.include new file mode 100644 index 0000000000..9fb515a3b4 --- /dev/null +++ b/pkg/lua/Makefile.include @@ -0,0 +1 @@ +INCLUDES += -I$(PKGDIRBASE)/lua diff --git a/pkg/lua/Makefile.lua b/pkg/lua/Makefile.lua new file mode 100644 index 0000000000..f0bd4d8a38 --- /dev/null +++ b/pkg/lua/Makefile.lua @@ -0,0 +1,9 @@ +SRC := $(filter-out lua.c luac.c,$(wildcard *.c)) + +# This builds for native using POSIX system calls and some extra libraries, and +# removes a compiler warning that warns against using tmpnam(). +ifeq ($(BOARD),native) + CFLAGS += -DLUA_USE_LINUX +endif + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/lua/doc.txt b/pkg/lua/doc.txt new file mode 100644 index 0000000000..944d45c632 --- /dev/null +++ b/pkg/lua/doc.txt @@ -0,0 +1,6 @@ +/** + * @defgroup pkg_lua Lua ported to RIOT + * @ingroup pkg + * @brief Provides Lua support for RIOT + * @see https://github.com/lua/lua + */ diff --git a/pkg/lua/patches/0001-Remove-dependency-on-nonexistent-RIOT-syscalls.patch b/pkg/lua/patches/0001-Remove-dependency-on-nonexistent-RIOT-syscalls.patch new file mode 100644 index 0000000000..b4017f5382 --- /dev/null +++ b/pkg/lua/patches/0001-Remove-dependency-on-nonexistent-RIOT-syscalls.patch @@ -0,0 +1,62 @@ +From b681cb20ee6bfc31b8ba23ec321140aae6e53e9d Mon Sep 17 00:00:00 2001 +From: danpetry +Date: Wed, 23 May 2018 14:09:17 +0200 +Subject: [PATCH 1/1] Remove dependency on nonexistent RIOT syscalls + +Os.rename and os.clock, in Lua, now always return an error message. +Also, l_randomizePivot, which is used by table.sort, will always +supply 0 rather than a pseudorandom number. +--- + loslib.c | 7 ++----- + ltablib.c | 4 +++- + 2 files changed, 5 insertions(+), 6 deletions(-) + +diff --git a/loslib.c b/loslib.c +index dd2bb378..f9e5cbd2 100644 +--- a/loslib.c ++++ b/loslib.c +@@ -157,9 +157,7 @@ static int os_remove (lua_State *L) { + + + static int os_rename (lua_State *L) { +- const char *fromname = luaL_checkstring(L, 1); +- const char *toname = luaL_checkstring(L, 2); +- return luaL_fileresult(L, rename(fromname, toname) == 0, NULL); ++ return luaL_error(L, "This function is not implemented in RIOT yet"); + } + + +@@ -181,8 +179,7 @@ static int os_getenv (lua_State *L) { + + + static int os_clock (lua_State *L) { +- lua_pushnumber(L, ((lua_Number)clock())/(lua_Number)CLOCKS_PER_SEC); +- return 1; ++ return luaL_error(L, "This function is not implemented in RIOT yet"); + } + + +diff --git a/ltablib.c b/ltablib.c +index 588bf40d..8895b653 100644 +--- a/ltablib.c ++++ b/ltablib.c +@@ -235,13 +235,15 @@ static int unpack (lua_State *L) { + /* type for array indices */ + typedef unsigned int IdxT; + +- + /* + ** Produce a "random" 'unsigned int' to randomize pivot choice. This + ** macro is used only when 'sort' detects a big imbalance in the result + ** of a partition. (If you don't want/need this "randomness", ~0 is a + ** good choice.) + */ ++ ++#define l_randomizePivot() 0 ++ + #if !defined(l_randomizePivot) /* { */ + + #include +-- +2.17.0 +