Improve Lua and JSON serialization

This commit is contained in:
Justine Tunney 2022-07-12 23:31:06 -07:00
parent 3027d67037
commit e3cd476a9b
20 changed files with 1041 additions and 476 deletions

View file

@ -511,9 +511,13 @@ static dontinline int LuaCoderImpl(lua_State *L,
void *p;
size_t n;
p = luaL_checklstring(L, 1, &n);
p = C(p, n, &n);
lua_pushlstring(L, p, n);
free(p);
if ((p = C(p, n, &n))) {
lua_pushlstring(L, p, n);
free(p);
} else {
luaL_error(L, "out of memory");
unreachable;
}
return 1;
}
@ -575,7 +579,17 @@ int LuaEscapeFragment(lua_State *L) {
}
int LuaEscapeLiteral(lua_State *L) {
return LuaCoder(L, EscapeJsStringLiteral);
char *p, *q = 0;
size_t n, y = 0;
p = luaL_checklstring(L, 1, &n);
if ((p = EscapeJsStringLiteral(&q, &y, p, n, &n))) {
lua_pushlstring(L, p, n);
free(q);
return 1;
} else {
luaL_error(L, "out of memory");
unreachable;
}
}
int LuaVisualizeControlCodes(lua_State *L) {