Initial commit

This commit is contained in:
domenico
2025-06-24 15:51:28 +02:00
commit 22031d9dab
6862 changed files with 1462554 additions and 0 deletions

175
package/utils/lua/Makefile Normal file
View File

@@ -0,0 +1,175 @@
#
# Copyright (C) 2006-2014 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=lua
PKG_VERSION:=5.1.5
PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.lua.org/ftp/ \
http://www.tecgraf.puc-rio.br/lua/ftp/
PKG_HASH:=2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333
PKG_BUILD_PARALLEL:=1
PKG_LICENSE:=MIT
PKG_LICENSE_FILES:=COPYRIGHT
HOST_PATCH_DIR := ./patches-host
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/host-build.mk
define Package/lua/Default
SUBMENU:=Lua
SECTION:=lang
CATEGORY:=Languages
TITLE:=Lua programming language
URL:=http://www.lua.org/
MAINTAINER:=Jo-Philipp Wich <jo@mein.io>
endef
define Package/lua/Default/description
Lua is a powerful light-weight programming language designed for extending
applications. Lua is also frequently used as a general-purpose, stand-alone
language. Lua is free software.
endef
define Package/liblua
$(call Package/lua/Default)
SUBMENU:=
SECTION:=libs
CATEGORY:=Libraries
TITLE+= (libraries)
endef
define Package/liblua/description
$(call Package/lua/Default/description)
This package contains the Lua shared libraries, needed by other programs.
endef
define Package/lua
$(call Package/lua/Default)
DEPENDS:=+liblua
TITLE+= (interpreter)
endef
define Package/lua/description
$(call Package/lua/Default/description)
This package contains the Lua language interpreter.
endef
define Package/luac
$(call Package/lua/Default)
DEPENDS:=+liblua
TITLE+= (compiler)
endef
define Package/luac/description
$(call Package/lua/Default/description)
This package contains the Lua language compiler.
endef
define Package/lua-examples
$(call Package/lua/Default)
DEPENDS:=lua
TITLE+= (examples)
endef
define Package/lua-examples/description
$(call Package/lua/Default/description)
This package contains Lua language examples.
endef
define Build/Configure
endef
TARGET_CFLAGS += -DLUA_USE_LINUX $(FPIC) -std=gnu99
define Build/Compile
$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
CC="$(TARGET_CROSS)gcc" \
AR="$(TARGET_CROSS)ar rcu" \
RANLIB="$(TARGET_CROSS)ranlib" \
INSTALL_ROOT=/usr \
CFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" \
MYLDFLAGS="$(TARGET_LDFLAGS)" \
PKG_VERSION=$(PKG_VERSION) \
linux
rm -rf $(PKG_INSTALL_DIR)
mkdir -p $(PKG_INSTALL_DIR)
$(MAKE) -C $(PKG_BUILD_DIR) \
INSTALL_TOP="$(PKG_INSTALL_DIR)/usr" \
install
endef
define Host/Configure
$(SED) 's,"/usr/local/","$(STAGING_DIR_HOSTPKG)/",' $(HOST_BUILD_DIR)/src/luaconf.h
endef
ifeq ($(HOST_OS),Darwin)
LUA_OS:=macosx
else
ifeq ($(HOST_OS),FreeBSD)
LUA_OS:=freebsd
else
LUA_OS:=linux
endif
endif
define Host/Compile
$(MAKE) -C $(HOST_BUILD_DIR) \
CC="$(HOSTCC) -std=gnu99" \
$(LUA_OS)
endef
define Host/Install
$(MAKE) -C $(HOST_BUILD_DIR) \
INSTALL_TOP="$(STAGING_DIR_HOSTPKG)" \
install
endef
define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/include
$(CP) $(PKG_INSTALL_DIR)/usr/include/lua{,lib,conf}.h $(1)/usr/include/
$(CP) $(PKG_INSTALL_DIR)/usr/include/lauxlib.h $(1)/usr/include/
$(CP) $(PKG_INSTALL_DIR)/usr/include/lnum_config.h $(1)/usr/include/
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/liblua.{a,so*} $(1)/usr/lib/
$(LN) liblua.so.$(PKG_VERSION) $(1)/usr/lib/liblualib.so
$(INSTALL_DIR) $(1)/usr/lib/pkgconfig
$(CP) $(PKG_BUILD_DIR)/etc/lua.pc $(1)/usr/lib/pkgconfig/
endef
define Package/liblua/install
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/liblua.so.* $(1)/usr/lib/
endef
define Package/lua/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/lua $(1)/usr/bin/
endef
define Package/luac/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/luac $(1)/usr/bin/
endef
define Package/lua-examples/install
$(INSTALL_DIR) $(1)/usr/share/lua/examples
$(INSTALL_DATA) $(PKG_BUILD_DIR)/test/*.lua \
$(1)/usr/share/lua/examples/
endef
$(eval $(call BuildPackage,liblua))
$(eval $(call BuildPackage,lua))
$(eval $(call BuildPackage,luac))
$(eval $(call BuildPackage,lua-examples))
$(eval $(call HostBuild))

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
--- a/src/lnum_config.h
+++ b/src/lnum_config.h
@@ -11,7 +11,7 @@
** Default number modes
*/
#if (!defined LNUM_DOUBLE) && (!defined LNUM_FLOAT) && (!defined LNUM_LDOUBLE)
-# define LNUM_FLOAT
+# define LNUM_DOUBLE
#endif
#if (!defined LNUM_INT16) && (!defined LNUM_INT32) && (!defined LNUM_INT64)
# define LNUM_INT32

