diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-27 15:47:32 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2018-02-27 15:47:32 -0300 |
commit | 34b00c16e28c2bbc3e633b4007de956130905ed6 (patch) | |
tree | fca960c3f8f1945a052a776722ccef4944b748fa /lauxlib.c | |
parent | 12110dec0eda3813b7609051aedb0cde932fbf93 (diff) | |
download | lua-34b00c16e28c2bbc3e633b4007de956130905ed6.tar.gz lua-34b00c16e28c2bbc3e633b4007de956130905ed6.tar.bz2 lua-34b00c16e28c2bbc3e633b4007de956130905ed6.zip |
removed compatibility code with older versions
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 83 |
1 files changed, 1 insertions, 82 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.292 2018/01/29 19:13:27 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.293 2018/02/21 13:48:44 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -846,87 +846,6 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { | |||
846 | 846 | ||
847 | 847 | ||
848 | /* | 848 | /* |
849 | ** {====================================================== | ||
850 | ** Compatibility with 5.1 module functions | ||
851 | ** ======================================================= | ||
852 | */ | ||
853 | #if defined(LUA_COMPAT_MODULE) | ||
854 | |||
855 | static const char *luaL_findtable (lua_State *L, int idx, | ||
856 | const char *fname, int szhint) { | ||
857 | const char *e; | ||
858 | if (idx) lua_pushvalue(L, idx); | ||
859 | do { | ||
860 | e = strchr(fname, '.'); | ||
861 | if (e == NULL) e = fname + strlen(fname); | ||
862 | lua_pushlstring(L, fname, e - fname); | ||
863 | if (lua_rawget(L, -2) == LUA_TNIL) { /* no such field? */ | ||
864 | lua_pop(L, 1); /* remove this nil */ | ||
865 | lua_createtable(L, 0, (*e == '.' ? 1 : szhint)); /* new table for field */ | ||
866 | lua_pushlstring(L, fname, e - fname); | ||
867 | lua_pushvalue(L, -2); | ||
868 | lua_settable(L, -4); /* set new table into field */ | ||
869 | } | ||
870 | else if (!lua_istable(L, -1)) { /* field has a non-table value? */ | ||
871 | lua_pop(L, 2); /* remove table and value */ | ||
872 | return fname; /* return problematic part of the name */ | ||
873 | } | ||
874 | lua_remove(L, -2); /* remove previous table */ | ||
875 | fname = e + 1; | ||
876 | } while (*e == '.'); | ||
877 | return NULL; | ||
878 | } | ||
879 | |||
880 | |||
881 | /* | ||
882 | ** Count number of elements in a luaL_Reg list. | ||
883 | */ | ||
884 | static int libsize (const luaL_Reg *l) { | ||
885 | int size = 0; | ||
886 | for (; l && l->name; l++) size++; | ||
887 | return size; | ||
888 | } | ||
889 | |||
890 | |||
891 | /* | ||
892 | ** Find or create a module table with a given name. The function | ||
893 | ** first looks at the LOADED table and, if that fails, try a | ||
894 | ** global variable with that name. In any case, leaves on the stack | ||
895 | ** the module table. | ||
896 | */ | ||
897 | LUALIB_API void luaL_pushmodule (lua_State *L, const char *modname, | ||
898 | int sizehint) { | ||
899 | luaL_findtable(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE, 1); | ||
900 | if (lua_getfield(L, -1, modname) != LUA_TTABLE) { /* no LOADED[modname]? */ | ||
901 | lua_pop(L, 1); /* remove previous result */ | ||
902 | /* try global variable (and create one if it does not exist) */ | ||
903 | lua_pushglobaltable(L); | ||
904 | if (luaL_findtable(L, 0, modname, sizehint) != NULL) | ||
905 | luaL_error(L, "name conflict for module '%s'", modname); | ||
906 | lua_pushvalue(L, -1); | ||
907 | lua_setfield(L, -3, modname); /* LOADED[modname] = new table */ | ||
908 | } | ||
909 | lua_remove(L, -2); /* remove LOADED table */ | ||
910 | } | ||
911 | |||
912 | |||
913 | LUALIB_API void luaL_openlib (lua_State *L, const char *libname, | ||
914 | const luaL_Reg *l, int nup) { | ||
915 | luaL_checkversion(L); | ||
916 | if (libname) { | ||
917 | luaL_pushmodule(L, libname, libsize(l)); /* get/create library table */ | ||
918 | lua_insert(L, -(nup + 1)); /* move library table to below upvalues */ | ||
919 | } | ||
920 | if (l) | ||
921 | luaL_setfuncs(L, l, nup); | ||
922 | else | ||
923 | lua_pop(L, nup); /* remove upvalues */ | ||
924 | } | ||
925 | |||
926 | #endif | ||
927 | /* }====================================================== */ | ||
928 | |||
929 | /* | ||
930 | ** set functions from list 'l' into table at top - 'nup'; each | 849 | ** set functions from list 'l' into table at top - 'nup'; each |
931 | ** function gets the 'nup' elements at the top as upvalues. | 850 | ** function gets the 'nup' elements at the top as upvalues. |
932 | ** Returns with only the table at the stack. | 851 | ** Returns with only the table at the stack. |