aboutsummaryrefslogtreecommitdiff
path: root/lbaselib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbaselib.c')
-rw-r--r--lbaselib.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/lbaselib.c b/lbaselib.c
index 1d60c9de..5a23c937 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -337,9 +337,20 @@ static int load_aux (lua_State *L, int status, int envidx) {
337} 337}
338 338
339 339
340static const char *getmode (lua_State *L, int idx) {
341 const char *mode = luaL_optstring(L, idx, "bt");
342 int i = 0;
343 if (mode[i] == 'b') i++;
344 if (mode[i] == 't') i++;
345 if (mode[i] != '\0')
346 luaL_argerror(L, idx, "invalid mode");
347 return mode;
348}
349
350
340static int luaB_loadfile (lua_State *L) { 351static int luaB_loadfile (lua_State *L) {
341 const char *fname = luaL_optstring(L, 1, NULL); 352 const char *fname = luaL_optstring(L, 1, NULL);
342 const char *mode = luaL_optstring(L, 2, NULL); 353 const char *mode = getmode(L, 2);
343 int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */ 354 int env = (!lua_isnone(L, 3) ? 3 : 0); /* 'env' index or 0 if no 'env' */
344 int status = luaL_loadfilex(L, fname, mode); 355 int status = luaL_loadfilex(L, fname, mode);
345 return load_aux(L, status, env); 356 return load_aux(L, status, env);
@@ -388,7 +399,7 @@ static int luaB_load (lua_State *L) {
388 int status; 399 int status;
389 size_t l; 400 size_t l;
390 const char *s = lua_tolstring(L, 1, &l); 401 const char *s = lua_tolstring(L, 1, &l);
391 const char *mode = luaL_optstring(L, 3, "bt"); 402 const char *mode = getmode(L, 3);
392 int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */ 403 int env = (!lua_isnone(L, 4) ? 4 : 0); /* 'env' index or 0 if no 'env' */
393 if (s != NULL) { /* loading a string? */ 404 if (s != NULL) { /* loading a string? */
394 const char *chunkname = luaL_optstring(L, 2, s); 405 const char *chunkname = luaL_optstring(L, 2, s);