Browse Source

removed compatibility code with older versions

pull/15/head
Roberto Ierusalimschy 7 years ago
parent
commit
34b00c16e2
  1. 83
      lauxlib.c
  2. 17
      lauxlib.h
  3. 38
      lbaselib.c
  4. 5
      linit.c
  5. 95
      loadlib.c
  6. 4
      lobject.c
  7. 28
      ltablib.c
  8. 12
      ltests.h
  9. 80
      luaconf.h
  10. 5
      lualib.h

83
lauxlib.c

@ -1,5 +1,5 @@
/* /*
** $Id: lauxlib.c,v 1.292 2018/01/29 19:13:27 roberto Exp roberto $ ** $Id: lauxlib.c,v 1.293 2018/02/21 13:48:44 roberto Exp roberto $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -845,87 +845,6 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
} }
/*
** {======================================================
** Compatibility with 5.1 module functions
** =======================================================
*/
#if defined(LUA_COMPAT_MODULE)
static const char *luaL_findtable (lua_State *L, int idx,
const char *fname, int szhint) {
const char *e;
if (idx) lua_pushvalue(L, idx);
do {
e = strchr(fname, '.');
if (e == NULL) e = fname + strlen(fname);
lua_pushlstring(L, fname, e - fname);
if (lua_rawget(L, -2) == LUA_TNIL) { /* no such field? */
lua_pop(L, 1); /* remove this nil */
lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */
lua_pushlstring(L, fname, e - fname);
lua_pushvalue(L, -2);
lua_settable(L, -4); /* set new table into field */
}
else if (!lua_istable(L, -1)) { /* field has a non-table value? */
lua_pop(L, 2); /* remove table and value */
return fname; /* return problematic part of the name */
}
lua_remove(L, -2); /* remove previous table */
fname = e + 1;
} while (*e == '.');
return NULL;
}
/*
** Count number of elements in a luaL_Reg list.
*/
static int libsize (const luaL_Reg *l) {
int size = 0;
for (; l && l->name; l++) size++;
return size;
}
/*
** Find or create a module table with a given name. The function
** first looks at the LOADED table and, if that fails, try a
** global variable with that name. In any case, leaves on the stack
** the module table.
*/
LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname,
int sizehint) {
luaL_findtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE, 1);
if (lua_getfield(L, -1, modname) != LUA_TTABLE) { /* no LOADED[modname]? */
lua_pop(L, 1); /* remove previous result */
/* try global variable (and create one if it does not exist) */
lua_pushglobaltable(L);
if (luaL_findtable(L, 0, modname, sizehint) != NULL)
luaL_error(L, "name conflict for module '%s'", modname);
lua_pushvalue(L, -1);
lua_setfield(L, -3, modname); /* LOADED[modname] = new table */
}
lua_remove(L, -2); /* remove LOADED table */
}
LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
const luaL_Reg *l, int nup) {
luaL_checkversion(L);
if (libname) {
luaL_pushmodule(L, libname, libsize(l)); /* get/create library table */
lua_insert(L, -(nup + 1)); /* move library table to below upvalues */
}
if (l)
luaL_setfuncs(L, l, nup);
else
lua_pop(L, nup); /* remove upvalues */
}
#endif
/* }====================================================== */
/* /*
** set functions from list 'l' into table at top - 'nup'; each ** set functions from list 'l' into table at top - 'nup'; each
** function gets the 'nup' elements at the top as upvalues. ** function gets the 'nup' elements at the top as upvalues.

17
lauxlib.h

@ -1,5 +1,5 @@
/* /*
** $Id: lauxlib.h,v 1.132 2017/04/24 18:06:12 roberto Exp roberto $ ** $Id: lauxlib.h,v 1.133 2017/06/27 18:32:49 roberto Exp roberto $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -204,21 +204,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

38
lbaselib.c

@ -1,5 +1,5 @@
/* /*
** $Id: lbaselib.c,v 1.320 2018/02/25 12:48:16 roberto Exp roberto $ ** $Id: lbaselib.c,v 1.321 2018/02/27 17:48:28 roberto Exp roberto $
** Basic library ** Basic library
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -253,23 +253,6 @@ static int luaB_type (lua_State *L) {
} }
static int pairsmeta (lua_State *L, const char *method, int iszero,
lua_CFunction iter) {
luaL_checkany(L, 1);
if (luaL_getmetafield(L, 1, method) == LUA_TNIL) { /* no metamethod? */
lua_pushcfunction(L, iter); /* will return generator, */
lua_pushvalue(L, 1); /* state, */
if (iszero) lua_pushinteger(L, 0); /* and initial value */
else lua_pushnil(L);
}
else {
lua_pushvalue(L, 1); /* argument 'self' to metamethod */
lua_call(L, 1, 3); /* get 3 values from metamethod */
}
return 3;
}
static int luaB_next (lua_State *L) { static int luaB_next (lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE); luaL_checktype(L, 1, LUA_TTABLE);
lua_settop(L, 2); /* create a 2nd argument if there isn't one */ lua_settop(L, 2); /* create a 2nd argument if there isn't one */
@ -283,7 +266,17 @@ static int luaB_next (lua_State *L) {
static int luaB_pairs (lua_State *L) { static int luaB_pairs (lua_State *L) {
return pairsmeta(L, "__pairs", 0, luaB_next); luaL_checkany(L, 1);
if (luaL_getmetafield(L, 1, "__pairs") == LUA_TNIL) { /* no metamethod? */
lua_pushcfunction(L, luaB_next); /* will return generator, */
lua_pushvalue(L, 1); /* state, */
lua_pushnil(L); /* and initial value */
}
else {
lua_pushvalue(L, 1); /* argument 'self' to metamethod */
lua_call(L, 1, 3); /* get 3 values from metamethod */
}
return 3;
} }
@ -302,15 +295,11 @@ static int ipairsaux (lua_State *L) {
** (The given "table" may not be a table.) ** (The given "table" may not be a table.)
*/ */
static int luaB_ipairs (lua_State *L) { static int luaB_ipairs (lua_State *L) {
#if defined(LUA_COMPAT_IPAIRS)
return pairsmeta(L, "__ipairs", 1, ipairsaux);
#else
luaL_checkany(L, 1); luaL_checkany(L, 1);
lua_pushcfunction(L, ipairsaux); /* iteration function */ lua_pushcfunction(L, ipairsaux); /* iteration function */
lua_pushvalue(L, 1); /* state */ lua_pushvalue(L, 1); /* state */
lua_pushinteger(L, 0); /* initial value */ lua_pushinteger(L, 0); /* initial value */
return 3; return 3;
#endif
} }
@ -506,9 +495,6 @@ static const luaL_Reg base_funcs[] = {
{"ipairs", luaB_ipairs}, {"ipairs", luaB_ipairs},
{"loadfile", luaB_loadfile}, {"loadfile", luaB_loadfile},
{"load", luaB_load}, {"load", luaB_load},
#if defined(LUA_COMPAT_LOADSTRING)
{"loadstring", luaB_load},
#endif
{"next", luaB_next}, {"next", luaB_next},
{"pairs", luaB_pairs}, {"pairs", luaB_pairs},
{"pcall", luaB_pcall}, {"pcall", luaB_pcall},

5
linit.c

@ -1,5 +1,5 @@
/* /*
** $Id: linit.c,v 1.39 2016/12/04 20:17:24 roberto Exp roberto $ ** $Id: linit.c,v 1.40 2017/06/27 18:32:49 roberto Exp roberto $
** Initialization of libraries for lua.c and other clients ** Initialization of libraries for lua.c and other clients
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -50,9 +50,6 @@ static const luaL_Reg loadedlibs[] = {
{LUA_MATHLIBNAME, luaopen_math}, {LUA_MATHLIBNAME, luaopen_math},
{LUA_UTF8LIBNAME, luaopen_utf8}, {LUA_UTF8LIBNAME, luaopen_utf8},
{LUA_DBLIBNAME, luaopen_debug}, {LUA_DBLIBNAME, luaopen_debug},
#if defined(LUA_COMPAT_BITLIB)
{LUA_BITLIBNAME, luaopen_bit32},
#endif
{NULL, NULL} {NULL, NULL}
}; };

95
loadlib.c

@ -1,5 +1,5 @@
/* /*
** $Id: loadlib.c,v 1.130 2017/01/12 17:14:26 roberto Exp roberto $ ** $Id: loadlib.c,v 1.131 2017/12/13 12:51:42 roberto Exp roberto $
** Dynamic library loader for Lua ** Dynamic library loader for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
** **
@ -621,96 +621,10 @@ static int ll_require (lua_State *L) {
/*
** {======================================================
** 'module' function
** =======================================================
*/
#if defined(LUA_COMPAT_MODULE)
/*
** changes the environment variable of calling function
*/
static void set_env (lua_State *L) {
lua_Debug ar;
if (lua_getstack(L, 1, &ar) == 0 ||
lua_getinfo(L, "f", &ar) == 0 || /* get calling function */
lua_iscfunction(L, -1))
luaL_error(L, "'module' not called from a Lua function");
lua_pushvalue(L, -2); /* copy new environment table to top */
lua_setupvalue(L, -2, 1);
lua_pop(L, 1); /* remove function */
}
static void dooptions (lua_State *L, int n) {
int i;
for (i = 2; i <= n; i++) {
if (lua_isfunction(L, i)) { /* avoid 'calling' extra info. */
lua_pushvalue(L, i); /* get option (a function) */
lua_pushvalue(L, -2); /* module */
lua_call(L, 1, 0);
}
}
}
static void modinit (lua_State *L, const char *modname) {
const char *dot;
lua_pushvalue(L, -1);
lua_setfield(L, -2, "_M"); /* module._M = module */
lua_pushstring(L, modname);
lua_setfield(L, -2, "_NAME");
dot = strrchr(modname, '.'); /* look for last dot in module name */
if (dot == NULL) dot = modname;
else dot++;
/* set _PACKAGE as package name (full module name minus last part) */
lua_pushlstring(L, modname, dot - modname);
lua_setfield(L, -2, "_PACKAGE");
}
static int ll_module (lua_State *L) {
const char *modname = luaL_checkstring(L, 1);
int lastarg = lua_gettop(L); /* last parameter */
luaL_pushmodule(L, modname, 1); /* get/create module table */
/* check whether table already has a _NAME field */
if (lua_getfield(L, -1, "_NAME") != LUA_TNIL)
lua_pop(L, 1); /* table is an initialized module */
else { /* no; initialize it */
lua_pop(L, 1);
modinit(L, modname);
}
lua_pushvalue(L, -1);
set_env(L);
dooptions(L, lastarg);
return 1;
}
static int ll_seeall (lua_State *L) {
luaL_checktype(L, 1, LUA_TTABLE);
if (!lua_getmetatable(L, 1)) {
lua_createtable(L, 0, 1); /* create new metatable */
lua_pushvalue(L, -1);
lua_setmetatable(L, 1);
}
lua_pushglobaltable(L);
lua_setfield(L, -2, "__index"); /* mt.__index = _G */
return 0;
}
#endif
/* }====================================================== */
static const luaL_Reg pk_funcs[] = { static const luaL_Reg pk_funcs[] = {
{"loadlib", ll_loadlib}, {"loadlib", ll_loadlib},
{"searchpath", ll_searchpath}, {"searchpath", ll_searchpath},
#if defined(LUA_COMPAT_MODULE)
{"seeall", ll_seeall},
#endif
/* placeholders */ /* placeholders */
{"preload", NULL}, {"preload", NULL},
{"cpath", NULL}, {"cpath", NULL},
@ -722,9 +636,6 @@ static const luaL_Reg pk_funcs[] = {
static const luaL_Reg ll_funcs[] = { static const luaL_Reg ll_funcs[] = {
#if defined(LUA_COMPAT_MODULE)
{"module", ll_module},
#endif
{"require", ll_require}, {"require", ll_require},
{NULL, NULL} {NULL, NULL}
}; };
@ -742,10 +653,6 @@ static void createsearcherstable (lua_State *L) {
lua_pushcclosure(L, searchers[i], 1); lua_pushcclosure(L, searchers[i], 1);
lua_rawseti(L, -2, i+1); lua_rawseti(L, -2, i+1);
} }
#if defined(LUA_COMPAT_LOADERS)
lua_pushvalue(L, -1); /* make a copy of 'searchers' table */
lua_setfield(L, -3, "loaders"); /* put it in field 'loaders' */
#endif
lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */ lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */
} }

4
lobject.c

@ -1,5 +1,5 @@
/* /*
** $Id: lobject.c,v 2.122 2017/12/30 20:46:18 roberto Exp roberto $ ** $Id: lobject.c,v 2.123 2018/01/28 15:13:26 roberto Exp roberto $
** Some generic functions over Lua objects ** Some generic functions over Lua objects
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -382,12 +382,10 @@ void luaO_tostring (lua_State *L, TValue *obj) {
len = lua_integer2str(buff, sizeof(buff), ivalue(obj)); len = lua_integer2str(buff, sizeof(buff), ivalue(obj));
else { else {
len = lua_number2str(buff, sizeof(buff), fltvalue(obj)); len = lua_number2str(buff, sizeof(buff), fltvalue(obj));
#if !defined(LUA_COMPAT_FLOATSTRING)
if (buff[strspn(buff, "-0123456789")] == '\0') { /* looks like an int? */ if (buff[strspn(buff, "-0123456789")] == '\0') { /* looks like an int? */
buff[len++] = lua_getlocaledecpoint(); buff[len++] = lua_getlocaledecpoint();
buff[len++] = '0'; /* adds '.0' to result */ buff[len++] = '0'; /* adds '.0' to result */
} }
#endif
} }
setsvalue(L, obj, luaS_newlstr(L, buff, len)); setsvalue(L, obj, luaS_newlstr(L, buff, len));
} }

