| 941 | |
| 942 | |
| 943 | static void addliteral (lua_State *L, luaL_Buffer *b, int arg) { |
| 944 | switch (lua_type(L, arg)) { |
| 945 | case LUA_TSTRING: { |
| 946 | size_t len; |
| 947 | const char *s = lua_tolstring(L, arg, &len); |
| 948 | addquoted(b, s, len); |
| 949 | break; |
| 950 | } |
| 951 | case LUA_TNUMBER: { |
| 952 | char *buff = luaL_prepbuffsize(b, MAX_ITEM); |
| 953 | int nb; |
| 954 | if (!lua_isinteger(L, arg)) { /* float? */ |
| 955 | lua_Number n = lua_tonumber(L, arg); /* write as hexa ('%a') */ |
| 956 | nb = lua_number2strx(L, buff, MAX_ITEM, "%" LUA_NUMBER_FRMLEN "a", n); |
| 957 | checkdp(buff, nb); /* ensure it uses a dot */ |
| 958 | } |
| 959 | else { /* integers */ |
| 960 | lua_Integer n = lua_tointeger(L, arg); |
| 961 | const char *format = (n == LUA_MININTEGER) /* corner case? */ |
| 962 | ? "0x%" LUA_INTEGER_FRMLEN "x" /* use hexa */ |
| 963 | : LUA_INTEGER_FMT; /* else use default format */ |
| 964 | nb = l_sprintf(buff, MAX_ITEM, format, (LUAI_UACINT)n); |
| 965 | } |
| 966 | luaL_addsize(b, nb); |
| 967 | break; |
| 968 | } |
| 969 | case LUA_TNIL: case LUA_TBOOLEAN: { |
| 970 | luaL_tolstring(L, arg, NULL); |
| 971 | luaL_addvalue(b); |
| 972 | break; |
| 973 | } |
| 974 | default: { |
| 975 | luaL_argerror(L, arg, "value has no literal form"); |
| 976 | } |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | |
| 981 | static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { |
no test coverage detected