lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> I am aware of the fact that on input number arguments are accepted by  
> lua_isstring (and luaL_checkstring, etc.), as is mentioned in the  
> documentation. Sometimes however it is necessary to reject a number and 
> accept a string only. As an example think of 2 optional arguments:
>   calling("optional_string")
>   calling(optional_number)
>   calling("optional_string", optional_number)
> In such a case differentiation between a real string and a number eases 
> processing of such an argument list. Although it is possible  
> differentiate with lua_isnumber, that has the drawback that other  
> erroneous types are not catched here.
>
> The solution is to define a macro:
>   #define isrealstring(S,A) (!lua_isnumber(S,A) && lua_isstring(S,A))
>
> My point then is: Given the series of lua_is's and luaL-check's, may I  
> be so bold as to suggest addition to the upcoming version of Lua of  
> something as lua_isrealstring?

To check whether an argument is a "real string", use its type:

  #define isrealstring(L,a)	(lua_type(L,a) == LUA_TSTRING)

-- Roberto