diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-11-14 15:10:24 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-11-14 15:10:24 -0200 |
commit | 6cce5c060186c109d5fc87ac13b5d36d9d3997ea (patch) | |
tree | b2215f8fec6effa7adc45e73614a0694b833016a /lbaselib.c | |
parent | eb70f58279e7bd8581ecf58c763d8065a8e2bfb0 (diff) | |
download | lua-6cce5c060186c109d5fc87ac13b5d36d9d3997ea.tar.gz lua-6cce5c060186c109d5fc87ac13b5d36d9d3997ea.tar.bz2 lua-6cce5c060186c109d5fc87ac13b5d36d9d3997ea.zip |
new function 'luaL_loadfilex'
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.267 2011/11/09 19:28:27 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.268 2011/11/09 19:38:00 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -255,7 +255,14 @@ static int load_aux (lua_State *L, int status) { | |||
255 | 255 | ||
256 | static int luaB_loadfile (lua_State *L) { | 256 | static int luaB_loadfile (lua_State *L) { |
257 | const char *fname = luaL_optstring(L, 1, NULL); | 257 | const char *fname = luaL_optstring(L, 1, NULL); |
258 | return load_aux(L, luaL_loadfile(L, fname)); | 258 | const char *mode = luaL_optstring(L, 2, NULL); |
259 | int env = !lua_isnone(L, 3); /* 'env' parameter? */ | ||
260 | int status = luaL_loadfilex(L, fname, mode); | ||
261 | if (status == LUA_OK && env) { /* 'env' parameter? */ | ||
262 | lua_pushvalue(L, 3); | ||
263 | lua_setupvalue(L, -2, 1); /* set it as 1st upvalue of loaded chunk */ | ||
264 | } | ||
265 | return load_aux(L, status); | ||
259 | } | 266 | } |
260 | 267 | ||
261 | 268 | ||
@@ -277,11 +284,11 @@ typedef struct { | |||
277 | ** pushed on the stack) in case of errors. | 284 | ** pushed on the stack) in case of errors. |
278 | */ | 285 | */ |
279 | static const char *checkrights (lua_State *L, const char *mode, const char *s) { | 286 | static const char *checkrights (lua_State *L, const char *mode, const char *s) { |
280 | if (strchr(mode, 'b') == NULL && *s == LUA_SIGNATURE[0]) | 287 | const char *x = (*s == LUA_SIGNATURE[0]) ? "binary" : "text"; |
281 | return lua_pushstring(L, "attempt to load a binary chunk"); | 288 | if (strchr(mode, x[0]) == NULL) |
282 | if (strchr(mode, 't') == NULL && *s != LUA_SIGNATURE[0]) | 289 | return lua_pushfstring(L, |
283 | return lua_pushstring(L, "attempt to load a text chunk"); | 290 | "attempt to load a %s chunk (mode is " LUA_QS ")", x, mode); |
284 | return NULL; /* chunk in allowed format */ | 291 | else return NULL; |
285 | } | 292 | } |
286 | 293 | ||
287 | 294 | ||