MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / addliteral

Function addliteral

lib/lua/src/lstrlib.c:1175–1207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1173
1174
1175static 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
1210static const char *get2digits (const char *s) {

Callers 1

str_formatFunction · 0.85

Calls 9

lua_typeFunction · 0.85
lua_tolstringFunction · 0.85
addquotedFunction · 0.85
luaL_prepbuffsizeFunction · 0.85
lua_isintegerFunction · 0.85
quotefloatFunction · 0.85
luaL_tolstringFunction · 0.85
luaL_addvalueFunction · 0.85
luaL_argerrorFunction · 0.85

Tested by

no test coverage detected