| 1152 | |
| 1153 | |
| 1154 | static void addliteral (lua_State *L, luaL_Buffer *b, int arg) { |
| 1155 | switch (lua_type(L, arg)) { |
| 1156 | case LUA_TSTRING: { |
| 1157 | size_t len; |
| 1158 | const char *s = lua_tolstring(L, arg, &len); |
| 1159 | addquoted(b, s, len); |
| 1160 | break; |
| 1161 | } |
| 1162 | case LUA_TNUMBER: { |
| 1163 | char *buff = luaL_prepbuffsize(b, MAX_ITEM); |
| 1164 | int nb; |
| 1165 | if (!lua_isinteger(L, arg)) /* float? */ |
| 1166 | nb = quotefloat(L, buff, lua_tonumber(L, arg)); |
| 1167 | else { /* integers */ |
| 1168 | lua_Integer n = lua_tointeger(L, arg); |
| 1169 | const char *format = (n == LUA_MININTEGER) /* corner case? */ |
| 1170 | ? "0x%" LUA_INTEGER_FRMLEN "x" /* use hex */ |
| 1171 | : LUA_INTEGER_FMT; /* else use default format */ |
| 1172 | nb = l_sprintf(buff, MAX_ITEM, format, (LUAI_UACINT)n); |
| 1173 | } |
| 1174 | luaL_addsize(b, nb); |
| 1175 | break; |
| 1176 | } |
| 1177 | case LUA_TNIL: case LUA_TBOOLEAN: { |
| 1178 | luaL_tolstring(L, arg, NULL); |
| 1179 | luaL_addvalue(b); |
| 1180 | break; |
| 1181 | } |
| 1182 | default: { |
| 1183 | luaL_argerror(L, arg, "value has no literal form"); |
| 1184 | } |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | |
| 1189 | static const char *scanformat (lua_State *L, const char *strfrmt, char *form) { |
no test coverage detected