commit 092dc95b06ee71f99f134727862a3a0d5783d9e5
parent e6e543a534832d7bb5680cee9d3b589a69c5e2cc
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 29 Mar 2005 13:47:26 -0300
using `require' to implement `-l'
Diffstat:
M | lua.c | | | 16 | ++++++---------- |
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/lua.c b/lua.c
@@ -1,5 +1,5 @@
/*
-** $Id: lua.c,v 1.137 2005/03/22 16:55:35 roberto Exp roberto $
+** $Id: lua.c,v 1.138 2005/03/23 17:50:49 roberto Exp roberto $
** Lua stand-alone interpreter
** See Copyright Notice in lua.h
*/
@@ -46,8 +46,9 @@ static void print_usage (void) {
" - execute stdin as a file\n"
" -e stat execute string `stat'\n"
" -i enter interactive mode after executing `script'\n"
- " -l name load and run library `name'\n"
+ " -l name require library `name'\n"
" -v show version information\n"
+ " -w control access to undefined globals\n"
" -- stop handling options\n" ,
progname);
}
@@ -130,14 +131,9 @@ static int dostring (lua_State *L, const char *s, const char *name) {
static int dolibrary (lua_State *L, const char *name) {
- luaL_getfield(L, LUA_GLOBALSINDEX, "package.path");
- if (!lua_isstring(L, -1)) {
- l_message(progname, "`package.path' must be a string");
- return 1;
- }
- name = luaL_searchpath(L, name, lua_tostring(L, -1));
- if (name == NULL) return report(L, 1);
- else return dofile(L, name);
+ lua_getglobal(L, "require");
+ lua_pushstring(L, name);
+ return report(L, lua_pcall(L, 1, 0, 0));
}