Polish redbean serialization

This commit is contained in:
Justine Tunney 2022-04-29 06:06:23 -07:00
parent 7aafa64ab3
commit 2d1731b995
24 changed files with 828 additions and 158 deletions

View file

@ -20,6 +20,7 @@
#include "libc/bits/popcnt.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/rusage.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/kprintf.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
@ -60,6 +61,33 @@ static int Rdpid(void) {
return rdpid();
}
int LuaHex(lua_State *L) {
char b[19];
uint64_t x;
x = luaL_checkinteger(L, 1);
FormatHex64(b, x, true);
lua_pushstring(L, b);
return 1;
}
int LuaOct(lua_State *L) {
char b[24];
uint64_t x;
x = luaL_checkinteger(L, 1);
FormatOctal64(b, x, true);
lua_pushstring(L, b);
return 1;
}
int LuaBin(lua_State *L) {
char b[67];
uint64_t x;
x = luaL_checkinteger(L, 1);
FormatBinary64(b, x, 2);
lua_pushstring(L, b);
return 1;
}
int LuaGetTime(lua_State *L) {
lua_pushnumber(L, nowl());
return 1;
@ -258,7 +286,7 @@ int LuaPopcnt(lua_State *L) {
int LuaBsr(lua_State *L) {
long x;
if ((x = luaL_checkinteger(L, 1))) {
lua_pushinteger(L, bsr(x));
lua_pushinteger(L, bsrl(x));
return 1;
} else {
luaL_argerror(L, 1, "zero");
@ -269,7 +297,7 @@ int LuaBsr(lua_State *L) {
int LuaBsf(lua_State *L) {
long x;
if ((x = luaL_checkinteger(L, 1))) {
lua_pushinteger(L, bsf(x));
lua_pushinteger(L, bsfl(x));
return 1;
} else {
luaL_argerror(L, 1, "zero");