View File

@@ -0,0 +1,22 @@
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -284,7 +284,8 @@ int luaV_lessthan (lua_State *L, const T
else
return luai_numlt( nvalue_fast(l), cast_num(ivalue(r)) );
- } else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
+ }
+ if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
return res;
return luaG_ordererror(L, l, r);
@@ -322,7 +323,8 @@ static int lessequal (lua_State *L, cons
else
return luai_numle( nvalue_fast(l), cast_num(ivalue(r)) );
- } else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
+ }
+ if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
return res;
else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
return !res;

View File

@@ -0,0 +1,48 @@
diff --git a/src/lnum.c b/src/lnum.c
index 1456b6a2ed23..b0632b04c2b7 100644
--- a/src/lnum.c
+++ b/src/lnum.c
@@ -127,6 +127,8 @@ static int luaO_str2i (const char *s, lua_Integer *res, char **endptr_ref) {
#else
return 0; /* Reject the number */
#endif
+ } else if (v > LUA_INTEGER_MAX) {
+ return TK_NUMBER;
}
} else if ((v > LUA_INTEGER_MAX) || (*endptr && (!isspace(*endptr)))) {
return TK_NUMBER; /* not in signed range, or has '.', 'e' etc. trailing */
@@ -310,3 +312,13 @@ int try_unmint( lua_Integer *r, lua_Integer ib ) {
return 0;
}
+#ifdef LONG_OVERFLOW_LUA_INTEGER
+unsigned LUA_INTEGER lua_str2ul( const char *str, char **endptr, int base ) {
+ unsigned long v= strtoul(str, endptr, base);
+ if ( v > LUA_INTEGER_MAX ) {
+ errno= ERANGE;
+ v= ULONG_MAX;
+ }
+ return (unsigned LUA_INTEGER)v;
+}
+#endif
diff --git a/src/lnum_config.h b/src/lnum_config.h
index 19d7a4231a49..1092eead6629 100644
--- a/src/lnum_config.h
+++ b/src/lnum_config.h
@@ -141,7 +141,12 @@
#endif
#ifndef lua_str2ul
-# define lua_str2ul (unsigned LUA_INTEGER)strtoul
+# if LONG_MAX > LUA_INTEGER_MAX
+# define LONG_OVERFLOW_LUA_INTEGER
+ unsigned LUA_INTEGER lua_str2ul( const char *str, char **endptr, int base );
+# else
+# define lua_str2ul (unsigned LUA_INTEGER)strtoul
+# endif
#endif
#ifndef LUA_INTEGER_MIN
# define LUA_INTEGER_MIN (-LUA_INTEGER_MAX -1) /* -2^16|32 */
--
1.9.1

View File

@@ -0,0 +1,11 @@
--- a/src/lua.h
+++ b/src/lua.h
@@ -79,7 +79,7 @@ typedef void * (*lua_Alloc) (void *ud, v
* not acceptable for 5.1, maybe 5.2 onwards?
* 9: greater than existing (5.1) type values.
*/
-#define LUA_TINT (-2)
+#define LUA_TINT 9
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1

View File

@@ -0,0 +1,111 @@
--- a/src/ldump.c
+++ b/src/ldump.c
@@ -67,12 +67,12 @@ static void DumpString(const TString* s,
{
if (s==NULL || getstr(s)==NULL)
{
- size_t size=0;
+ unsigned int size=0;
DumpVar(size,D);
}
else
{
- size_t size=s->tsv.len+1; /* include trailing '\0' */
+ unsigned int size=s->tsv.len+1; /* include trailing '\0' */
DumpVar(size,D);
DumpBlock(getstr(s),size,D);
}
--- a/src/lundump.c
+++ b/src/lundump.c
@@ -25,6 +25,7 @@ typedef struct {
ZIO* Z;
Mbuffer* b;
const char* name;
+ int swap;
} LoadState;
#ifdef LUAC_TRUST_BINARIES
@@ -40,7 +41,6 @@ static void error(LoadState* S, const ch
}
#endif
-#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
#define LoadByte(S) (lu_byte)LoadChar(S)
#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
@@ -51,6 +51,49 @@ static void LoadBlock(LoadState* S, void
IF (r!=0, "unexpected end");
}
+static void LoadMem (LoadState* S, void* b, int n, size_t size)
+{
+ LoadBlock(S,b,n*size);
+ if (S->swap)
+ {
+ char* p=(char*) b;
+ char c;
+ switch (size)
+ {
+ case 1:
+ break;
+ case 2:
+ while (n--)
+ {
+ c=p[0]; p[0]=p[1]; p[1]=c;
+ p+=2;
+ }
+ break;
+ case 4:
+ while (n--)
+ {
+ c=p[0]; p[0]=p[3]; p[3]=c;
+ c=p[1]; p[1]=p[2]; p[2]=c;
+ p+=4;
+ }
+ break;
+ case 8:
+ while (n--)
+ {
+ c=p[0]; p[0]=p[7]; p[7]=c;
+ c=p[1]; p[1]=p[6]; p[6]=c;
+ c=p[2]; p[2]=p[5]; p[5]=c;
+ c=p[3]; p[3]=p[4]; p[4]=c;
+ p+=8;
+ }
+ break;
+ default:
+ IF(1, "bad size");
+ break;
+ }
+ }
+}
+
static int LoadChar(LoadState* S)
{
char x;
@@ -82,7 +125,7 @@ static lua_Integer LoadInteger(LoadState
static TString* LoadString(LoadState* S)
{
- size_t size;
+ unsigned int size;
LoadVar(S,size);
if (size==0)
return NULL;
@@ -196,6 +239,7 @@ static void LoadHeader(LoadState* S)
char s[LUAC_HEADERSIZE];
luaU_header(h);
LoadBlock(S,s,LUAC_HEADERSIZE);
+ S->swap=(s[6]!=h[6]); s[6]=h[6];
IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
}
@@ -230,7 +274,7 @@ void luaU_header (char* h)
*h++=(char)LUAC_FORMAT;
*h++=(char)*(char*)&x; /* endianness */
*h++=(char)sizeof(int);
- *h++=(char)sizeof(size_t);
+ *h++=(char)sizeof(unsigned int);
*h++=(char)sizeof(Instruction);
*h++=(char)sizeof(lua_Number);

View File

@@ -0,0 +1,49 @@
--- a/src/luaconf.h
+++ b/src/luaconf.h
@@ -38,7 +38,6 @@
#if defined(LUA_USE_LINUX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
-#define LUA_USE_READLINE /* needs some extra libraries */
#endif
#if defined(LUA_USE_MACOSX)
--- a/src/Makefile
+++ b/src/Makefile
@@ -17,6 +17,7 @@
MYCFLAGS=
MYLDFLAGS=
MYLIBS=
+# USE_READLINE=1
# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
@@ -75,7 +76,7 @@
@echo "MYLIBS = $(MYLIBS)"
# convenience targets for popular platforms
-
+RFLAG=$(if $(USE_READLINE),-DLUA_USE_READLINE)
none:
@echo "Please choose a platform:"
@echo " $(PLATS)"
@@ -90,16 +91,16 @@
$(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
freebsd:
- $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"
+ $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX" $(RFLAG)" MYLIBS="-Wl,-E$(if $(USE_READLINE), -lreadline)"
generic:
$(MAKE) all MYCFLAGS=
linux:
- $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
+ $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX $(RFLAG)" MYLIBS="-Wl,-E -ldl $(if $(USE_READLINE), -lreadline -lhistory -lncurses)"
macosx:
- $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
+ $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX $(if $(USE_READLINE), MYLIBS="-lreadline")
# use this on Mac OS X 10.3-
# $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
--- a/src/lnum_config.h
+++ b/src/lnum_config.h
@@ -11,7 +11,7 @@
** Default number modes
*/
#if (!defined LNUM_DOUBLE) && (!defined LNUM_FLOAT) && (!defined LNUM_LDOUBLE)
-# define LNUM_FLOAT
+# define LNUM_DOUBLE
#endif
#if (!defined LNUM_INT16) && (!defined LNUM_INT32) && (!defined LNUM_INT64)
# define LNUM_INT32

View File

@@ -0,0 +1,22 @@
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -281,7 +281,8 @@ int luaV_lessthan (lua_State *L, const T
else
return luai_numlt( nvalue_fast(l), cast_num(ivalue(r)) );
- } else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
+ }
+ if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
return res;
return luaG_ordererror(L, l, r);
@@ -319,7 +320,8 @@ static int lessequal (lua_State *L, cons
else
return luai_numle( nvalue_fast(l), cast_num(ivalue(r)) );
- } else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
+ }
+ if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
return res;
else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
return !res;

View File

@@ -0,0 +1,41 @@
--- a/src/lnum.c
+++ b/src/lnum.c
@@ -127,6 +127,8 @@ static int luaO_str2i (const char *s, lu
#else
return 0; /* Reject the number */
#endif
+ } else if (v > LUA_INTEGER_MAX) {
+ return TK_NUMBER;
}
} else if ((v > LUA_INTEGER_MAX) || (*endptr && (!isspace(*endptr)))) {
return TK_NUMBER; /* not in signed range, or has '.', 'e' etc. trailing */
@@ -310,3 +312,13 @@ int try_unmint( lua_Integer *r, lua_Inte
return 0;
}
+#ifdef LONG_OVERFLOW_LUA_INTEGER
+unsigned LUA_INTEGER lua_str2ul( const char *str, char **endptr, int base ) {
+ unsigned long v= strtoul(str, endptr, base);
+ if ( v > LUA_INTEGER_MAX ) {
+ errno= ERANGE;
+ v= ULONG_MAX;
+ }
+ return (unsigned LUA_INTEGER)v;
+}
+#endif
--- a/src/lnum_config.h
+++ b/src/lnum_config.h
@@ -141,7 +141,12 @@
#endif
#ifndef lua_str2ul
-# define lua_str2ul (unsigned LUA_INTEGER)strtoul
+# if LONG_MAX > LUA_INTEGER_MAX
+# define LONG_OVERFLOW_LUA_INTEGER
+ unsigned LUA_INTEGER lua_str2ul( const char *str, char **endptr, int base );
+# else
+# define lua_str2ul (unsigned LUA_INTEGER)strtoul
+# endif
#endif
#ifndef LUA_INTEGER_MIN
# define LUA_INTEGER_MIN (-LUA_INTEGER_MAX -1) /* -2^16|32 */

View File

@@ -0,0 +1,11 @@
--- a/src/lua.h
+++ b/src/lua.h
@@ -79,7 +79,7 @@ typedef void * (*lua_Alloc) (void *ud, v
* not acceptable for 5.1, maybe 5.2 onwards?
* 9: greater than existing (5.1) type values.
*/
-#define LUA_TINT (-2)
+#define LUA_TINT 9
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1

View File

@@ -0,0 +1,140 @@
--- a/Makefile
+++ b/Makefile
@@ -42,8 +42,8 @@ PLATS= aix ansi bsd freebsd generic linu
# What to install.
TO_BIN= lua luac
-TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
-TO_LIB= liblua.a
+TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp lnum_config.h
+TO_LIB= liblua.a liblua.so.$R
TO_MAN= lua.1 luac.1
# Lua version and release.
@@ -63,6 +63,7 @@ install: dummy
cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)
cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
+ ln -s liblua.so.$R $(INSTALL_LIB)/liblua.so
cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
ranlib:
--- a/src/ldo.h
+++ b/src/ldo.h
@@ -46,7 +46,7 @@ LUAI_FUNC int luaD_pcall (lua_State *L,
LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult);
LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize);
LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);
-LUAI_FUNC void luaD_growstack (lua_State *L, int n);
+LUA_API void luaD_growstack (lua_State *L, int n);
LUAI_FUNC void luaD_throw (lua_State *L, int errcode);
LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
--- a/src/lfunc.h
+++ b/src/lfunc.h
@@ -18,7 +18,7 @@
cast(int, sizeof(TValue *)*((n)-1)))
-LUAI_FUNC Proto *luaF_newproto (lua_State *L);
+LUA_API Proto *luaF_newproto (lua_State *L);
LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e);
LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e);
LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
--- a/src/lmem.h
+++ b/src/lmem.h
@@ -38,9 +38,9 @@
((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
-LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
+LUA_API void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
size_t size);
-LUAI_FUNC void *luaM_toobig (lua_State *L);
+LUA_API void *luaM_toobig (lua_State *L);
LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
size_t size_elem, int limit,
const char *errormsg);
--- a/src/lstring.h
+++ b/src/lstring.h
@@ -25,7 +25,7 @@
LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
-LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
+LUA_API TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
#endif
--- a/src/lundump.h
+++ b/src/lundump.h
@@ -17,7 +17,7 @@ LUAI_FUNC Proto* luaU_undump (lua_State*
LUAI_FUNC void luaU_header (char* h);
/* dump one chunk; from ldump.c */
-LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
+LUA_API int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
#ifdef luac_c
/* print one chunk; from print.c */
--- a/src/Makefile
+++ b/src/Makefile
@@ -23,6 +23,7 @@ MYLIBS=
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
LUA_A= liblua.a
+LUA_SO= liblua.so
CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
lundump.o lvm.o lzio.o lnum.o
@@ -33,11 +34,12 @@ LUA_T= lua
LUA_O= lua.o
LUAC_T= luac
-LUAC_O= luac.o print.o
+LUAC_O= luac.o print.o lopcodes.o
ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
-ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
+ALL_T= $(LUA_A) $(LUA_SO) $(LUA_T) $(LUAC_T)
ALL_A= $(LUA_A)
+ALL_SO= $(LUA_SO)
default: $(PLAT)
@@ -47,14 +49,23 @@ o: $(ALL_O)
a: $(ALL_A)
+so: $(ALL_SO)
+
$(LUA_A): $(CORE_O) $(LIB_O)
$(AR) $@ $(CORE_O) $(LIB_O) # DLL needs all object files
$(RANLIB) $@
-$(LUA_T): $(LUA_O) $(LUA_A)
- $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
+$(LUA_SO): $(CORE_O) $(LIB_O)
+ $(CC) -o $@.$(PKG_VERSION) -shared -Wl,-soname="$@.$(PKG_VERSION)" $?
+ ln -fs $@.$(PKG_VERSION) $@
+
+$(LUA_T): $(LUA_O) $(LUA_SO)
+ $(CC) -o $@ -L. -llua $(MYLDFLAGS) $(LUA_O) $(LIBS)
+
+$(LUAC_T): $(LUAC_O) $(LUA_SO)
+ $(CC) -o $@ -L. -llua $(MYLDFLAGS) $(LUAC_O) $(LIBS)
-$(LUAC_T): $(LUAC_O) $(LUA_A)
+$(LUAC_T)-host: $(LUAC_O) $(LUA_A)
$(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
clean:
@@ -96,7 +107,7 @@ generic:
$(MAKE) all MYCFLAGS=
linux:
- $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
+ $(MAKE) all MYCFLAGS+=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
macosx:
$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"

View File

@@ -0,0 +1,111 @@
--- a/src/ldump.c
+++ b/src/ldump.c
@@ -67,12 +67,12 @@ static void DumpString(const TString* s,
{
if (s==NULL || getstr(s)==NULL)
{
- size_t size=0;
+ unsigned int size=0;
DumpVar(size,D);
}
else
{
- size_t size=s->tsv.len+1; /* include trailing '\0' */
+ unsigned int size=s->tsv.len+1; /* include trailing '\0' */
DumpVar(size,D);
DumpBlock(getstr(s),size,D);
}
--- a/src/lundump.c
+++ b/src/lundump.c
@@ -25,6 +25,7 @@ typedef struct {
ZIO* Z;
Mbuffer* b;
const char* name;
+ int swap;
} LoadState;
#ifdef LUAC_TRUST_BINARIES
@@ -40,7 +41,6 @@ static void error(LoadState* S, const ch
}
#endif
-#define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
#define LoadByte(S) (lu_byte)LoadChar(S)
#define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
#define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
@@ -51,6 +51,49 @@ static void LoadBlock(LoadState* S, void
IF (r!=0, "unexpected end");
}
+static void LoadMem (LoadState* S, void* b, int n, size_t size)
+{
+ LoadBlock(S,b,n*size);
+ if (S->swap)
+ {
+ char* p=(char*) b;
+ char c;
+ switch (size)
+ {
+ case 1:
+ break;
+ case 2:
+ while (n--)
+ {
+ c=p[0]; p[0]=p[1]; p[1]=c;
+ p+=2;
+ }
+ break;
+ case 4:
+ while (n--)
+ {
+ c=p[0]; p[0]=p[3]; p[3]=c;
+ c=p[1]; p[1]=p[2]; p[2]=c;
+ p+=4;
+ }
+ break;
+ case 8:
+ while (n--)
+ {
+ c=p[0]; p[0]=p[7]; p[7]=c;
+ c=p[1]; p[1]=p[6]; p[6]=c;
+ c=p[2]; p[2]=p[5]; p[5]=c;
+ c=p[3]; p[3]=p[4]; p[4]=c;
+ p+=8;
+ }
+ break;
+ default:
+ IF(1, "bad size");
+ break;
+ }
+ }
+}
+
static int LoadChar(LoadState* S)
{
char x;
@@ -82,7 +125,7 @@ static lua_Integer LoadInteger(LoadState
static TString* LoadString(LoadState* S)
{
- size_t size;
+ unsigned int size;
LoadVar(S,size);
if (size==0)
return NULL;
@@ -196,6 +239,7 @@ static void LoadHeader(LoadState* S)
char s[LUAC_HEADERSIZE];
luaU_header(h);
LoadBlock(S,s,LUAC_HEADERSIZE);
+ S->swap=(s[6]!=h[6]); s[6]=h[6];
IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
}
@@ -230,7 +274,7 @@ void luaU_header (char* h)
*h++=(char)LUAC_FORMAT;
*h++=(char)*(char*)&x; /* endianness */
*h++=(char)sizeof(int);
- *h++=(char)sizeof(size_t);
+ *h++=(char)sizeof(unsigned int);
*h++=(char)sizeof(Instruction);
*h++=(char)sizeof(lua_Number);

View File

@@ -0,0 +1,11 @@
--- a/src/Makefile
+++ b/src/Makefile
@@ -56,7 +56,7 @@ $(LUA_A): $(CORE_O) $(LIB_O)
$(RANLIB) $@
$(LUA_SO): $(CORE_O) $(LIB_O)
- $(CC) -o $@.$(PKG_VERSION) -shared -Wl,-soname="$@.$(PKG_VERSION)" $?
+ $(CC) -o $@.$(PKG_VERSION) -Wl,-Bsymbolic-functions -shared -Wl,-soname="$@.$(PKG_VERSION)" $?
ln -fs $@.$(PKG_VERSION) $@
$(LUA_T): $(LUA_O) $(LUA_SO)

View File

@@ -0,0 +1,11 @@
--- a/src/Makefile
+++ b/src/Makefile
@@ -56,7 +56,7 @@ $(LUA_A): $(CORE_O) $(LIB_O)
$(RANLIB) $@
$(LUA_SO): $(CORE_O) $(LIB_O)
- $(CC) -o $@.$(PKG_VERSION) -Wl,-Bsymbolic-functions -shared -Wl,-soname="$@.$(PKG_VERSION)" $?
+ $(CC) -o $@.$(PKG_VERSION) -Wl,-Bsymbolic-functions $(MYLDFLAGS) -shared -Wl,-soname="$@.$(PKG_VERSION)" $?
ln -fs $@.$(PKG_VERSION) $@
$(LUA_T): $(LUA_O) $(LUA_SO)

View File

@@ -0,0 +1,49 @@
--- a/src/luaconf.h
+++ b/src/luaconf.h
@@ -38,7 +38,6 @@
#if defined(LUA_USE_LINUX)
#define LUA_USE_POSIX
#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
-#define LUA_USE_READLINE /* needs some extra libraries */
#endif
#if defined(LUA_USE_MACOSX)
--- a/src/Makefile
+++ b/src/Makefile
@@ -17,6 +17,7 @@ LIBS= -lm $(MYLIBS)
MYCFLAGS=
MYLDFLAGS=
MYLIBS=
+# USE_READLINE=1
# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
@@ -86,7 +87,7 @@ echo:
@echo "MYLIBS = $(MYLIBS)"
# convenience targets for popular platforms
-
+RFLAG=$(if $(USE_READLINE),-DLUA_USE_READLINE)
none:
@echo "Please choose a platform:"
@echo " $(PLATS)"
@@ -101,16 +102,16 @@ bsd:
$(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
freebsd:
- $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"
+ $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX $(RFLAG)" MYLIBS="-Wl,-E$(if $(USE_READLINE), -lreadline)"
generic:
$(MAKE) all MYCFLAGS=
linux:
- $(MAKE) all MYCFLAGS+=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
+ $(MAKE) all MYCFLAGS+="-DLUA_USE_LINUX $(RFLAG)" MYLIBS="-Wl,-E -ldl $(if $(USE_READLINE), -lreadline -lhistory -lncurses)"
macosx:
- $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
+ $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX $(if $(USE_READLINE), MYLIBS="-lreadline")
# use this on Mac OS X 10.3-
# $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX

View File

@@ -0,0 +1,15 @@
--- a/src/luaconf.h
+++ b/src/luaconf.h
@@ -95,9 +95,9 @@
".\\?.dll;" LUA_CDIR"?.dll;" LUA_CDIR"loadall.dll"
#else
-#define LUA_ROOT "/usr/local/"
-#define LUA_LDIR LUA_ROOT "share/lua/5.1/"
-#define LUA_CDIR LUA_ROOT "lib/lua/5.1/"
+#define LUA_ROOT "/usr/"
+#define LUA_LDIR LUA_ROOT "share/lua/"
+#define LUA_CDIR LUA_ROOT "lib/lua/"
#define LUA_PATH_DEFAULT \
"./?.lua;" LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua"

View File

@@ -0,0 +1,363 @@
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -31,6 +31,9 @@
/* limit for table tag-method chains (to avoid loops) */
#define MAXTAGLOOP 100
+#ifdef __GNUC__
+#define COMPUTED_GOTO 1
+#endif
/*
* If 'obj' is a string, it is tried to be interpreted as a number.
@@ -568,12 +571,63 @@ static inline int arith_mode( const TVal
ARITH_OP1_END
#endif
+#ifdef COMPUTED_GOTO
+#define OPCODE_TARGET(op) DO_OP_##op:
+#define CALL_OPCODE(op) goto *opcodes[op];
+#define OPCODE_PTR(op) [OP_##op] = &&DO_OP_##op
+#else
+#define OPCODE_TARGET(op) case OP_##op:
+#define CALL_OPCODE(op) switch (op)
+#endif
+
void luaV_execute (lua_State *L, int nexeccalls) {
LClosure *cl;
StkId base;
TValue *k;
const Instruction *pc;
+#ifdef COMPUTED_GOTO
+ static const void *opcodes[] = {
+ OPCODE_PTR(MOVE),
+ OPCODE_PTR(LOADK),
+ OPCODE_PTR(LOADBOOL),
+ OPCODE_PTR(LOADNIL),
+ OPCODE_PTR(GETUPVAL),
+ OPCODE_PTR(GETGLOBAL),
+ OPCODE_PTR(GETTABLE),
+ OPCODE_PTR(SETGLOBAL),
+ OPCODE_PTR(SETUPVAL),
+ OPCODE_PTR(SETTABLE),
+ OPCODE_PTR(NEWTABLE),
+ OPCODE_PTR(SELF),
+ OPCODE_PTR(ADD),
+ OPCODE_PTR(SUB),
+ OPCODE_PTR(MUL),
+ OPCODE_PTR(DIV),
+ OPCODE_PTR(MOD),
+ OPCODE_PTR(POW),
+ OPCODE_PTR(UNM),
+ OPCODE_PTR(NOT),
+ OPCODE_PTR(LEN),
+ OPCODE_PTR(CONCAT),
+ OPCODE_PTR(JMP),
+ OPCODE_PTR(EQ),
+ OPCODE_PTR(LT),
+ OPCODE_PTR(LE),
+ OPCODE_PTR(TEST),
+ OPCODE_PTR(TESTSET),
+ OPCODE_PTR(CALL),
+ OPCODE_PTR(TAILCALL),
+ OPCODE_PTR(RETURN),
+ OPCODE_PTR(FORLOOP),
+ OPCODE_PTR(FORPREP),
+ OPCODE_PTR(TFORLOOP),
+ OPCODE_PTR(SETLIST),
+ OPCODE_PTR(CLOSE),
+ OPCODE_PTR(CLOSURE),
+ OPCODE_PTR(VARARG)
+ };
+#endif
reentry: /* entry point */
lua_assert(isLua(L->ci));
pc = L->savedpc;
@@ -598,33 +652,33 @@ void luaV_execute (lua_State *L, int nex
lua_assert(base == L->base && L->base == L->ci->base);
lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);
lua_assert(L->top == L->ci->top || luaG_checkopenop(i));
- switch (GET_OPCODE(i)) {
- case OP_MOVE: {
+ CALL_OPCODE(GET_OPCODE(i)) {
+ OPCODE_TARGET(MOVE) {
setobjs2s(L, ra, RB(i));
continue;
}
- case OP_LOADK: {
+ OPCODE_TARGET(LOADK) {
setobj2s(L, ra, KBx(i));
continue;
}
- case OP_LOADBOOL: {
+ OPCODE_TARGET(LOADBOOL) {
setbvalue(ra, GETARG_B(i));
if (GETARG_C(i)) pc++; /* skip next instruction (if C) */
continue;
}
- case OP_LOADNIL: {
+ OPCODE_TARGET(LOADNIL) {
TValue *rb = RB(i);
do {
setnilvalue(rb--);
} while (rb >= ra);
continue;
}
- case OP_GETUPVAL: {
+ OPCODE_TARGET(GETUPVAL) {
int b = GETARG_B(i);
setobj2s(L, ra, cl->upvals[b]->v);
continue;
}
- case OP_GETGLOBAL: {
+ OPCODE_TARGET(GETGLOBAL) {
TValue g;
TValue *rb = KBx(i);
sethvalue(L, &g, cl->env);
@@ -632,88 +686,88 @@ void luaV_execute (lua_State *L, int nex
Protect(luaV_gettable(L, &g, rb, ra));
continue;
}
- case OP_GETTABLE: {
+ OPCODE_TARGET(GETTABLE) {
Protect(luaV_gettable(L, RB(i), RKC(i), ra));
continue;
}
- case OP_SETGLOBAL: {
+ OPCODE_TARGET(SETGLOBAL) {
TValue g;
sethvalue(L, &g, cl->env);
lua_assert(ttisstring(KBx(i)));
Protect(luaV_settable(L, &g, KBx(i), ra));
continue;
}
- case OP_SETUPVAL: {
+ OPCODE_TARGET(SETUPVAL) {
UpVal *uv = cl->upvals[GETARG_B(i)];
setobj(L, uv->v, ra);
luaC_barrier(L, uv, ra);
continue;
}
- case OP_SETTABLE: {
+ OPCODE_TARGET(SETTABLE) {
Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
continue;
}
- case OP_NEWTABLE: {
+ OPCODE_TARGET(NEWTABLE) {
int b = GETARG_B(i);
int c = GETARG_C(i);
sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));
Protect(luaC_checkGC(L));
continue;
}
- case OP_SELF: {
+ OPCODE_TARGET(SELF) {
StkId rb = RB(i);
setobjs2s(L, ra+1, rb);
Protect(luaV_gettable(L, rb, RKC(i), ra));
continue;
}
- case OP_ADD: {
+ OPCODE_TARGET(ADD) {
TValue *rb = RKB(i), *rc= RKC(i);
arith_op_continue( luai_numadd, try_addint, luai_vectadd );
Protect(Arith(L, ra, rb, rc, TM_ADD)); \
continue;
}
- case OP_SUB: {
+ OPCODE_TARGET(SUB) {
TValue *rb = RKB(i), *rc= RKC(i);
arith_op_continue( luai_numsub, try_subint, luai_vectsub );
Protect(Arith(L, ra, rb, rc, TM_SUB));
continue;
}
- case OP_MUL: {
+ OPCODE_TARGET(MUL) {
TValue *rb = RKB(i), *rc= RKC(i);
arith_op_continue(luai_nummul, try_mulint, luai_vectmul);
Protect(Arith(L, ra, rb, rc, TM_MUL));
continue;
}
- case OP_DIV: {
+ OPCODE_TARGET(DIV) {
TValue *rb = RKB(i), *rc= RKC(i);
arith_op_continue(luai_numdiv, try_divint, luai_vectdiv);
Protect(Arith(L, ra, rb, rc, TM_DIV));
continue;
}
- case OP_MOD: {
+ OPCODE_TARGET(MOD) {
TValue *rb = RKB(i), *rc= RKC(i);
arith_op_continue_scalar(luai_nummod, try_modint); /* scalars only */
Protect(Arith(L, ra, rb, rc, TM_MOD));
continue;
}
- case OP_POW: {
+ OPCODE_TARGET(POW) {
TValue *rb = RKB(i), *rc= RKC(i);
arith_op_continue(luai_numpow, try_powint, luai_vectpow);
Protect(Arith(L, ra, rb, rc, TM_POW));
continue;
}
- case OP_UNM: {
+ OPCODE_TARGET(UNM) {
TValue *rb = RB(i);
arith_op1_continue(luai_numunm, try_unmint, luai_vectunm);
Protect(Arith(L, ra, rb, rb, TM_UNM));
continue;
}
- case OP_NOT: {
+ OPCODE_TARGET(NOT) {
int res = l_isfalse(RB(i)); /* next assignment may change this value */
setbvalue(ra, res);
continue;
}
- case OP_LEN: {
+ OPCODE_TARGET(LEN) {
const TValue *rb = RB(i);
switch (ttype(rb)) {
case LUA_TTABLE: {
@@ -733,18 +787,18 @@ void luaV_execute (lua_State *L, int nex
}
continue;
}
- case OP_CONCAT: {
+ OPCODE_TARGET(CONCAT) {
int b = GETARG_B(i);
int c = GETARG_C(i);
Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L));
setobjs2s(L, RA(i), base+b);
continue;
}
- case OP_JMP: {
+ OPCODE_TARGET(JMP) {
dojump(L, pc, GETARG_sBx(i));
continue;
}
- case OP_EQ: {
+ OPCODE_TARGET(EQ) {
TValue *rb = RKB(i);
TValue *rc = RKC(i);
Protect(
@@ -754,7 +808,7 @@ void luaV_execute (lua_State *L, int nex
pc++;
continue;
}
- case OP_LT: {
+ OPCODE_TARGET(LT) {
Protect(
if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i))
dojump(L, pc, GETARG_sBx(*pc));
@@ -762,7 +816,7 @@ void luaV_execute (lua_State *L, int nex
pc++;
continue;
}
- case OP_LE: {
+ OPCODE_TARGET(LE) {
Protect(
if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i))
dojump(L, pc, GETARG_sBx(*pc));
@@ -770,13 +824,13 @@ void luaV_execute (lua_State *L, int nex
pc++;
continue;
}
- case OP_TEST: {
+ OPCODE_TARGET(TEST) {
if (l_isfalse(ra) != GETARG_C(i))
dojump(L, pc, GETARG_sBx(*pc));
pc++;
continue;
}
- case OP_TESTSET: {
+ OPCODE_TARGET(TESTSET) {
TValue *rb = RB(i);
if (l_isfalse(rb) != GETARG_C(i)) {
setobjs2s(L, ra, rb);
@@ -785,7 +839,7 @@ void luaV_execute (lua_State *L, int nex
pc++;
continue;
}
- case OP_CALL: {
+ OPCODE_TARGET(CALL) {
int b = GETARG_B(i);
int nresults = GETARG_C(i) - 1;
if (b != 0) L->top = ra+b; /* else previous instruction set top */
@@ -806,7 +860,7 @@ void luaV_execute (lua_State *L, int nex
}
}
}
- case OP_TAILCALL: {
+ OPCODE_TARGET(TAILCALL) {
int b = GETARG_B(i);
if (b != 0) L->top = ra+b; /* else previous instruction set top */
L->savedpc = pc;
@@ -838,7 +892,7 @@ void luaV_execute (lua_State *L, int nex
}
}
}
- case OP_RETURN: {
+ OPCODE_TARGET(RETURN) {
int b = GETARG_B(i);
if (b != 0) L->top = ra+b-1;
if (L->openupval) luaF_close(L, base);
@@ -853,7 +907,7 @@ void luaV_execute (lua_State *L, int nex
goto reentry;
}
}
- case OP_FORLOOP: {
+ OPCODE_TARGET(FORLOOP) {
/* If start,step and limit are all integers, we don't need to check
* against overflow in the looping.
*/
@@ -881,7 +935,7 @@ void luaV_execute (lua_State *L, int nex
}
continue;
}
- case OP_FORPREP: {
+ OPCODE_TARGET(FORPREP) {
const TValue *init = ra;
const TValue *plimit = ra+1;
const TValue *pstep = ra+2;
@@ -904,7 +958,7 @@ void luaV_execute (lua_State *L, int nex
dojump(L, pc, GETARG_sBx(i));
continue;
}
- case OP_TFORLOOP: {
+ OPCODE_TARGET(TFORLOOP) {
StkId cb = ra + 3; /* call base */
setobjs2s(L, cb+2, ra+2);
setobjs2s(L, cb+1, ra+1);
@@ -920,7 +974,7 @@ void luaV_execute (lua_State *L, int nex
pc++;
continue;
}
- case OP_SETLIST: {
+ OPCODE_TARGET(SETLIST) {
int n = GETARG_B(i);
int c = GETARG_C(i);
int last;
@@ -942,11 +996,11 @@ void luaV_execute (lua_State *L, int nex
}
continue;
}
- case OP_CLOSE: {
+ OPCODE_TARGET(CLOSE) {
luaF_close(L, ra);
continue;
}
- case OP_CLOSURE: {
+ OPCODE_TARGET(CLOSURE) {
Proto *p;
Closure *ncl;
int nup, j;
@@ -966,7 +1020,7 @@ void luaV_execute (lua_State *L, int nex
Protect(luaC_checkGC(L));
continue;
}
- case OP_VARARG: {
+ OPCODE_TARGET(VARARG) {
int b = GETARG_B(i) - 1;
int j;
CallInfo *ci = L->ci;