Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
5b6b2f98
Commit
5b6b2f98
authored
Sep 20, 2020
by
philip
Committed by
Nathaniel Wesley Filardo
Sep 27, 2020
Browse files
Make round tripping work for lua53 and floats
parent
e9c4bb74
Changes
2
Show whitespace changes
Inline
Side-by-side
app/modules/node.c
View file @
5b6b2f98
...
...
@@ -643,6 +643,28 @@ static int node_writercr (lua_State *L) {
lua_pushinteger
(
L
,
n
);
return
1
;
}
static
int
node_int2float
(
lua_State
*
L
)
{
union
{
lua_Integer
i
;
lua_Float
f
;
}
u
;
u
.
i
=
luaL_checkinteger
(
L
,
1
);
lua_pushnumber
(
L
,
u
.
f
);
return
1
;
}
static
int
node_float2int
(
lua_State
*
L
)
{
union
{
lua_Integer
i
;
lua_Float
f
;
}
u
;
u
.
f
=
luaL_checknumber
(
L
,
1
);
lua_pushinteger
(
L
,
u
.
i
);
return
1
;
}
#endif
// Lua: n = node.LFS.reload(lfsimage)
...
...
@@ -915,6 +937,8 @@ LROT_BEGIN(node, NULL, 0)
#endif
#ifdef DEVELOPMENT_TOOLS
LROT_FUNCENTRY
(
osprint
,
node_osprint
)
LROT_FUNCENTRY
(
int2float
,
node_int2float
)
LROT_FUNCENTRY
(
float2int
,
node_float2int
)
#endif
LROT_FUNCENTRY
(
getpartitiontable
,
node_getpartitiontable
)
LROT_FUNCENTRY
(
setpartitiontable
,
node_setpartitiontable
)
...
...
app/modules/sjson.c
View file @
5b6b2f98
...
...
@@ -18,6 +18,8 @@
#define DBG_PRINTF(...)
#define SJSON_FLOAT_FMT ((sizeof(lua_Float) == 8) ? "%.19g" : "%.9g")
typedef
struct
{
jsonsl_t
jsn
;
int
result_ref
;
...
...
@@ -720,10 +722,13 @@ static void encode_lua_object(lua_State *L, ENC_DATA *data, int argno, const cha
case
LUA_TNUMBER
:
{
lua_pushvalue
(
L
,
argno
);
size_t
len
;
const
char
*
str
=
lua_tolstring
(
L
,
-
1
,
&
len
);
char
value
[
len
+
1
];
strcpy
(
value
,
str
);
char
value
[
50
];
if
(
lua_isinteger
(
L
,
-
1
))
{
l_sprintf
(
value
,
sizeof
(
value
),
LUA_INTEGER_FMT
,
lua_tointeger
(
L
,
-
1
));
}
else
{
l_sprintf
(
value
,
sizeof
(
value
),
SJSON_FLOAT_FMT
,
lua_tonumber
(
L
,
-
1
));
}
lua_pop
(
L
,
1
);
if
(
strcmp
(
value
,
"-Infinity"
)
==
0
||
strcmp
(
value
,
"NaN"
)
==
0
||
strcmp
(
value
,
"Infinity"
)
==
0
)
{
luaL_addstring
(
&
b
,
"null"
);
// According to ECMA-262 section 24.5.2 Note 4
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment