diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-06-16 11:12:24 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-06-16 11:12:24 -0300 |
commit | 22e1c5ebadc63f4b6aa1b2db82067151041e75c7 (patch) | |
tree | ce66801deb1a7f4969a9c4beae0224945d887604 | |
parent | 470dd56a89751efd6e53c0f28509b45631cd4fd4 (diff) | |
download | lua-22e1c5ebadc63f4b6aa1b2db82067151041e75c7.tar.gz lua-22e1c5ebadc63f4b6aa1b2db82067151041e75c7.tar.bz2 lua-22e1c5ebadc63f4b6aa1b2db82067151041e75c7.zip |
avoid conversion from 'const char*' to 'void *' (warning about 'const')
-rw-r--r-- | lbaselib.c | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.260 2011/02/28 17:32:10 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.261 2011/05/26 16:09:40 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 | */ |
@@ -268,6 +268,13 @@ static int luaB_loadfile (lua_State *L) { | |||
268 | ** ======================================================= | 268 | ** ======================================================= |
269 | */ | 269 | */ |
270 | 270 | ||
271 | |||
272 | typedef struct { | ||
273 | char c; | ||
274 | const char *mode; | ||
275 | } loaddata; | ||
276 | |||
277 | |||
271 | /* | 278 | /* |
272 | ** check whether a chunk (prefix in 's') satisfies given 'mode' | 279 | ** check whether a chunk (prefix in 's') satisfies given 'mode' |
273 | ** ('t' for text, 'b' for binary). Returns error message (also | 280 | ** ('t' for text, 'b' for binary). Returns error message (also |
@@ -298,7 +305,7 @@ static const char *checkrights (lua_State *L, const char *mode, const char *s) { | |||
298 | */ | 305 | */ |
299 | static const char *generic_reader (lua_State *L, void *ud, size_t *size) { | 306 | static const char *generic_reader (lua_State *L, void *ud, size_t *size) { |
300 | const char *s; | 307 | const char *s; |
301 | const char **mode = (const char **)ud; | 308 | loaddata *ld = (loaddata *)ud; |
302 | luaL_checkstack(L, 2, "too many nested functions"); | 309 | luaL_checkstack(L, 2, "too many nested functions"); |
303 | lua_pushvalue(L, 1); /* get function */ | 310 | lua_pushvalue(L, 1); /* get function */ |
304 | lua_call(L, 0, 1); /* call it */ | 311 | lua_call(L, 0, 1); /* call it */ |
@@ -307,9 +314,9 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) { | |||
307 | return NULL; | 314 | return NULL; |
308 | } | 315 | } |
309 | else if ((s = lua_tostring(L, -1)) != NULL) { | 316 | else if ((s = lua_tostring(L, -1)) != NULL) { |
310 | if (*mode != NULL) { /* first time? */ | 317 | if (ld->mode != NULL) { /* first time? */ |
311 | s = checkrights(L, *mode, s); /* check mode */ | 318 | s = checkrights(L, ld->mode, s); /* check mode */ |
312 | *mode = NULL; /* to avoid further checks */ | 319 | ld->mode = NULL; /* to avoid further checks */ |
313 | if (s) luaL_error(L, s); | 320 | if (s) luaL_error(L, s); |
314 | } | 321 | } |
315 | lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */ | 322 | lua_replace(L, RESERVEDSLOT); /* save string in reserved slot */ |
@@ -335,9 +342,11 @@ static int luaB_load (lua_State *L) { | |||
335 | } | 342 | } |
336 | else { /* loading from a reader function */ | 343 | else { /* loading from a reader function */ |
337 | const char *chunkname = luaL_optstring(L, 2, "=(load)"); | 344 | const char *chunkname = luaL_optstring(L, 2, "=(load)"); |
345 | loaddata ld; | ||
346 | ld.mode = mode; | ||
338 | luaL_checktype(L, 1, LUA_TFUNCTION); | 347 | luaL_checktype(L, 1, LUA_TFUNCTION); |
339 | lua_settop(L, RESERVEDSLOT); /* create reserved slot */ | 348 | lua_settop(L, RESERVEDSLOT); /* create reserved slot */ |
340 | status = lua_load(L, generic_reader, &mode, chunkname); | 349 | status = lua_load(L, generic_reader, &ld, chunkname); |
341 | } | 350 | } |
342 | if (status == LUA_OK && top >= 4) { /* is there an 'env' argument */ | 351 | if (status == LUA_OK && top >= 4) { /* is there an 'env' argument */ |
343 | lua_pushvalue(L, 4); /* environment for loaded function */ | 352 | lua_pushvalue(L, 4); /* environment for loaded function */ |