Commit d0e3f9ae authored by fallenstardust's avatar fallenstardust

update LUA5.4

parent c4a0e6d7
...@@ -3,7 +3,7 @@ LOCAL_PATH := $(call my-dir) ...@@ -3,7 +3,7 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS) include $(CLEAR_VARS)
LOCAL_MODULE := lua5.3 LOCAL_MODULE := lua5.4
LOCAL_SRC_FILES := lapi.c \ LOCAL_SRC_FILES := lapi.c \
lauxlib.c \ lauxlib.c \
lbaselib.c \ lbaselib.c \
...@@ -39,7 +39,7 @@ LOCAL_SRC_FILES := lapi.c \ ...@@ -39,7 +39,7 @@ LOCAL_SRC_FILES := lapi.c \
lutf8lib.c \ lutf8lib.c \
lvm.c \ lvm.c \
lzio.c lzio.c
LOCAL_CFLAGS := -DLUA_USE_POSIX -O2 -Wall -D"getlocaledecpoint()='.'" -Wno-psabi -fexceptions LOCAL_CFLAGS := -DLUA_USE_POSIX -O2 -Wall -DLUA_COMPAT_5_2 -D"getlocaledecpoint()='.'" -Wno-psabi -fexceptions
#LOCAL_CPP_EXTENSION := .c #LOCAL_CPP_EXTENSION := .c
include $(BUILD_STATIC_LIBRARY) include $(BUILD_STATIC_LIBRARY)
...@@ -4,16 +4,17 @@ ...@@ -4,16 +4,17 @@
# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT ======================= # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
# Your platform. See PLATS for possible values. # Your platform. See PLATS for possible values.
PLAT= none PLAT= guess
CC= gcc -std=gnu99 CC= gcc -std=gnu99
CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS) CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(SYSCFLAGS) $(MYCFLAGS)
LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS) LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
LIBS= -lm $(SYSLIBS) $(MYLIBS) LIBS= -lm $(SYSLIBS) $(MYLIBS)
AR= ar rcu AR= ar rcu
RANLIB= ranlib RANLIB= ranlib
RM= rm -f RM= rm -f
UNAME= uname
SYSCFLAGS= SYSCFLAGS=
SYSLDFLAGS= SYSLDFLAGS=
...@@ -24,16 +25,16 @@ MYLDFLAGS= ...@@ -24,16 +25,16 @@ MYLDFLAGS=
MYLIBS= MYLIBS=
MYOBJS= MYOBJS=
# Special flags for compiler modules; -Os reduces code size.
CMCFLAGS=
# == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE ======= # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======
PLATS= aix bsd c89 freebsd generic linux macosx mingw posix solaris PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris
LUA_A= liblua.a LUA_A= liblua.a
CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \ CORE_O= lapi.o lcode.o lctype.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
lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \ LIB_O= lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o
ltm.o lundump.o lvm.o lzio.o
LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \
lmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o
BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS) BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)
LUA_T= lua LUA_T= lua
...@@ -65,6 +66,9 @@ $(LUA_T): $(LUA_O) $(LUA_A) ...@@ -65,6 +66,9 @@ $(LUA_T): $(LUA_O) $(LUA_A)
$(LUAC_T): $(LUAC_O) $(LUA_A) $(LUAC_T): $(LUAC_O) $(LUA_A)
$(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS) $(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
test:
./$(LUA_T) -v
clean: clean:
$(RM) $(ALL_T) $(ALL_O) $(RM) $(ALL_T) $(ALL_O)
...@@ -80,15 +84,21 @@ echo: ...@@ -80,15 +84,21 @@ echo:
@echo "AR= $(AR)" @echo "AR= $(AR)"
@echo "RANLIB= $(RANLIB)" @echo "RANLIB= $(RANLIB)"
@echo "RM= $(RM)" @echo "RM= $(RM)"
@echo "UNAME= $(UNAME)"
# Convenience targets for popular platforms # Convenience targets for popular platforms.
ALL= all ALL= all
none: help:
@echo "Please do 'make PLATFORM' where PLATFORM is one of these:" @echo "Do 'make PLATFORM' where PLATFORM is one of these:"
@echo " $(PLATS)" @echo " $(PLATS)"
@echo "See doc/readme.html for complete instructions."
guess:
@echo Guessing `$(UNAME)`
@$(MAKE) `$(UNAME)`
aix: AIX aix:
$(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall" $(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall"
bsd: bsd:
...@@ -98,22 +108,28 @@ c89: ...@@ -98,22 +108,28 @@ c89:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_C89" CC="gcc -std=c89" $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_C89" CC="gcc -std=c89"
@echo '' @echo ''
@echo '*** C89 does not guarantee 64-bit integers for Lua.' @echo '*** C89 does not guarantee 64-bit integers for Lua.'
@echo '*** Make sure to compile all external Lua libraries'
@echo '*** with LUA_USE_C89 to ensure consistency'
@echo '' @echo ''
FreeBSD NetBSD OpenBSD freebsd:
freebsd: $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE -I/usr/include/edit" SYSLIBS="-Wl,-E -ledit" CC="cc"
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -I/usr/include/edit" SYSLIBS="-Wl,-E -ledit" CC="cc"
generic: $(ALL) generic: $(ALL)
linux: Linux linux: linux-noreadline
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline"
linux-noreadline:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl"
macosx: linux-readline:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX" SYSLIBS="-lreadline" $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE" SYSLIBS="-Wl,-E -ldl -lreadline"
Darwin macos macosx:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_MACOSX -DLUA_USE_READLINE" SYSLIBS="-lreadline"
mingw: mingw:
$(MAKE) "LUA_A=lua53.dll" "LUA_T=lua.exe" \ $(MAKE) "LUA_A=lua54.dll" "LUA_T=lua.exe" \
"AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \ "AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \
"SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe "SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe
$(MAKE) "LUAC_T=luac.exe" luac.exe $(MAKE) "LUAC_T=luac.exe" luac.exe
...@@ -121,11 +137,21 @@ mingw: ...@@ -121,11 +137,21 @@ mingw:
posix: posix:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX" $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX"
solaris: SunOS solaris:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT" SYSLIBS="-ldl" $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN -D_REENTRANT" SYSLIBS="-ldl"
# list targets that do not create files (but not all makes understand .PHONY) # Targets that do not create files (not all makes understand .PHONY).
.PHONY: all $(PLATS) default o a clean depend echo none .PHONY: all $(PLATS) help test clean default o a depend echo
# Compiler modules may use special flags.
llex.o:
$(CC) $(CFLAGS) $(CMCFLAGS) -c llex.c
lparser.o:
$(CC) $(CFLAGS) $(CMCFLAGS) -c lparser.c
lcode.o:
$(CC) $(CFLAGS) $(CMCFLAGS) -c lcode.c
# DO NOT DELETE # DO NOT DELETE
...@@ -134,7 +160,6 @@ lapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ ...@@ -134,7 +160,6 @@ lapi.o: lapi.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
ltable.h lundump.h lvm.h ltable.h lundump.h lvm.h
lauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h lauxlib.o: lauxlib.c lprefix.h lua.h luaconf.h lauxlib.h
lbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h lbaselib.o: lbaselib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
lbitlib.o: lbitlib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
lcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \ lcode.o: lcode.c lprefix.h lua.h luaconf.h lcode.h llex.h lobject.h \
llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \ llimits.h lzio.h lmem.h lopcodes.h lparser.h ldebug.h lstate.h ltm.h \
ldo.h lgc.h lstring.h ltable.h lvm.h ldo.h lgc.h lstring.h ltable.h lvm.h
...@@ -149,8 +174,8 @@ ldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \ ...@@ -149,8 +174,8 @@ ldo.o: ldo.c lprefix.h lua.h luaconf.h lapi.h llimits.h lstate.h \
lparser.h lstring.h ltable.h lundump.h lvm.h lparser.h lstring.h ltable.h lundump.h lvm.h
ldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \ ldump.o: ldump.c lprefix.h lua.h luaconf.h lobject.h llimits.h lstate.h \
ltm.h lzio.h lmem.h lundump.h ltm.h lzio.h lmem.h lundump.h
lfunc.o: lfunc.c lprefix.h lua.h luaconf.h lfunc.h lobject.h llimits.h \ lfunc.o: lfunc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
lgc.h lstate.h ltm.h lzio.h lmem.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h
lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ lgc.o: lgc.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h
linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h linit.o: linit.c lprefix.h lua.h luaconf.h lualib.h lauxlib.h
...@@ -180,17 +205,17 @@ ltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ ...@@ -180,17 +205,17 @@ ltable.o: ltable.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h
ltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h ltablib.o: ltablib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
ltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ ltm.o: ltm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
llimits.h ltm.h lzio.h lmem.h ldo.h lstring.h lgc.h ltable.h lvm.h llimits.h ltm.h lzio.h lmem.h ldo.h lgc.h lstring.h ltable.h lvm.h
lua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h lua.o: lua.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
luac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h lobject.h llimits.h \ luac.o: luac.c lprefix.h lua.h luaconf.h lauxlib.h ldebug.h lstate.h \
lstate.h ltm.h lzio.h lmem.h lundump.h ldebug.h lopcodes.h lobject.h llimits.h ltm.h lzio.h lmem.h lopcodes.h lopnames.h lundump.h
lundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \ lundump.o: lundump.c lprefix.h lua.h luaconf.h ldebug.h lstate.h \
lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \ lobject.h llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lstring.h lgc.h \
lundump.h lundump.h
lutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h lutf8lib.o: lutf8lib.c lprefix.h lua.h luaconf.h lauxlib.h lualib.h
lvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \ lvm.o: lvm.c lprefix.h lua.h luaconf.h ldebug.h lstate.h lobject.h \
llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \ llimits.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lopcodes.h lstring.h \
ltable.h lvm.h ltable.h lvm.h ljumptab.h
lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \ lzio.o: lzio.c lprefix.h lua.h luaconf.h llimits.h lmem.h lstate.h \
lobject.h ltm.h lzio.h lobject.h ltm.h lzio.h
......
This diff is collapsed.
/* /*
** $Id: lapi.h,v 2.9.1.1 2017/04/19 17:20:42 roberto Exp $ ** $Id: lapi.h $
** Auxiliary functions from Lua API ** Auxiliary functions from Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
...@@ -11,14 +11,39 @@ ...@@ -11,14 +11,39 @@
#include "llimits.h" #include "llimits.h"
#include "lstate.h" #include "lstate.h"
/* Increments 'L->top', checking for stack overflows */
#define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \
"stack overflow");} "stack overflow");}
/*
** If a call returns too many multiple returns, the callee may not have
** stack space to accommodate all results. In this case, this macro
** increases its stack space ('L->ci->top').
*/
#define adjustresults(L,nres) \ #define adjustresults(L,nres) \
{ if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
/* Ensure the stack has at least 'n' elements */
#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
"not enough elements in the stack") "not enough elements in the stack")
/*
** To reduce the overhead of returning from C functions, the presence of
** to-be-closed variables in these functions is coded in the CallInfo's
** field 'nresults', in a way that functions with no to-be-closed variables
** with zero, one, or "all" wanted results have no overhead. Functions
** with other number of wanted results, as well as functions with
** variables to be closed, have an extra check.
*/
#define hastocloseCfunc(n) ((n) < LUA_MULTRET)
/* Map [-1, inf) (range of 'nresults') into (-inf, -2] */
#define codeNresults(n) (-(n) - 3)
#define decodeNresults(n) (-(n) - 3)
#endif #endif
This diff is collapsed.
/* /*
** $Id: lauxlib.h,v 1.131.1.1 2017/04/19 17:20:42 roberto Exp $ ** $Id: lauxlib.h $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
...@@ -12,9 +12,16 @@ ...@@ -12,9 +12,16 @@
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include "luaconf.h"
#include "lua.h" #include "lua.h"
/* global table */
#define LUA_GNAME "_G"
typedef struct luaL_Buffer luaL_Buffer;
/* extra error code for 'luaL_loadfilex' */ /* extra error code for 'luaL_loadfilex' */
#define LUA_ERRFILE (LUA_ERRERR+1) #define LUA_ERRFILE (LUA_ERRERR+1)
...@@ -44,6 +51,7 @@ LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); ...@@ -44,6 +51,7 @@ LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e);
LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e);
LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len); LUALIB_API const char *(luaL_tolstring) (lua_State *L, int idx, size_t *len);
LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg); LUALIB_API int (luaL_argerror) (lua_State *L, int arg, const char *extramsg);
LUALIB_API int (luaL_typeerror) (lua_State *L, int arg, const char *tname);
LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg, LUALIB_API const char *(luaL_checklstring) (lua_State *L, int arg,
size_t *l); size_t *l);
LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg, LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg,
...@@ -73,6 +81,7 @@ LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def, ...@@ -73,6 +81,7 @@ LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,
LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname); LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
LUALIB_API int (luaL_execresult) (lua_State *L, int stat); LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
/* predefined references */ /* predefined references */
#define LUA_NOREF (-2) #define LUA_NOREF (-2)
#define LUA_REFNIL (-1) #define LUA_REFNIL (-1)
...@@ -93,8 +102,10 @@ LUALIB_API lua_State *(luaL_newstate) (void); ...@@ -93,8 +102,10 @@ LUALIB_API lua_State *(luaL_newstate) (void);
LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx); LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,
const char *r); const char *p, const char *r);
LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s,
const char *p, const char *r);
LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup); LUALIB_API void (luaL_setfuncs) (lua_State *L, const luaL_Reg *l, int nup);
...@@ -120,7 +131,11 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, ...@@ -120,7 +131,11 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
(luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0)) (luaL_checkversion(L), luaL_newlibtable(L,l), luaL_setfuncs(L,l,0))
#define luaL_argcheck(L, cond,arg,extramsg) \ #define luaL_argcheck(L, cond,arg,extramsg) \
((void)((cond) || luaL_argerror(L, (arg), (extramsg)))) ((void)(luai_likely(cond) || luaL_argerror(L, (arg), (extramsg))))
#define luaL_argexpected(L,cond,arg,tname) \
((void)(luai_likely(cond) || luaL_typeerror(L, (arg), (tname))))
#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) #define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL))
#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) #define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL))
...@@ -139,19 +154,46 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname, ...@@ -139,19 +154,46 @@ LUALIB_API void (luaL_requiref) (lua_State *L, const char *modname,
#define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL) #define luaL_loadbuffer(L,s,sz,n) luaL_loadbufferx(L,s,sz,n,NULL)
/* push the value used to represent failure/error */
#define luaL_pushfail(L) lua_pushnil(L)
/*
** Internal assertions for in-house debugging
*/
#if !defined(lua_assert)
#if defined LUAI_ASSERT
#include <assert.h>
#define lua_assert(c) assert(c)
#else
#define lua_assert(c) ((void)0)
#endif
#endif
/* /*
** {====================================================== ** {======================================================
** Generic Buffer manipulation ** Generic Buffer manipulation
** ======================================================= ** =======================================================
*/ */
typedef struct luaL_Buffer { struct luaL_Buffer {
char *b; /* buffer address */ char *b; /* buffer address */
size_t size; /* buffer size */ size_t size; /* buffer size */
size_t n; /* number of characters in buffer */ size_t n; /* number of characters in buffer */
lua_State *L; lua_State *L;
char initb[LUAL_BUFFERSIZE]; /* initial buffer */ union {
} luaL_Buffer; LUAI_MAXALIGN; /* ensure maximum alignment for buffer */
char b[LUAL_BUFFERSIZE]; /* initial buffer */
} init;
};
#define luaL_bufflen(bf) ((bf)->n)
#define luaL_buffaddr(bf) ((bf)->b)
#define luaL_addchar(B,c) \ #define luaL_addchar(B,c) \
...@@ -160,6 +202,8 @@ typedef struct luaL_Buffer { ...@@ -160,6 +202,8 @@ typedef struct luaL_Buffer {
#define luaL_addsize(B,s) ((B)->n += (s)) #define luaL_addsize(B,s) ((B)->n += (s))
#define luaL_buffsub(B,s) ((B)->n -= (s))
LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B);
LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz); LUALIB_API char *(luaL_prepbuffsize) (luaL_Buffer *B, size_t sz);
LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l);
...@@ -197,21 +241,6 @@ typedef struct luaL_Stream { ...@@ -197,21 +241,6 @@ typedef struct luaL_Stream {
/* }====================================================== */ /* }====================================================== */
/* compatibility with old module system */
#if defined(LUA_COMPAT_MODULE)
LUALIB_API void (luaL_pushmodule) (lua_State *L, const char *modname,
int sizehint);
LUALIB_API void (luaL_openlib) (lua_State *L, const char *libname,
const luaL_Reg *l, int nup);
#define luaL_register(L,n,l) (luaL_openlib(L,(n),(l),0))
#endif
/* /*
** {================================================================== ** {==================================================================
** "Abstraction Layer" for basic report of messages and errors ** "Abstraction Layer" for basic report of messages and errors
......
This diff is collapsed.
This diff is collapsed.
/* /*
** $Id: lcode.h,v 1.64.1.1 2017/04/19 17:20:42 roberto Exp $ ** $Id: lcode.h $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
...@@ -24,40 +24,53 @@ ...@@ -24,40 +24,53 @@
** grep "ORDER OPR" if you change these enums (ORDER OP) ** grep "ORDER OPR" if you change these enums (ORDER OP)
*/ */
typedef enum BinOpr { typedef enum BinOpr {
/* arithmetic operators */
OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW,
OPR_DIV, OPR_DIV, OPR_IDIV,
OPR_IDIV, /* bitwise operators */
OPR_BAND, OPR_BOR, OPR_BXOR, OPR_BAND, OPR_BOR, OPR_BXOR,
OPR_SHL, OPR_SHR, OPR_SHL, OPR_SHR,
/* string operator */
OPR_CONCAT, OPR_CONCAT,
/* comparison operators */
OPR_EQ, OPR_LT, OPR_LE, OPR_EQ, OPR_LT, OPR_LE,
OPR_NE, OPR_GT, OPR_GE, OPR_NE, OPR_GT, OPR_GE,
/* logical operators */
OPR_AND, OPR_OR, OPR_AND, OPR_OR,
OPR_NOBINOPR OPR_NOBINOPR
} BinOpr; } BinOpr;
/* true if operation is foldable (that is, it is arithmetic or bitwise) */
#define foldbinop(op) ((op) <= OPR_SHR)
#define luaK_codeABC(fs,o,a,b,c) luaK_codeABCk(fs,o,a,b,c,0)
typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
/* get (pointer to) instruction of given 'expdesc' */ /* get (pointer to) instruction of given 'expdesc' */
#define getinstruction(fs,e) ((fs)->f->code[(e)->u.info]) #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info])
#define luaK_codeAsBx(fs,o,A,sBx) luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)
#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
#define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t)
LUAI_FUNC int luaK_code (FuncState *fs, Instruction i);
LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); LUAI_FUNC int luaK_codeAsBx (FuncState *fs, OpCode o, int A, int Bx);
LUAI_FUNC int luaK_codek (FuncState *fs, int reg, int k); LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A,
int B, int C, int k);
LUAI_FUNC int luaK_isKint (expdesc *e);
LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v);
LUAI_FUNC void luaK_fixline (FuncState *fs, int line); LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); LUAI_FUNC void luaK_checkstack (FuncState *fs, int n);
LUAI_FUNC int luaK_stringK (FuncState *fs, TString *s); LUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n);
LUAI_FUNC int luaK_intK (FuncState *fs, lua_Integer n);
LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);
LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);
...@@ -75,14 +88,17 @@ LUAI_FUNC int luaK_jump (FuncState *fs); ...@@ -75,14 +88,17 @@ LUAI_FUNC int luaK_jump (FuncState *fs);
LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret);
LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target);
LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list);
LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level);
LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2);
LUAI_FUNC int luaK_getlabel (FuncState *fs); LUAI_FUNC int luaK_getlabel (FuncState *fs);
LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line);
LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1,
expdesc *v2, int line); expdesc *v2, int line);
LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc,
int ra, int asize, int hsize);
LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore);
LUAI_FUNC void luaK_finish (FuncState *fs);
LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg);
#endif #endif
/* /*
** $Id: lcorolib.c,v 1.10.1.1 2017/04/19 17:20:42 roberto Exp $ ** $Id: lcorolib.c $
** Coroutine Library ** Coroutine Library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
...@@ -20,26 +20,25 @@ ...@@ -20,26 +20,25 @@
static lua_State *getco (lua_State *L) { static lua_State *getco (lua_State *L) {
lua_State *co = lua_tothread(L, 1); lua_State *co = lua_tothread(L, 1);
luaL_argcheck(L, co, 1, "thread expected"); luaL_argexpected(L, co, 1, "thread");
return co; return co;
} }
/*
** Resumes a coroutine. Returns the number of results for non-error
** cases or -1 for errors.
*/
static int auxresume (lua_State *L, lua_State *co, int narg) { static int auxresume (lua_State *L, lua_State *co, int narg) {
int status; int status, nres;
if (!lua_checkstack(co, narg)) { if (l_unlikely(!lua_checkstack(co, narg))) {
lua_pushliteral(L, "too many arguments to resume"); lua_pushliteral(L, "too many arguments to resume");
return -1; /* error flag */ return -1; /* error flag */
} }
if (lua_status(co) == LUA_OK && lua_gettop(co) == 0) {
lua_pushliteral(L, "cannot resume dead coroutine");
return -1; /* error flag */
}
lua_xmove(L, co, narg); lua_xmove(L, co, narg);
status = lua_resume(co, L, narg); status = lua_resume(co, L, narg, &nres);
if (status == LUA_OK || status == LUA_YIELD) { if (l_likely(status == LUA_OK || status == LUA_YIELD)) {
int nres = lua_gettop(co); if (l_unlikely(!lua_checkstack(L, nres + 1))) {
if (!lua_checkstack(L, nres + 1)) {
lua_pop(co, nres); /* remove results anyway */ lua_pop(co, nres); /* remove results anyway */
lua_pushliteral(L, "too many results to resume"); lua_pushliteral(L, "too many results to resume");
return -1; /* error flag */ return -1; /* error flag */
...@@ -58,7 +57,7 @@ static int luaB_coresume (lua_State *L) { ...@@ -58,7 +57,7 @@ static int luaB_coresume (lua_State *L) {
lua_State *co = getco(L); lua_State *co = getco(L);
int r; int r;
r = auxresume(L, co, lua_gettop(L) - 1); r = auxresume(L, co, lua_gettop(L) - 1);
if (r < 0) { if (l_unlikely(r < 0)) {
lua_pushboolean(L, 0); lua_pushboolean(L, 0);
lua_insert(L, -2); lua_insert(L, -2);
return 2; /* return false + error message */ return 2; /* return false + error message */
...@@ -74,9 +73,16 @@ static int luaB_coresume (lua_State *L) { ...@@ -74,9 +73,16 @@ static int luaB_coresume (lua_State *L) {
static int luaB_auxwrap (lua_State *L) { static int luaB_auxwrap (lua_State *L) {
lua_State *co = lua_tothread(L, lua_upvalueindex(1)); lua_State *co = lua_tothread(L, lua_upvalueindex(1));
int r = auxresume(L, co, lua_gettop(L)); int r = auxresume(L, co, lua_gettop(L));
if (r < 0) { if (l_unlikely(r < 0)) { /* error? */
if (lua_type(L, -1) == LUA_TSTRING) { /* error object is a string? */ int stat = lua_status(co);
luaL_where(L, 1); /* add extra info */ if (stat != LUA_OK && stat != LUA_YIELD) { /* error in the coroutine? */
stat = lua_resetthread(co); /* close its tbc variables */
lua_assert(stat != LUA_OK);
lua_xmove(co, L, 1); /* copy error message */
}
if (stat != LUA_ERRMEM && /* not a memory error and ... */
lua_type(L, -1) == LUA_TSTRING) { /* ... error object is a string? */
luaL_where(L, 1); /* add extra info, if available */
lua_insert(L, -2); lua_insert(L, -2);
lua_concat(L, 2); lua_concat(L, 2);
} }
...@@ -108,35 +114,48 @@ static int luaB_yield (lua_State *L) { ...@@ -108,35 +114,48 @@ static int luaB_yield (lua_State *L) {
} }
static int luaB_costatus (lua_State *L) { #define COS_RUN 0
lua_State *co = getco(L); #define COS_DEAD 1
if (L == co) lua_pushliteral(L, "running"); #define COS_YIELD 2
#define COS_NORM 3
static const char *const statname[] =
{"running", "dead", "suspended", "normal"};
static int auxstatus (lua_State *L, lua_State *co) {
if (L == co) return COS_RUN;
else { else {
switch (lua_status(co)) { switch (lua_status(co)) {
case LUA_YIELD: case LUA_YIELD:
lua_pushliteral(L, "suspended"); return COS_YIELD;
break;
case LUA_OK: { case LUA_OK: {
lua_Debug ar; lua_Debug ar;
if (lua_getstack(co, 0, &ar) > 0) /* does it have frames? */ if (lua_getstack(co, 0, &ar)) /* does it have frames? */
lua_pushliteral(L, "normal"); /* it is running */ return COS_NORM; /* it is running */
else if (lua_gettop(co) == 0) else if (lua_gettop(co) == 0)
lua_pushliteral(L, "dead"); return COS_DEAD;
else else
lua_pushliteral(L, "suspended"); /* initial state */ return COS_YIELD; /* initial state */
break;
} }
default: /* some error occurred */ default: /* some error occurred */
lua_pushliteral(L, "dead"); return COS_DEAD;
break;
} }
} }
}
static int luaB_costatus (lua_State *L) {
lua_State *co = getco(L);
lua_pushstring(L, statname[auxstatus(L, co)]);
return 1; return 1;
} }
static int luaB_yieldable (lua_State *L) { static int luaB_yieldable (lua_State *L) {
lua_pushboolean(L, lua_isyieldable(L)); lua_State *co = lua_isnone(L, 1) ? L : getco(L);
lua_pushboolean(L, lua_isyieldable(co));
return 1; return 1;
} }
...@@ -148,6 +167,28 @@ static int luaB_corunning (lua_State *L) { ...@@ -148,6 +167,28 @@ static int luaB_corunning (lua_State *L) {
} }
static int luaB_close (lua_State *L) {
lua_State *co = getco(L);
int status = auxstatus(L, co);
switch (status) {
case COS_DEAD: case COS_YIELD: {
status = lua_resetthread(co);
if (status == LUA_OK) {
lua_pushboolean(L, 1);
return 1;
}
else {
lua_pushboolean(L, 0);
lua_xmove(co, L, 1); /* copy error message */
return 2;
}
}
default: /* normal or running coroutine */
return luaL_error(L, "cannot close a %s coroutine", statname[status]);
}
}
static const luaL_Reg co_funcs[] = { static const luaL_Reg co_funcs[] = {
{"create", luaB_cocreate}, {"create", luaB_cocreate},
{"resume", luaB_coresume}, {"resume", luaB_coresume},
...@@ -156,6 +197,7 @@ static const luaL_Reg co_funcs[] = { ...@@ -156,6 +197,7 @@ static const luaL_Reg co_funcs[] = {
{"wrap", luaB_cowrap}, {"wrap", luaB_cowrap},
{"yield", luaB_yield}, {"yield", luaB_yield},
{"isyieldable", luaB_yieldable}, {"isyieldable", luaB_yieldable},
{"close", luaB_close},
{NULL, NULL} {NULL, NULL}
}; };
......
/* /*
** $Id: lctype.c,v 1.12.1.1 2017/04/19 17:20:42 roberto Exp $ ** $Id: lctype.c $
** 'ctype' functions for Lua ** 'ctype' functions for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
...@@ -16,6 +16,15 @@ ...@@ -16,6 +16,15 @@
#include <limits.h> #include <limits.h>
#if defined (LUA_UCID) /* accept UniCode IDentifiers? */
/* consider all non-ascii codepoints to be alphabetic */
#define NONA 0x01
#else
#define NONA 0x00 /* default */
#endif
LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {
0x00, /* EOZ */ 0x00, /* EOZ */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */
...@@ -34,22 +43,22 @@ LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { ...@@ -34,22 +43,22 @@ LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = {
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */
0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8. */ NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 8. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 9. */ NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 9. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* a. */ NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* a. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* b. */ NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* b. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* c. */ 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, /* c. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* d. */ NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* d. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* e. */ NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* e. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* f. */ NONA, NONA, NONA, NONA, NONA, 0x00, 0x00, 0x00, /* f. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; };
#endif /* } */ #endif /* } */
/* /*
** $Id: lctype.h,v 1.12.1.1 2013/04/12 18:48:47 roberto Exp $ ** $Id: lctype.h $
** 'ctype' functions for Lua ** 'ctype' functions for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
/* /*
** WARNING: the functions defined here do not necessarily correspond ** WARNING: the functions defined here do not necessarily correspond
** to the similar functions in the standard C ctype.h. They are ** to the similar functions in the standard C ctype.h. They are
** optimized for the specific needs of Lua ** optimized for the specific needs of Lua.
*/ */
#if !defined(LUA_USE_CTYPE) #if !defined(LUA_USE_CTYPE)
...@@ -61,14 +61,20 @@ ...@@ -61,14 +61,20 @@
#define lisprint(c) testprop(c, MASK(PRINTBIT)) #define lisprint(c) testprop(c, MASK(PRINTBIT))
#define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) #define lisxdigit(c) testprop(c, MASK(XDIGITBIT))
/* /*
** this 'ltolower' only works for alphabetic characters ** In ASCII, this 'ltolower' is correct for alphabetic characters and
** for '.'. That is enough for Lua needs. ('check_exp' ensures that
** the character either is an upper-case letter or is unchanged by
** the transformation, which holds for lower-case letters and '.'.)
*/ */
#define ltolower(c) ((c) | ('A' ^ 'a')) #define ltolower(c) \
check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \
(c) | ('A' ^ 'a'))
/* two more entries for 0 and -1 (EOZ) */ /* one entry for each character and for -1 (EOZ) */
LUAI_DDEC const lu_byte luai_ctype_[UCHAR_MAX + 2]; LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];)
#else /* }{ */ #else /* }{ */
......
/* /*
** $Id: ldblib.c,v 1.151.1.1 2017/04/19 17:20:42 roberto Exp $ ** $Id: ldblib.c $
** Interface from Lua to its debug API ** Interface from Lua to its debug API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
...@@ -21,10 +21,10 @@ ...@@ -21,10 +21,10 @@
/* /*
** The hook table at registry[&HOOKKEY] maps threads to their current ** The hook table at registry[HOOKKEY] maps threads to their current
** hook function. (We only need the unique address of 'HOOKKEY'.) ** hook function.
*/ */
static const int HOOKKEY = 0; static const char *const HOOKKEY = "_HOOKKEY";
/* /*
...@@ -33,7 +33,7 @@ static const int HOOKKEY = 0; ...@@ -33,7 +33,7 @@ static const int HOOKKEY = 0;
** checked. ** checked.
*/ */
static void checkstack (lua_State *L, lua_State *L1, int n) { static void checkstack (lua_State *L, lua_State *L1, int n) {
if (L != L1 && !lua_checkstack(L1, n)) if (l_unlikely(L != L1 && !lua_checkstack(L1, n)))
luaL_error(L, "stack overflow"); luaL_error(L, "stack overflow");
} }
...@@ -55,8 +55,7 @@ static int db_getmetatable (lua_State *L) { ...@@ -55,8 +55,7 @@ static int db_getmetatable (lua_State *L) {
static int db_setmetatable (lua_State *L) { static int db_setmetatable (lua_State *L) {
int t = lua_type(L, 2); int t = lua_type(L, 2);
luaL_argcheck(L, t == LUA_TNIL || t == LUA_TTABLE, 2, luaL_argexpected(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil or table");
"nil or table expected");
lua_settop(L, 2); lua_settop(L, 2);
lua_setmetatable(L, 1); lua_setmetatable(L, 1);
return 1; /* return 1st argument */ return 1; /* return 1st argument */
...@@ -64,19 +63,24 @@ static int db_setmetatable (lua_State *L) { ...@@ -64,19 +63,24 @@ static int db_setmetatable (lua_State *L) {
static int db_getuservalue (lua_State *L) { static int db_getuservalue (lua_State *L) {
int n = (int)luaL_optinteger(L, 2, 1);
if (lua_type(L, 1) != LUA_TUSERDATA) if (lua_type(L, 1) != LUA_TUSERDATA)
lua_pushnil(L); luaL_pushfail(L);
else else if (lua_getiuservalue(L, 1, n) != LUA_TNONE) {
lua_getuservalue(L, 1); lua_pushboolean(L, 1);
return 2;
}
return 1; return 1;
} }
static int db_setuservalue (lua_State *L) { static int db_setuservalue (lua_State *L) {
int n = (int)luaL_optinteger(L, 3, 1);
luaL_checktype(L, 1, LUA_TUSERDATA); luaL_checktype(L, 1, LUA_TUSERDATA);
luaL_checkany(L, 2); luaL_checkany(L, 2);
lua_settop(L, 2); lua_settop(L, 2);
lua_setuservalue(L, 1); if (!lua_setiuservalue(L, 1, n))
luaL_pushfail(L);
return 1; return 1;
} }
...@@ -146,8 +150,9 @@ static int db_getinfo (lua_State *L) { ...@@ -146,8 +150,9 @@ static int db_getinfo (lua_State *L) {
lua_Debug ar; lua_Debug ar;
int arg; int arg;
lua_State *L1 = getthread(L, &arg); lua_State *L1 = getthread(L, &arg);
const char *options = luaL_optstring(L, arg+2, "flnStu"); const char *options = luaL_optstring(L, arg+2, "flnSrtu");
checkstack(L, L1, 3); checkstack(L, L1, 3);
luaL_argcheck(L, options[0] != '>', arg + 2, "invalid option '>'");
if (lua_isfunction(L, arg + 1)) { /* info about a function? */ if (lua_isfunction(L, arg + 1)) { /* info about a function? */
options = lua_pushfstring(L, ">%s", options); /* add '>' to 'options' */ options = lua_pushfstring(L, ">%s", options); /* add '>' to 'options' */
lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */ lua_pushvalue(L, arg + 1); /* move function to 'L1' stack */
...@@ -155,7 +160,7 @@ static int db_getinfo (lua_State *L) { ...@@ -155,7 +160,7 @@ static int db_getinfo (lua_State *L) {
} }
else { /* stack level */ else { /* stack level */
if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) { if (!lua_getstack(L1, (int)luaL_checkinteger(L, arg + 1), &ar)) {
lua_pushnil(L); /* level out of range */ luaL_pushfail(L); /* level out of range */
return 1; return 1;
} }
} }
...@@ -163,7 +168,8 @@ static int db_getinfo (lua_State *L) { ...@@ -163,7 +168,8 @@ static int db_getinfo (lua_State *L) {
return luaL_argerror(L, arg+2, "invalid option"); return luaL_argerror(L, arg+2, "invalid option");
lua_newtable(L); /* table to collect results */ lua_newtable(L); /* table to collect results */
if (strchr(options, 'S')) { if (strchr(options, 'S')) {
settabss(L, "source", ar.source); lua_pushlstring(L, ar.source, ar.srclen);
lua_setfield(L, -2, "source");
settabss(L, "short_src", ar.short_src); settabss(L, "short_src", ar.short_src);
settabsi(L, "linedefined", ar.linedefined); settabsi(L, "linedefined", ar.linedefined);
settabsi(L, "lastlinedefined", ar.lastlinedefined); settabsi(L, "lastlinedefined", ar.lastlinedefined);
...@@ -180,6 +186,10 @@ static int db_getinfo (lua_State *L) { ...@@ -180,6 +186,10 @@ static int db_getinfo (lua_State *L) {
settabss(L, "name", ar.name); settabss(L, "name", ar.name);
settabss(L, "namewhat", ar.namewhat); settabss(L, "namewhat", ar.namewhat);
} }
if (strchr(options, 'r')) {
settabsi(L, "ftransfer", ar.ftransfer);
settabsi(L, "ntransfer", ar.ntransfer);
}
if (strchr(options, 't')) if (strchr(options, 't'))
settabsb(L, "istailcall", ar.istailcall); settabsb(L, "istailcall", ar.istailcall);
if (strchr(options, 'L')) if (strchr(options, 'L'))
...@@ -193,8 +203,6 @@ static int db_getinfo (lua_State *L) { ...@@ -193,8 +203,6 @@ static int db_getinfo (lua_State *L) {
static int db_getlocal (lua_State *L) { static int db_getlocal (lua_State *L) {
int arg; int arg;
lua_State *L1 = getthread(L, &arg); lua_State *L1 = getthread(L, &arg);
lua_Debug ar;
const char *name;
int nvar = (int)luaL_checkinteger(L, arg + 2); /* local-variable index */ int nvar = (int)luaL_checkinteger(L, arg + 2); /* local-variable index */
if (lua_isfunction(L, arg + 1)) { /* function argument? */ if (lua_isfunction(L, arg + 1)) { /* function argument? */
lua_pushvalue(L, arg + 1); /* push function */ lua_pushvalue(L, arg + 1); /* push function */
...@@ -202,8 +210,10 @@ static int db_getlocal (lua_State *L) { ...@@ -202,8 +210,10 @@ static int db_getlocal (lua_State *L) {
return 1; /* return only name (there is no value) */ return 1; /* return only name (there is no value) */
} }
else { /* stack-level argument */ else { /* stack-level argument */
lua_Debug ar;
const char *name;
int level = (int)luaL_checkinteger(L, arg + 1); int level = (int)luaL_checkinteger(L, arg + 1);
if (!lua_getstack(L1, level, &ar)) /* out of range? */ if (l_unlikely(!lua_getstack(L1, level, &ar))) /* out of range? */
return luaL_argerror(L, arg+1, "level out of range"); return luaL_argerror(L, arg+1, "level out of range");
checkstack(L, L1, 1); checkstack(L, L1, 1);
name = lua_getlocal(L1, &ar, nvar); name = lua_getlocal(L1, &ar, nvar);
...@@ -214,7 +224,7 @@ static int db_getlocal (lua_State *L) { ...@@ -214,7 +224,7 @@ static int db_getlocal (lua_State *L) {
return 2; return 2;
} }
else { else {
lua_pushnil(L); /* no name (nor value) */ luaL_pushfail(L); /* no name (nor value) */
return 1; return 1;
} }
} }
...@@ -228,7 +238,7 @@ static int db_setlocal (lua_State *L) { ...@@ -228,7 +238,7 @@ static int db_setlocal (lua_State *L) {
lua_Debug ar; lua_Debug ar;
int level = (int)luaL_checkinteger(L, arg + 1); int level = (int)luaL_checkinteger(L, arg + 1);
int nvar = (int)luaL_checkinteger(L, arg + 2); int nvar = (int)luaL_checkinteger(L, arg + 2);
if (!lua_getstack(L1, level, &ar)) /* out of range? */ if (l_unlikely(!lua_getstack(L1, level, &ar))) /* out of range? */
return luaL_argerror(L, arg+1, "level out of range"); return luaL_argerror(L, arg+1, "level out of range");
luaL_checkany(L, arg+3); luaL_checkany(L, arg+3);
lua_settop(L, arg+3); lua_settop(L, arg+3);
...@@ -272,25 +282,33 @@ static int db_setupvalue (lua_State *L) { ...@@ -272,25 +282,33 @@ static int db_setupvalue (lua_State *L) {
** Check whether a given upvalue from a given closure exists and ** Check whether a given upvalue from a given closure exists and
** returns its index ** returns its index
*/ */
static int checkupval (lua_State *L, int argf, int argnup) { static void *checkupval (lua_State *L, int argf, int argnup, int *pnup) {
void *id;
int nup = (int)luaL_checkinteger(L, argnup); /* upvalue index */ int nup = (int)luaL_checkinteger(L, argnup); /* upvalue index */
luaL_checktype(L, argf, LUA_TFUNCTION); /* closure */ luaL_checktype(L, argf, LUA_TFUNCTION); /* closure */
luaL_argcheck(L, (lua_getupvalue(L, argf, nup) != NULL), argnup, id = lua_upvalueid(L, argf, nup);
"invalid upvalue index"); if (pnup) {
return nup; luaL_argcheck(L, id != NULL, argnup, "invalid upvalue index");
*pnup = nup;
}
return id;
} }
static int db_upvalueid (lua_State *L) { static int db_upvalueid (lua_State *L) {
int n = checkupval(L, 1, 2); void *id = checkupval(L, 1, 2, NULL);
lua_pushlightuserdata(L, lua_upvalueid(L, 1, n)); if (id != NULL)
lua_pushlightuserdata(L, id);
else
luaL_pushfail(L);
return 1; return 1;
} }
static int db_upvaluejoin (lua_State *L) { static int db_upvaluejoin (lua_State *L) {
int n1 = checkupval(L, 1, 2); int n1, n2;
int n2 = checkupval(L, 3, 4); checkupval(L, 1, 2, &n1);
checkupval(L, 3, 4, &n2);
luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected"); luaL_argcheck(L, !lua_iscfunction(L, 1), 1, "Lua function expected");
luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected"); luaL_argcheck(L, !lua_iscfunction(L, 3), 3, "Lua function expected");
lua_upvaluejoin(L, 1, n1, 3, n2); lua_upvaluejoin(L, 1, n1, 3, n2);
...@@ -305,7 +323,7 @@ static int db_upvaluejoin (lua_State *L) { ...@@ -305,7 +323,7 @@ static int db_upvaluejoin (lua_State *L) {
static void hookf (lua_State *L, lua_Debug *ar) { static void hookf (lua_State *L, lua_Debug *ar) {
static const char *const hooknames[] = static const char *const hooknames[] =
{"call", "return", "line", "count", "tail call"}; {"call", "return", "line", "count", "tail call"};
lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY); lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY);
lua_pushthread(L); lua_pushthread(L);
if (lua_rawget(L, -2) == LUA_TFUNCTION) { /* is there a hook function? */ if (lua_rawget(L, -2) == LUA_TFUNCTION) { /* is there a hook function? */
lua_pushstring(L, hooknames[(int)ar->event]); /* push event name */ lua_pushstring(L, hooknames[(int)ar->event]); /* push event name */
...@@ -358,14 +376,12 @@ static int db_sethook (lua_State *L) { ...@@ -358,14 +376,12 @@ static int db_sethook (lua_State *L) {
count = (int)luaL_optinteger(L, arg + 3, 0); count = (int)luaL_optinteger(L, arg + 3, 0);
func = hookf; mask = makemask(smask, count); func = hookf; mask = makemask(smask, count);
} }
if (lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY) == LUA_TNIL) { if (!luaL_getsubtable(L, LUA_REGISTRYINDEX, HOOKKEY)) {
lua_createtable(L, 0, 2); /* create a hook table */ /* table just created; initialize it */
lua_pushvalue(L, -1); lua_pushliteral(L, "k");
lua_rawsetp(L, LUA_REGISTRYINDEX, &HOOKKEY); /* set it in position */
lua_pushstring(L, "k");
lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */ lua_setfield(L, -2, "__mode"); /** hooktable.__mode = "k" */
lua_pushvalue(L, -1); lua_pushvalue(L, -1);
lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */ lua_setmetatable(L, -2); /* metatable(hooktable) = hooktable */
} }
checkstack(L, L1, 1); checkstack(L, L1, 1);
lua_pushthread(L1); lua_xmove(L1, L, 1); /* key (thread) */ lua_pushthread(L1); lua_xmove(L1, L, 1); /* key (thread) */
...@@ -382,12 +398,14 @@ static int db_gethook (lua_State *L) { ...@@ -382,12 +398,14 @@ static int db_gethook (lua_State *L) {
char buff[5]; char buff[5];
int mask = lua_gethookmask(L1); int mask = lua_gethookmask(L1);
lua_Hook hook = lua_gethook(L1); lua_Hook hook = lua_gethook(L1);
if (hook == NULL) /* no hook? */ if (hook == NULL) { /* no hook? */
lua_pushnil(L); luaL_pushfail(L);
return 1;
}
else if (hook != hookf) /* external hook? */ else if (hook != hookf) /* external hook? */
lua_pushliteral(L, "external hook"); lua_pushliteral(L, "external hook");
else { /* hook table must exist */ else { /* hook table must exist */
lua_rawgetp(L, LUA_REGISTRYINDEX, &HOOKKEY); lua_getfield(L, LUA_REGISTRYINDEX, HOOKKEY);
checkstack(L, L1, 1); checkstack(L, L1, 1);
lua_pushthread(L1); lua_xmove(L1, L, 1); lua_pushthread(L1); lua_xmove(L1, L, 1);
lua_rawget(L, -2); /* 1st result = hooktable[L1] */ lua_rawget(L, -2); /* 1st result = hooktable[L1] */
...@@ -403,12 +421,12 @@ static int db_debug (lua_State *L) { ...@@ -403,12 +421,12 @@ static int db_debug (lua_State *L) {
for (;;) { for (;;) {
char buffer[250]; char buffer[250];
lua_writestringerror("%s", "lua_debug> "); lua_writestringerror("%s", "lua_debug> ");
if (fgets(buffer, sizeof(buffer), stdin) == 0 || if (fgets(buffer, sizeof(buffer), stdin) == NULL ||
strcmp(buffer, "cont\n") == 0) strcmp(buffer, "cont\n") == 0)
return 0; return 0;
if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") || if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
lua_pcall(L, 0, 0, 0)) lua_pcall(L, 0, 0, 0))
lua_writestringerror("%s\n", lua_tostring(L, -1)); lua_writestringerror("%s\n", luaL_tolstring(L, -1, NULL));
lua_settop(L, 0); /* remove eventual returns */ lua_settop(L, 0); /* remove eventual returns */
} }
} }
...@@ -428,6 +446,14 @@ static int db_traceback (lua_State *L) { ...@@ -428,6 +446,14 @@ static int db_traceback (lua_State *L) {
} }
static int db_setcstacklimit (lua_State *L) {
int limit = (int)luaL_checkinteger(L, 1);
int res = lua_setcstacklimit(L, limit);
lua_pushinteger(L, res);
return 1;
}
static const luaL_Reg dblib[] = { static const luaL_Reg dblib[] = {
{"debug", db_debug}, {"debug", db_debug},
{"getuservalue", db_getuservalue}, {"getuservalue", db_getuservalue},
...@@ -445,6 +471,7 @@ static const luaL_Reg dblib[] = { ...@@ -445,6 +471,7 @@ static const luaL_Reg dblib[] = {
{"setmetatable", db_setmetatable}, {"setmetatable", db_setmetatable},
{"setupvalue", db_setupvalue}, {"setupvalue", db_setupvalue},
{"traceback", db_traceback}, {"traceback", db_traceback},
{"setcstacklimit", db_setcstacklimit},
{NULL, NULL} {NULL, NULL}
}; };
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* /*
** $Id: lzio.c,v 1.37.1.1 2017/04/19 17:20:42 roberto Exp $ ** $Id: lzio.c $
** Buffered streams ** Buffered streams
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment