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 /loadlib.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 'loadlib.c')
| -rw-r--r-- | loadlib.c | 95 |
1 files changed, 1 insertions, 94 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: loadlib.c,v 1.130 2017/01/12 17:14:26 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.131 2017/12/13 12:51:42 roberto Exp roberto $ |
| 3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | ** | 5 | ** |
| @@ -621,96 +621,10 @@ static int ll_require (lua_State *L) { | |||
| 621 | 621 | ||
| 622 | 622 | ||
| 623 | 623 | ||
| 624 | /* | ||
| 625 | ** {====================================================== | ||
| 626 | ** 'module' function | ||
| 627 | ** ======================================================= | ||
| 628 | */ | ||
| 629 | #if defined(LUA_COMPAT_MODULE) | ||
| 630 | |||
| 631 | /* | ||
| 632 | ** changes the environment variable of calling function | ||
| 633 | */ | ||
| 634 | static void set_env (lua_State *L) { | ||
| 635 | lua_Debug ar; | ||
| 636 | if (lua_getstack(L, 1, &ar) == 0 || | ||
| 637 | lua_getinfo(L, "f", &ar) == 0 || /* get calling function */ | ||
| 638 | lua_iscfunction(L, -1)) | ||
| 639 | luaL_error(L, "'module' not called from a Lua function"); | ||
| 640 | lua_pushvalue(L, -2); /* copy new environment table to top */ | ||
| 641 | lua_setupvalue(L, -2, 1); | ||
| 642 | lua_pop(L, 1); /* remove function */ | ||
| 643 | } | ||
| 644 | |||
| 645 | |||
| 646 | static void dooptions (lua_State *L, int n) { | ||
| 647 | int i; | ||
| 648 | for (i = 2; i <= n; i++) { | ||
| 649 | if (lua_isfunction(L, i)) { /* avoid 'calling' extra info. */ | ||
| 650 | lua_pushvalue(L, i); /* get option (a function) */ | ||
| 651 | lua_pushvalue(L, -2); /* module */ | ||
| 652 | lua_call(L, 1, 0); | ||
| 653 | } | ||
| 654 | } | ||
| 655 | } | ||
| 656 | |||
| 657 | |||
| 658 | static void modinit (lua_State *L, const char *modname) { | ||
| 659 | const char *dot; | ||
| 660 | lua_pushvalue(L, -1); | ||
| 661 | lua_setfield(L, -2, "_M"); /* module._M = module */ | ||
| 662 | lua_pushstring(L, modname); | ||
| 663 | lua_setfield(L, -2, "_NAME"); | ||
| 664 | dot = strrchr(modname, '.'); /* look for last dot in module name */ | ||
| 665 | if (dot == NULL) dot = modname; | ||
| 666 | else dot++; | ||
| 667 | /* set _PACKAGE as package name (full module name minus last part) */ | ||
| 668 | lua_pushlstring(L, modname, dot - modname); | ||
| 669 | lua_setfield(L, -2, "_PACKAGE"); | ||
| 670 | } | ||
| 671 | |||
| 672 | |||
| 673 | static int ll_module (lua_State *L) { | ||
| 674 | const char *modname = luaL_checkstring(L, 1); | ||
| 675 | int lastarg = lua_gettop(L); /* last parameter */ | ||
| 676 | luaL_pushmodule(L, modname, 1); /* get/create module table */ | ||
| 677 | /* check whether table already has a _NAME field */ | ||
| 678 | if (lua_getfield(L, -1, "_NAME") != LUA_TNIL) | ||
| 679 | lua_pop(L, 1); /* table is an initialized module */ | ||
| 680 | else { /* no; initialize it */ | ||
| 681 | lua_pop(L, 1); | ||
| 682 | modinit(L, modname); | ||
| 683 | } | ||
| 684 | lua_pushvalue(L, -1); | ||
| 685 | set_env(L); | ||
| 686 | dooptions(L, lastarg); | ||
| 687 | return 1; | ||
| 688 | } | ||
| 689 | |||
| 690 | |||
| 691 | static int ll_seeall (lua_State *L) { | ||
| 692 | luaL_checktype(L, 1, LUA_TTABLE); | ||
| 693 | if (!lua_getmetatable(L, 1)) { | ||
| 694 | lua_createtable(L, 0, 1); /* create new metatable */ | ||
| 695 | lua_pushvalue(L, -1); | ||
| 696 | lua_setmetatable(L, 1); | ||
| 697 | } | ||
| 698 | lua_pushglobaltable(L); | ||
| 699 | lua_setfield(L, -2, "__index"); /* mt.__index = _G */ | ||
| 700 | return 0; | ||
| 701 | } | ||
| 702 | |||
| 703 | #endif | ||
| 704 | /* }====================================================== */ | ||
| 705 | |||
| 706 | |||
| 707 | 624 | ||
| 708 | static const luaL_Reg pk_funcs[] = { | 625 | static const luaL_Reg pk_funcs[] = { |
| 709 | {"loadlib", ll_loadlib}, | 626 | {"loadlib", ll_loadlib}, |
| 710 | {"searchpath", ll_searchpath}, | 627 | {"searchpath", ll_searchpath}, |
| 711 | #if defined(LUA_COMPAT_MODULE) | ||
| 712 | {"seeall", ll_seeall}, | ||
| 713 | #endif | ||
| 714 | /* placeholders */ | 628 | /* placeholders */ |
| 715 | {"preload", NULL}, | 629 | {"preload", NULL}, |
| 716 | {"cpath", NULL}, | 630 | {"cpath", NULL}, |
| @@ -722,9 +636,6 @@ static const luaL_Reg pk_funcs[] = { | |||
| 722 | 636 | ||
| 723 | 637 | ||
| 724 | static const luaL_Reg ll_funcs[] = { | 638 | static const luaL_Reg ll_funcs[] = { |
| 725 | #if defined(LUA_COMPAT_MODULE) | ||
| 726 | {"module", ll_module}, | ||
| 727 | #endif | ||
| 728 | {"require", ll_require}, | 639 | {"require", ll_require}, |
| 729 | {NULL, NULL} | 640 | {NULL, NULL} |
| 730 | }; | 641 | }; |
| @@ -742,10 +653,6 @@ static void createsearcherstable (lua_State *L) { | |||
| 742 | lua_pushcclosure(L, searchers[i], 1); | 653 | lua_pushcclosure(L, searchers[i], 1); |
| 743 | lua_rawseti(L, -2, i+1); | 654 | lua_rawseti(L, -2, i+1); |
| 744 | } | 655 | } |
| 745 | #if defined(LUA_COMPAT_LOADERS) | ||
| 746 | lua_pushvalue(L, -1); /* make a copy of 'searchers' table */ | ||
| 747 | lua_setfield(L, -3, "loaders"); /* put it in field 'loaders' */ | ||
| 748 | #endif | ||
| 749 | lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */ | 656 | lua_setfield(L, -2, "searchers"); /* put it in field 'searchers' */ |
| 750 | } | 657 | } |
| 751 | 658 | ||
