diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-10-21 11:47:42 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-10-21 11:47:42 -0200 |
commit | 053e87314596e48588a929791012def7818ec989 (patch) | |
tree | e5ce2b8bdf03da3dbdac087bf62824b49e7d40f0 /lauxlib.c | |
parent | 9f4211310fcea9ebf08f4884f8665520c1b8d85f (diff) | |
download | lua-053e87314596e48588a929791012def7818ec989.tar.gz lua-053e87314596e48588a929791012def7818ec989.tar.bz2 lua-053e87314596e48588a929791012def7818ec989.zip |
new macro luaL_opt to avoid evaluating defaults when no needed
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.154 2005/10/19 13:05:11 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.155 2005/10/20 11:35:25 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 | */ |
@@ -176,8 +176,7 @@ LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) { | |||
176 | 176 | ||
177 | 177 | ||
178 | LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { | 178 | LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) { |
179 | if (lua_isnoneornil(L, narg)) return def; | 179 | return luaL_opt(L, luaL_checknumber, narg, def); |
180 | else return luaL_checknumber(L, narg); | ||
181 | } | 180 | } |
182 | 181 | ||
183 | 182 | ||
@@ -190,9 +189,8 @@ LUALIB_API lua_Integer luaL_checkinteger (lua_State *L, int narg) { | |||
190 | 189 | ||
191 | 190 | ||
192 | LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, | 191 | LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int narg, |
193 | lua_Integer def) { | 192 | lua_Integer def) { |
194 | if (lua_isnoneornil(L, narg)) return def; | 193 | return luaL_opt(L, luaL_checkinteger, narg, def); |
195 | else return luaL_checkinteger(L, narg); | ||
196 | } | 194 | } |
197 | 195 | ||
198 | 196 | ||