diff options
Diffstat (limited to 'lauxlib.c')
| -rw-r--r-- | lauxlib.c | 92 |
1 files changed, 46 insertions, 46 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.254 2013/06/25 14:05:26 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.255 2013/06/27 18:32:33 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -150,33 +150,33 @@ LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, | |||
| 150 | ** ======================================================= | 150 | ** ======================================================= |
| 151 | */ | 151 | */ |
| 152 | 152 | ||
| 153 | LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) { | 153 | LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) { |
| 154 | lua_Debug ar; | 154 | lua_Debug ar; |
| 155 | if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ | 155 | if (!lua_getstack(L, 0, &ar)) /* no stack frame? */ |
| 156 | return luaL_error(L, "bad argument #%d (%s)", narg, extramsg); | 156 | return luaL_error(L, "bad argument #%d (%s)", arg, extramsg); |
| 157 | lua_getinfo(L, "n", &ar); | 157 | lua_getinfo(L, "n", &ar); |
| 158 | if (strcmp(ar.namewhat, "method") == 0) { | 158 | if (strcmp(ar.namewhat, "method") == 0) { |
| 159 | narg--; /* do not count `self' */ | 159 | arg--; /* do not count `self' */ |
| 160 | if (narg == 0) /* error is in the self argument itself? */ | 160 | if (arg == 0) /* error is in the self argument itself? */ |
| 161 | return luaL_error(L, "calling " LUA_QS " on bad self (%s)", | 161 | return luaL_error(L, "calling " LUA_QS " on bad self (%s)", |
| 162 | ar.name, extramsg); | 162 | ar.name, extramsg); |
| 163 | } | 163 | } |
| 164 | if (ar.name == NULL) | 164 | if (ar.name == NULL) |
| 165 | ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?"; | 165 | ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?"; |
| 166 | return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", | 166 | return luaL_error(L, "bad argument #%d to " LUA_QS " (%s)", |
| 167 | narg, ar.name, extramsg); | 167 | arg, ar.name, extramsg); |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | 170 | ||
| 171 | static int typeerror (lua_State *L, int narg, const char *tname) { | 171 | static int typeerror (lua_State *L, int arg, const char *tname) { |
| 172 | const char *msg = lua_pushfstring(L, "%s expected, got %s", | 172 | const char *msg = lua_pushfstring(L, "%s expected, got %s", |
| 173 | tname, luaL_typename(L, narg)); | 173 | tname, luaL_typename(L, arg)); |
| 174 | return luaL_argerror(L, narg, msg); | 174 | return luaL_argerror(L, arg, msg); |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | 177 | ||
| 178 | static void tag_error (lua_State *L, int narg, int tag) { | 178 | static void tag_error (lua_State *L, int arg, int tag) { |
| 179 | typeerror(L, narg, lua_typename(L, tag)); | 179 | typeerror(L, arg, lua_typename(L, tag)); |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | 182 | ||
| @@ -317,15 +317,15 @@ LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { | |||
| 317 | ** ======================================================= | 317 | ** ======================================================= |
| 318 | */ | 318 | */ |
| 319 | 319 | ||
| 320 | LUALIB_API int luaL_checkoption (lua_State *L, int narg, const char *def, | 320 | LUALIB_API int luaL_checkoption (lua_State *L, int arg, const char *def, |
| 321 | const char *const lst[]) { | 321 | const char *const lst[]) { |
| 322 | const char *name = (def) ? luaL_optstring(L, narg, def) : | 322 | const char *name = (def) ? luaL_optstring(L, arg, def) : |
| 323 | luaL_checkstring(L, narg); | 323 | luaL_checkstring(L, arg); |
| 324 | int i; | 324 | int i; |
| 325 | for (i=0; lst[i]; i++) | 325 | for (i=0; lst[i]; i++) |
| 326 | if (strcmp(lst[i], name) == 0) | 326 | if (strcmp(lst[i], name) == 0) |
| 327 | return i; | 327 | return i; |
| 328 | return luaL_argerror(L, narg, | 328 | return luaL_argerror(L, arg, |
| 329 | lua_pushfstring(L, "invalid option " LUA_QS, name)); | 329 | lua_pushfstring(L, "invalid option " LUA_QS, name)); |
| 330 | } | 330 | } |
| 331 | 331 | ||
| @@ -342,86 +342,86 @@ LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg) { | |||
| 342 | } | 342 | } |
| 343 | 343 | ||
| 344 | 344 | ||
| 345 | LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) { | 345 | LUALIB_API void luaL_checktype (lua_State *L, int arg, int t) { |
| 346 | if (lua_type(L, narg) != t) | 346 | if (lua_type(L, arg) != t) |
| 347 | tag_error(L, narg, t); | 347 | tag_error(L, arg, t); |
| 348 | } | 348 | } |
| 349 | 349 | ||
| 350 | 350 | ||
| 351 | LUALIB_API void luaL_checkany (lua_State *L, int narg) { | 351 | LUALIB_API void luaL_checkany (lua_State *L, int arg) { |
| 352 | if (lua_type(L, narg) == LUA_TNONE) | 352 | if (lua_type(L, arg) == LUA_TNONE) |
| 353 | luaL_argerror(L, narg, "value expected"); | 353 | luaL_argerror(L, arg, "value expected"); |
| 354 | } | 354 | } |
| 355 | 355 | ||
| 356 | 356 | ||
| 357 | LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) { | 357 | LUALIB_API const char *luaL_checklstring (lua_State *L, int arg, size_t *len) { |
| 358 | const char *s = lua_tolstring(L, narg, len); | 358 | const char *s = lua_tolstring(L, arg, len); |
| 359 | if (!s) tag_error(L, narg, LUA_TSTRING); | 359 | if (!s) tag_error(L, arg, LUA_TSTRING); |
| 360 | return s; | 360 | return s; |
| 361 | } | 361 | } |
| 362 | 362 | ||
| 363 | 363 | ||
| 364 | LUALIB_API const char *luaL_optlstring (lua_State *L, int narg, | 364 | LUALIB_API const char *luaL_optlstring (lua_State *L, int arg, |
| 365 | const char *def, size_t *len) { | 365 | const char *def, size_t *len) { |
| 366 | if (lua_isnoneornil(L, narg)) { | 366 | if (lua_isnoneornil(L, arg)) { |
| 367 | if (len) | 367 | if (len) |
| 368 | *len = (def ? strlen(def) : 0); | 368 | *len = (def ? strlen(def) : 0); |
| 369 | return def; | 369 | return def; |
| 370 | } | 370 | } |
| 371 | else return luaL_checklstring(L, narg, len); | 371 | else return luaL_checklstring(L, arg, len); |
| 372 | } | 372 | } |
| 373 | 373 | ||
| 374 | 374 | ||
| 375 | LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { | 375 | LUALIB_API lua_Number luaL_checknumber (lua_State *L, int arg) { |
| 376 | int isnum; | 376 | int isnum; |
| 377 | lua_Number d = lua_tonumberx(L, narg, &isnum); | 377 | lua_Number d = lua_tonumberx(L, arg, &isnum); |
| 378 | if (!isnum) | 378 | if (!isnum) |
| 379 | tag_error(L, narg, LUA_TNUMBER); | 379 | tag_error(L, arg, LUA_TNUMBER); |
| 380 | return d; | 380 | return d; |
| 381 | } | 381 | } |
| 382 | 382 | ||
| 383 | 383 | ||
| 384 | LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { | 384 | LUALIB_API lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number def) { |
| 385 | return luaL_opt(L, luaL_checknumber, narg, def); | 385 | return luaL_opt(L, luaL_checknumber, arg, def); |
| 386 | } | 386 | } |
| 387 | 387 | ||
| 388 | 388 | ||
| 389 | static void interror (lua_State *L, int narg) { | 389 | static void interror (lua_State *L, int arg) { |
| 390 | if (lua_type(L, narg) == LUA_TNUMBER) | 390 | if (lua_type(L, arg) == LUA_TNUMBER) |
| 391 | luaL_argerror(L, narg, "float value out of range"); | 391 | luaL_argerror(L, arg, "float value out of range"); |
| 392 | else | 392 | else |
| 393 | tag_error(L, narg, LUA_TNUMBER); | 393 | tag_error(L, arg, LUA_TNUMBER); |
| 394 | } | 394 | } |
| 395 | 395 | ||
| 396 | 396 | ||
| 397 | LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { | 397 | LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int arg) { |
| 398 | int isnum; | 398 | int isnum; |
| 399 | lua_Integer d = lua_tointegerx(L, narg, &isnum); | 399 | lua_Integer d = lua_tointegerx(L, arg, &isnum); |
| 400 | if (!isnum) { | 400 | if (!isnum) { |
| 401 | interror(L, narg); | 401 | interror(L, arg); |
| 402 | } | 402 | } |
| 403 | return d; | 403 | return d; |
| 404 | } | 404 | } |
| 405 | 405 | ||
| 406 | 406 | ||
| 407 | LUALIB_API lua_Unsigned luaL_checkunsigned (lua_State *L, int narg) { | 407 | LUALIB_API lua_Unsigned luaL_checkunsigned (lua_State *L, int arg) { |
| 408 | int isnum; | 408 | int isnum; |
| 409 | lua_Unsigned d = lua_tounsignedx(L, narg, &isnum); | 409 | lua_Unsigned d = lua_tounsignedx(L, arg, &isnum); |
| 410 | if (!isnum) | 410 | if (!isnum) |
| 411 | interror(L, narg); | 411 | interror(L, arg); |
| 412 | return d; | 412 | return d; |
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | 415 | ||
| 416 | LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, | 416 | LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg, |
| 417 | lua_Integer def) { | 417 | lua_Integer def) { |
| 418 | return luaL_opt(L, luaL_checkinteger, narg, def); | 418 | return luaL_opt(L, luaL_checkinteger, arg, def); |
| 419 | } | 419 | } |
| 420 | 420 | ||
| 421 | 421 | ||
| 422 | LUALIB_API lua_Unsigned luaL_optunsigned (lua_State *L, int narg, | 422 | LUALIB_API lua_Unsigned luaL_optunsigned (lua_State *L, int arg, |
| 423 | lua_Unsigned def) { | 423 | lua_Unsigned def) { |
| 424 | return luaL_opt(L, luaL_checkunsigned, narg, def); | 424 | return luaL_opt(L, luaL_checkunsigned, arg, def); |
| 425 | } | 425 | } |
| 426 | 426 | ||
| 427 | /* }====================================================== */ | 427 | /* }====================================================== */ |
