json.encode and json.decode finished. Also lots of refactoring.

This commit is contained in:
2022-06-06 23:03:26 -04:00
parent f03a48b0a6
commit 779d9e20b8
11 changed files with 1292 additions and 109 deletions

View File

@@ -5,6 +5,7 @@
#include "table.hpp"
#include <iostream>
#include <cmath>
void atomic_print(LuaStack &LS, LuaSlot val, bool quote, std::ostream *os) {
@@ -23,11 +24,15 @@ void atomic_print(LuaStack &LS, LuaSlot val, bool quote, std::ostream *os) {
return;
case LUA_TNUMBER: {
double value = LS.cknumber(val);
int64_t ivalue = int64_t(value);
if (double(ivalue) == value) {
(*os) << ivalue;
if (std::isnan(value)) {
(*os) << "nan";
} else {
(*os) << value;
int64_t ivalue = int64_t(value);
if (double(ivalue) == value) {
(*os) << ivalue;
} else {
(*os) << value;
}
}
return;
}
@@ -38,6 +43,11 @@ void atomic_print(LuaStack &LS, LuaSlot val, bool quote, std::ostream *os) {
(*os) << "<function>";
return;
}
case LUA_TLIGHTUSERDATA: {
LuaToken token = LS.cktoken(val);
(*os) << "[" << token.str() << "]";
return;
}
default:
(*os) << "<" << lua_typename(LS.state(), tt) << ">";
return;