28
ltablib.c

@ -1,5 +1,5 @@
/* /*
** $Id: ltablib.c,v 1.93 2016/02/25 19:41:54 roberto Exp roberto $ ** $Id: ltablib.c,v 1.94 2018/02/25 12:48:16 roberto Exp roberto $
** Library for Table Manipulation ** Library for Table Manipulation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -58,24 +58,6 @@ static void checktab (lua_State *L, int arg, int what) {
} }
#if defined(LUA_COMPAT_MAXN)
static int maxn (lua_State *L) {
lua_Number max = 0;
luaL_checktype(L, 1, LUA_TTABLE);
lua_pushnil(L); /* first key */
while (lua_next(L, 1)) {
lua_pop(L, 1); /* remove value */
if (lua_type(L, -1) == LUA_TNUMBER) {
lua_Number v = lua_tonumber(L, -1);
if (v > max) max = v;
}
}
lua_pushnumber(L, max);
return 1;
}
#endif
static int tinsert (lua_State *L) { static int tinsert (lua_State *L) {
lua_Integer e = aux_getn(L, 1, TAB_RW) + 1; /* first empty element */ lua_Integer e = aux_getn(L, 1, TAB_RW) + 1; /* first empty element */
lua_Integer pos; /* where to insert new element */ lua_Integer pos; /* where to insert new element */
@ -425,9 +407,6 @@ static int sort (lua_State *L) {
static const luaL_Reg tab_funcs[] = { static const luaL_Reg tab_funcs[] = {
{"concat", tconcat}, {"concat", tconcat},
#if defined(LUA_COMPAT_MAXN)
{"maxn", maxn},
#endif
{"insert", tinsert}, {"insert", tinsert},
{"pack", pack}, {"pack", pack},
{"unpack", unpack}, {"unpack", unpack},
@ -440,11 +419,6 @@ static const luaL_Reg tab_funcs[] = {
LUAMOD_API int luaopen_table (lua_State *L) { LUAMOD_API int luaopen_table (lua_State *L) {
luaL_newlib(L, tab_funcs); luaL_newlib(L, tab_funcs);
#if defined(LUA_COMPAT_UNPACK)
/* _G.unpack = table.unpack */
lua_getfield(L, -1, "unpack");
lua_setglobal(L, "unpack");
#endif
return 1; return 1;
} }

12
ltests.h

@ -1,5 +1,5 @@
/* /*
** $Id: ltests.h,v 2.54 2017/12/07 18:51:39 roberto Exp roberto $ ** $Id: ltests.h,v 2.55 2017/12/18 13:01:49 roberto Exp roberto $
** Internal Header for Debugging of the Lua Implementation ** Internal Header for Debugging of the Lua Implementation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -13,16 +13,6 @@
/* test Lua with compatibility code */ /* test Lua with compatibility code */
#define LUA_COMPAT_MATHLIB #define LUA_COMPAT_MATHLIB
#define LUA_COMPAT_IPAIRS
#define LUA_COMPAT_BITLIB
#define LUA_COMPAT_APIINTCASTS
#define LUA_COMPAT_FLOATSTRING
#define LUA_COMPAT_UNPACK
#define LUA_COMPAT_LOADERS
#define LUA_COMPAT_LOG10
#define LUA_COMPAT_LOADSTRING
#define LUA_COMPAT_MAXN
#define LUA_COMPAT_MODULE
#define LUA_DEBUG #define LUA_DEBUG

80
luaconf.h

@ -1,5 +1,5 @@
/* /*
** $Id: luaconf.h,v 1.263 2017/12/30 20:46:18 roberto Exp roberto $ ** $Id: luaconf.h,v 1.264 2018/02/20 20:52:50 roberto Exp roberto $
** Configuration file for Lua ** Configuration file for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -295,29 +295,20 @@
*/ */
/* /*
@@ LUA_COMPAT_5_2 controls other macros for compatibility with Lua 5.2. @@ LUA_COMPAT_5_3 controls other macros for compatibility with Lua 5.2.
@@ LUA_COMPAT_5_1 controls other macros for compatibility with Lua 5.1.
** You can define it to get all options, or change specific options ** You can define it to get all options, or change specific options
** to fit your specific needs. ** to fit your specific needs.
*/ */
#if defined(LUA_COMPAT_5_2) /* { */ #if defined(LUA_COMPAT_5_3) /* { */
/* /*
@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated @@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
** functions in the mathematical library. ** functions in the mathematical library.
** (These functions were already officially removed in 5.3, but
** nevertheless they are available by default there.)
*/ */
#define LUA_COMPAT_MATHLIB #define LUA_COMPAT_MATHLIB
/*
@@ LUA_COMPAT_BITLIB controls the presence of library 'bit32'.
*/
#define LUA_COMPAT_BITLIB
/*
@@ LUA_COMPAT_IPAIRS controls the effectiveness of the __ipairs metamethod.
*/
#define LUA_COMPAT_IPAIRS
/* /*
@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for @@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
** manipulating other integer types (lua_pushunsigned, lua_tounsigned, ** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
@ -328,50 +319,6 @@
#endif /* } */ #endif /* } */
#if defined(LUA_COMPAT_5_1) /* { */
/* Incompatibilities from 5.2 -> 5.3 */
#define LUA_COMPAT_MATHLIB
#define LUA_COMPAT_APIINTCASTS
/*
@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
** You can replace it with 'table.unpack'.
*/
#define LUA_COMPAT_UNPACK
/*
@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.
** You can replace it with 'package.searchers'.
*/
#define LUA_COMPAT_LOADERS
/*
@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
** You can call your C function directly (with light C functions).
*/
#define lua_cpcall(L,f,u) \
(lua_pushcfunction(L, (f)), \
lua_pushlightuserdata(L,(u)), \
lua_pcall(L,1,0,0))
/*
@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
** You can rewrite 'log10(x)' as 'log(x, 10)'.
*/
#define LUA_COMPAT_LOG10
/*
@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base
** library. You can rewrite 'loadstring(s)' as 'load(s)'.
*/
#define LUA_COMPAT_LOADSTRING
/*
@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
*/
#define LUA_COMPAT_MAXN
/* /*
@@ The following macros supply trivial compatibility for some @@ The following macros supply trivial compatibility for some
@ -385,23 +332,6 @@
#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
/*
@@ LUA_COMPAT_MODULE controls compatibility with previous
** module functions 'module' (Lua) and 'luaL_register' (C).
*/
#define LUA_COMPAT_MODULE
#endif /* } */
/*
@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a
@@ a float mark ('.0').
** This macro is not on by default even in compatibility mode,
** because this is not really an incompatibility.
*/
/* #define LUA_COMPAT_FLOATSTRING */
/* }================================================================== */ /* }================================================================== */

5
lualib.h

@ -1,5 +1,5 @@
/* /*
** $Id: lualib.h,v 1.44 2014/02/06 17:32:33 roberto Exp roberto $ ** $Id: lualib.h,v 1.45 2017/01/12 17:14:26 roberto Exp roberto $
** Lua standard libraries ** Lua standard libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -35,9 +35,6 @@ LUAMOD_API int (luaopen_string) (lua_State *L);
#define LUA_UTF8LIBNAME "utf8" #define LUA_UTF8LIBNAME "utf8"
LUAMOD_API int (luaopen_utf8) (lua_State *L); LUAMOD_API int (luaopen_utf8) (lua_State *L);
#define LUA_BITLIBNAME "bit32"
LUAMOD_API int (luaopen_bit32) (lua_State *L);
#define LUA_MATHLIBNAME "math" #define LUA_MATHLIBNAME "math"
LUAMOD_API int (luaopen_math) (lua_State *L); LUAMOD_API int (luaopen_math) (lua_State *L);

Loading…
Cancel
Save