| 1173 | |
| 1174 | |
| 1175 | static void addliteral (lua_State *L, luaL_Buffer *b, int arg) { |
| 1176 | switch (lua_type(L, arg)) { |
| 1177 | case LUA_TSTRING: { |
| 1178 | size_t len; |
| 1179 | const char *s = lua_tolstring(L, arg, &len); |
| 1180 | addquoted(b, s, len); |
| 1181 | break; |
| 1182 | } |
| 1183 | case LUA_TNUMBER: { |
| 1184 | char *buff = luaL_prepbuffsize(b, MAX_ITEM); |
| 1185 | int nb; |
| 1186 | if (!lua_isinteger(L, arg)) /* float? */ |
| 1187 | nb = quotefloat(L, buff, lua_tonumber(L, arg)); |
| 1188 | else { /* integers */ |
| 1189 | lua_Integer n = lua_tointeger(L, arg); |
| 1190 | const char *format = (n == LUA_MININTEGER) /* corner case? */ |
| 1191 | ? "0x%" LUA_INTEGER_FRMLEN "x" /* use hex */ |
| 1192 | : LUA_INTEGER_FMT; /* else use default format */ |
| 1193 | nb = l_sprintf(buff, MAX_ITEM, format, (LUAI_UACINT)n); |
| 1194 | } |
| 1195 | luaL_addsize(b, nb); |
| 1196 | break; |
| 1197 | } |
| 1198 | case LUA_TNIL: case LUA_TBOOLEAN: { |
| 1199 | luaL_tolstring(L, arg, NULL); |
| 1200 | luaL_addvalue(b); |
| 1201 | break; |
| 1202 | } |
| 1203 | default: { |
| 1204 | luaL_argerror(L, arg, "value has no literal form"); |
| 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | |
| 1210 | static const char *get2digits (const char *s) { |
no test coverage detected