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
a92da3c3
Unverified
Commit
a92da3c3
authored
Aug 22, 2020
by
Terry Ellison
Committed by
GitHub
Aug 22, 2020
Browse files
Lua 5.1 / 5.3 alignment and document (#3193)
parent
1f386e93
Changes
76
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
a92da3c3
.gdb_history
app/lua/.std
app/lua53/.std
sdk/
cache/
.ccache/
...
...
app/coap/coap.h
View file @
a92da3c3
...
...
@@ -7,7 +7,6 @@ extern "C" {
#include <stdint.h>
#include <stddef.h>
#include "lualib.h"
#include "lauxlib.h"
#define MAXOPT 16
...
...
app/coap/endpoints.c
View file @
a92da3c3
...
...
@@ -5,7 +5,6 @@
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "os_type.h"
#include "user_interface.h"
...
...
app/http/httpclient.c
View file @
a92da3c3
...
...
@@ -14,12 +14,12 @@
#include "osapi.h"
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "user_interface.h"
#include "espconn.h"
#include "mem.h"
#include "limits.h"
#include "httpclient.h"
#include "stdlib.h"
#include "pm/swtimer.h"
#define REDIRECTION_FOLLOW_MAX 20
...
...
app/include/user_config.h
View file @
a92da3c3
...
...
@@ -247,7 +247,8 @@
#define LUA_TASK_PRIO USER_TASK_PRIO_0
#define LUA_PROCESS_LINE_SIG 2
#define LUA_OPTIMIZE_DEBUG 2
// LUAI_OPTIMIZE_DEBUG 0 = Keep all debug; 1 = keep line number info; 2 = remove all debug
#define LUAI_OPTIMIZE_DEBUG 1
#define READLINE_INTERVAL 80
#define STRBUF_DEFAULT_INCREMENT 3
#define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback()
...
...
app/lua/lapi.c
View file @
a92da3c3
...
...
@@ -152,6 +152,16 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
*/
/*
** convert an acceptable stack index into an absolute index
*/
LUA_API
int
lua_absindex
(
lua_State
*
L
,
int
idx
)
{
return
(
idx
>
0
||
idx
<=
LUA_REGISTRYINDEX
)
?
idx
:
cast_int
(
L
->
top
-
L
->
base
)
-
1
+
idx
;
}
LUA_API
int
lua_gettop
(
lua_State
*
L
)
{
return
cast_int
(
L
->
top
-
L
->
base
);
}
...
...
@@ -241,7 +251,7 @@ LUA_API void lua_pushvalue (lua_State *L, int idx) {
LUA_API
int
lua_type
(
lua_State
*
L
,
int
idx
)
{
StkId
o
=
index2adr
(
L
,
idx
);
return
(
o
==
luaO_nilobject
)
?
LUA_TNONE
:
basettype
(
o
);
return
(
o
==
luaO_nilobject
)
?
LUA_TNONE
:
ttnov
(
o
);
}
...
...
@@ -253,7 +263,7 @@ LUA_API int lua_fulltype (lua_State *L, int idx) {
LUA_API
const
char
*
lua_typename
(
lua_State
*
L
,
int
t
)
{
UNUSED
(
L
);
return
(
t
==
LUA_TNONE
)
?
"no value"
:
luaT_typenames
[
t
];
return
(
t
==
LUA_TNONE
||
t
>=
LUA_NUMTAGS
)
?
"no value"
:
luaT_typenames
[
t
];
}
...
...
@@ -290,32 +300,25 @@ LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
}
LUA_API
int
lua_equal
(
lua_State
*
L
,
int
index1
,
int
index2
)
{
StkId
o1
,
o2
;
int
i
;
lua_lock
(
L
);
/* may call tag method */
o1
=
index2adr
(
L
,
index1
);
o2
=
index2adr
(
L
,
index2
);
i
=
(
o1
==
luaO_nilobject
||
o2
==
luaO_nilobject
)
?
0
:
equalobj
(
L
,
o1
,
o2
);
lua_unlock
(
L
);
return
i
;
}
LUA_API
int
lua_lessthan
(
lua_State
*
L
,
int
index1
,
int
index2
)
{
LUA_API
int
lua_compare
(
lua_State
*
L
,
int
index1
,
int
index2
,
int
op
)
{
StkId
o1
,
o2
;
int
i
;
int
i
=
0
;
lua_lock
(
L
);
/* may call tag method */
o1
=
index2adr
(
L
,
index1
);
o2
=
index2adr
(
L
,
index2
);
i
=
(
o1
==
luaO_nilobject
||
o2
==
luaO_nilobject
)
?
0
:
luaV_lessthan
(
L
,
o1
,
o2
);
if
(
o1
!=
luaO_nilobject
&&
o2
!=
luaO_nilobject
)
{
switch
(
op
)
{
case
LUA_OPEQ
:
i
=
luaV_equalval
(
L
,
o1
,
o2
);
break
;
case
LUA_OPLT
:
i
=
luaV_lessthan
(
L
,
o1
,
o2
);
break
;
case
LUA_OPLE
:
i
=
luaV_lessequal
(
L
,
o1
,
o2
);
break
;
default:
api_check
(
L
,
0
);
}
}
lua_unlock
(
L
);
return
i
;
}
LUA_API
lua_Number
lua_tonumber
(
lua_State
*
L
,
int
idx
)
{
TValue
n
;
const
TValue
*
o
=
index2adr
(
L
,
idx
);
...
...
@@ -366,7 +369,7 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
LUA_API
size_t
lua_objlen
(
lua_State
*
L
,
int
idx
)
{
StkId
o
=
index2adr
(
L
,
idx
);
switch
(
basettype
(
o
))
{
switch
(
ttnov
(
o
))
{
case
LUA_TSTRING
:
return
tsvalue
(
o
)
->
len
;
case
LUA_TUSERDATA
:
return
uvalue
(
o
)
->
len
;
case
LUA_TTABLE
:
return
luaH_getn
(
hvalue
(
o
));
...
...
@@ -552,16 +555,17 @@ LUA_API int lua_pushthread (lua_State *L) {
*/
LUA_API
void
lua_gettable
(
lua_State
*
L
,
int
idx
)
{
LUA_API
int
lua_gettable
(
lua_State
*
L
,
int
idx
)
{
StkId
t
;
lua_lock
(
L
);
t
=
index2adr
(
L
,
idx
);
api_checkvalidindex
(
L
,
t
);
luaV_gettable
(
L
,
t
,
L
->
top
-
1
,
L
->
top
-
1
);
lua_unlock
(
L
);
return
ttnov
(
L
->
top
-
1
);
}
LUA_API
void
lua_getfield
(
lua_State
*
L
,
int
idx
,
const
char
*
k
)
{
LUA_API
int
lua_getfield
(
lua_State
*
L
,
int
idx
,
const
char
*
k
)
{
StkId
t
;
TValue
key
;
lua_lock
(
L
);
...
...
@@ -573,20 +577,36 @@ LUA_API void lua_getfield (lua_State *L, int idx, const char *k) {
luaV_gettable
(
L
,
t
,
&
key
,
L
->
top
);
api_incr_top
(
L
);
lua_unlock
(
L
);
return
ttnov
(
L
->
top
-
1
);
}
LUA_API
int
lua_geti
(
lua_State
*
L
,
int
idx
,
int
n
)
{
StkId
t
;
TValue
key
;
lua_lock
(
L
);
t
=
index2adr
(
L
,
idx
);
api_checkvalidindex
(
L
,
t
);
fixedstack
(
L
);
setnvalue
(
&
key
,
n
);
unfixedstack
(
L
);
luaV_gettable
(
L
,
t
,
&
key
,
L
->
top
);
api_incr_top
(
L
);
lua_unlock
(
L
);
return
ttnov
(
L
->
top
-
1
);
}
LUA_API
void
lua_rawget
(
lua_State
*
L
,
int
idx
)
{
LUA_API
int
lua_rawget
(
lua_State
*
L
,
int
idx
)
{
StkId
t
;
lua_lock
(
L
);
t
=
index2adr
(
L
,
idx
);
api_check
(
L
,
ttistable
(
t
));
setobj2s
(
L
,
L
->
top
-
1
,
luaH_get
(
hvalue
(
t
),
L
->
top
-
1
));
lua_unlock
(
L
);
return
ttnov
(
L
->
top
-
1
);
}
LUA_API
void
lua_rawgeti
(
lua_State
*
L
,
int
idx
,
int
n
)
{
LUA_API
int
lua_rawgeti
(
lua_State
*
L
,
int
idx
,
int
n
)
{
StkId
o
;
lua_lock
(
L
);
o
=
index2adr
(
L
,
idx
);
...
...
@@ -594,6 +614,21 @@ LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
setobj2s
(
L
,
L
->
top
,
luaH_getnum
(
hvalue
(
o
),
n
));
api_incr_top
(
L
);
lua_unlock
(
L
);
return
ttnov
(
L
->
top
-
1
);
}
LUA_API
int
lua_rawgetp
(
lua_State
*
L
,
int
idx
,
const
void
*
p
)
{
StkId
t
;
TValue
k
;
lua_lock
(
L
);
t
=
index2adr
(
L
,
idx
);
api_check
(
L
,
ttistable
(
t
));
setpvalue
(
&
k
,
cast
(
void
*
,
p
));
setobj2s
(
L
,
L
->
top
,
luaH_get
(
hvalue
(
t
),
&
k
));
api_incr_top
(
L
);
lua_unlock
(
L
);
return
ttnov
(
L
->
top
-
1
);
}
...
...
@@ -612,7 +647,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) {
int
res
;
lua_lock
(
L
);
obj
=
index2adr
(
L
,
objindex
);
switch
(
basettype
(
obj
))
{
switch
(
ttnov
(
obj
))
{
case
LUA_TTABLE
:
mt
=
hvalue
(
obj
)
->
metatable
;
break
;
...
...
@@ -620,7 +655,7 @@ LUA_API int lua_getmetatable (lua_State *L, int objindex) {
mt
=
uvalue
(
obj
)
->
metatable
;
break
;
default:
mt
=
G
(
L
)
->
mt
[
basettype
(
obj
)];
mt
=
G
(
L
)
->
mt
[
ttnov
(
obj
)];
break
;
}
if
(
mt
==
NULL
)
...
...
@@ -720,6 +755,23 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
}
LUA_API
void
lua_rawsetp
(
lua_State
*
L
,
int
idx
,
const
void
*
p
)
{
StkId
o
;
TValue
k
;
lua_lock
(
L
);
api_checknelems
(
L
,
1
);
o
=
index2adr
(
L
,
idx
);
api_check
(
L
,
ttistable
(
o
));
fixedstack
(
L
);
setpvalue
(
&
k
,
cast
(
void
*
,
p
))
setobj2t
(
L
,
luaH_set
(
L
,
hvalue
(
o
),
&
k
),
L
->
top
-
1
);
unfixedstack
(
L
);
luaC_barriert
(
L
,
hvalue
(
o
),
L
->
top
-
1
);
L
->
top
--
;
lua_unlock
(
L
);
}
LUA_API
int
lua_setmetatable
(
lua_State
*
L
,
int
objindex
)
{
TValue
*
obj
;
Table
*
mt
;
...
...
@@ -750,7 +802,7 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
break
;
}
default:
{
G
(
L
)
->
mt
[
basettype
(
obj
)]
=
mt
;
G
(
L
)
->
mt
[
ttnov
(
obj
)]
=
mt
;
break
;
}
}
...
...
@@ -901,7 +953,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
}
LUA_API
int
lua_dump
Ex
(
lua_State
*
L
,
lua_Writer
writer
,
void
*
data
,
int
stripping
)
{
LUA_API
int
lua_dump
(
lua_State
*
L
,
lua_Writer
writer
,
void
*
data
,
int
stripping
)
{
int
status
;
TValue
*
o
;
lua_lock
(
L
);
...
...
@@ -916,6 +968,30 @@ LUA_API int lua_dumpEx (lua_State *L, lua_Writer writer, void *data, int strippi
}
LUA_API
int
lua_stripdebug
(
lua_State
*
L
,
int
stripping
){
TValue
*
o
=
L
->
top
-
1
;
Proto
*
p
=
NULL
;
int
res
=
-
1
;
lua_lock
(
L
);
api_checknelems
(
L
,
1
);
if
(
isLfunction
(
o
))
{
p
=
clvalue
(
o
)
->
l
.
p
;
if
(
p
&&
!
isLFSobject
(
p
)
&&
(
unsigned
)
stripping
<
3
)
{
// found a valid proto to strip
res
=
luaG_stripdebug
(
L
,
p
,
stripping
,
1
);
}
}
else
if
(
ttisnil
(
L
->
top
-
1
))
{
// get or set the default strip level
if
((
unsigned
)
stripping
<
3
)
G
(
L
)
->
stripdefault
=
stripping
;
res
=
G
(
L
)
->
stripdefault
;
}
L
->
top
--
;
lua_unlock
(
L
);
return
res
;
}
LUA_API
int
lua_status
(
lua_State
*
L
)
{
return
L
->
status
;
}
...
...
@@ -1136,15 +1212,15 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
return
name
;
}
LUA_API
void
lua_setegcmode
(
lua_State
*
L
,
int
mode
,
int
limit
)
{
LUA_API
void
lua_setegcmode
(
lua_State
*
L
,
int
mode
,
int
limit
)
{
G
(
L
)
->
egcmode
=
mode
;
G
(
L
)
->
memlimit
=
limit
;
}
LUA_API
void
l
egc_set_mode
(
lua_State
*
L
,
int
mode
,
int
limit
)
{
global_State
*
g
=
G
(
L
);
g
->
egcmode
=
mod
e
;
g
->
memlimit
=
limit
;
LUA_API
void
l
ua_getegcinfo
(
lua_State
*
L
,
int
*
totals
)
{
if
(
totals
)
{
totals
[
0
]
=
G
(
L
)
->
totalbytes
;
totals
[
1
]
=
G
(
L
)
->
estimat
e
;
}
}
app/lua/lauxlib.c
View file @
a92da3c3
...
...
@@ -25,9 +25,9 @@
*/
#define lauxlib_c
#include "lauxlib.h"
#define LUA_LIB
#include "lauxlib.h"
#include "lgc.h"
#include "ldo.h"
#include "lobject.h"
...
...
app/lua/lauxlib.h
View file @
a92da3c3
...
...
@@ -9,6 +9,9 @@
#define lauxlib_h
#include "lua.h"
#ifdef LUA_LIB
#include "lnodemcu.h"
#endif
#include <stdio.h>
...
...
@@ -73,7 +76,7 @@ LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
LUALIB_API
int
(
luaL_ref
)
(
lua_State
*
L
,
int
t
);
LUALIB_API
void
(
luaL_unref
)
(
lua_State
*
L
,
int
t
,
int
ref
);
#define luaL_unref2(l,t,r) luaL_unref(L, (t), (r)); r = LUA_NOREF
#define luaL_unref2(l,t,r)
do {
luaL_unref(L, (t), (r)); r = LUA_NOREF
;} while (0)
LUALIB_API
void
(
luaL_reref
)
(
lua_State
*
L
,
int
t
,
int
*
ref
);
LUALIB_API
int
(
luaL_loadfile
)
(
lua_State
*
L
,
const
char
*
filename
);
...
...
@@ -108,8 +111,8 @@ LUALIB_API void luaL_assertfail(const char *file, int line, const char *message)
#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d)))
#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n)))
#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d)))
#define luaL_checktable(L,n) luaL_checktype(L, (n), LUA_TTABLE)
;
#define luaL_checkfunction(L,n) luaL_checktype(L, (n), LUA_TFUNCTION)
;
#define luaL_checktable(L,n) luaL_checktype(L, (n), LUA_TTABLE)
#define luaL_checkfunction(L,n) luaL_checktype(L, (n), LUA_TFUNCTION)
#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i)))
...
...
@@ -162,8 +165,16 @@ LUALIB_API void (luaL_pushresult) (luaL_Buffer *B);
/* }====================================================== */
LUALIB_API
int
luaL_pcallx
(
lua_State
*
L
,
int
narg
,
int
nres
);
LUALIB_API
int
luaL_posttask
(
lua_State
*
L
,
int
prio
);
LUALIB_API
int
(
luaL_pushlfsmodules
)
(
lua_State
*
L
);
LUALIB_API
int
(
luaL_pushlfsmodule
)
(
lua_State
*
L
);
LUALIB_API
int
(
luaL_pushlfsdts
)
(
lua_State
*
L
);
LUALIB_API
void
(
luaL_lfsreload
)
(
lua_State
*
L
);
LUALIB_API
int
(
luaL_pcallx
)
(
lua_State
*
L
,
int
narg
,
int
nres
);
LUALIB_API
int
(
luaL_posttask
)
(
lua_State
*
L
,
int
prio
);
#define LUA_TASK_LOW 0
#define LUA_TASK_MEDIUM 1
#define LUA_TASK_HIGH 2
/* }====================================================== */
...
...
app/lua/lbaselib.c
View file @
a92da3c3
...
...
@@ -10,7 +10,6 @@
#define LUA_LIB
#include "lua.h"
#include "lnodemcu.h"
#include <stdio.h>
#include <string.h>
...
...
app/lua/lcode.c
View file @
a92da3c3
...
...
@@ -780,8 +780,6 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
}
#ifdef LUA_OPTIMIZE_DEBUG
/*
* Attempted to write to last (null terminator) byte of lineinfo, so need
* to grow the lineinfo vector and extend the fill bytes
...
...
@@ -828,10 +826,8 @@ static void generateInfoDeltaLine(FuncState *fs, int line) {
fs
->
lastlineOffset
=
p
-
fs
->
f
->
packedlineinfo
-
1
;
#undef addDLbyte
}
#endif
void
luaK_fixline
(
FuncState
*
fs
,
int
line
)
{
#ifdef LUA_OPTIMIZE_DEBUG
/* The fixup line can be the same as existing one and in this case there's nothing to do */
if
(
line
!=
fs
->
lastline
)
{
/* first remove the current line reference */
...
...
@@ -862,9 +858,6 @@ void luaK_fixline (FuncState *fs, int line) {
/* Then add the new line reference */
generateInfoDeltaLine
(
fs
,
line
);
}
#else
fs
->
f
->
lineinfo
[
fs
->
pc
-
1
]
=
line
;
#endif
}
...
...
@@ -876,7 +869,6 @@ static int luaK_code (FuncState *fs, Instruction i, int line) {
MAX_INT
,
"code size overflow"
);
f
->
code
[
fs
->
pc
]
=
i
;
/* save corresponding line information */
#ifdef LUA_OPTIMIZE_DEBUG
/* note that frst time fs->lastline==0 through, so the else branch is taken */
if
(
fs
->
pc
==
fs
->
lineinfoLastPC
+
1
)
{
if
(
line
==
fs
->
lastline
&&
f
->
packedlineinfo
[
fs
->
lastlineOffset
]
<
INFO_MAX_LINECNT
)
{
...
...
@@ -890,11 +882,6 @@ static int luaK_code (FuncState *fs, Instruction i, int line) {
luaK_fixline
(
fs
,
line
);
}
fs
->
lineinfoLastPC
=
fs
->
pc
;
#else
luaM_growvector
(
fs
->
L
,
f
->
lineinfo
,
fs
->
pc
,
f
->
sizelineinfo
,
int
,
MAX_INT
,
"code size overflow"
);
f
->
lineinfo
[
fs
->
pc
]
=
line
;
#endif
return
fs
->
pc
++
;
}
...
...
app/lua/ldblib.c
View file @
a92da3c3
...
...
@@ -15,9 +15,6 @@
#include "lauxlib.h"
#include "lualib.h"
#include "lstring.h"
#include "lflash.h"
#include "lnodemcu.h"
#include "user_modules.h"
...
...
@@ -27,34 +24,16 @@ static int db_getregistry (lua_State *L) {
}
static
int
db_getstrings
(
lua_State
*
L
)
{
size_t
i
,
n
=
0
;
stringtable
*
tb
;
GCObject
*
o
;
#ifndef LUA_CROSS_COMPILER
const
char
*
opt
=
lua_tolstring
(
L
,
1
,
&
n
);
if
(
n
==
3
&&
memcmp
(
opt
,
"ROM"
,
4
)
==
0
)
{
if
(
G
(
L
)
->
ROstrt
.
hash
==
NULL
)
return
0
;
tb
=
&
G
(
L
)
->
ROstrt
;
}
else
#endif
tb
=
&
G
(
L
)
->
strt
;
lua_settop
(
L
,
0
);
lua_createtable
(
L
,
tb
->
nuse
,
0
);
/* create table the same size as the strt */
for
(
i
=
0
,
n
=
1
;
i
<
tb
->
size
;
i
++
)
{
for
(
o
=
tb
->
hash
[
i
];
o
;
o
=
o
->
gch
.
next
)
{
TString
*
ts
=
cast
(
TString
*
,
o
);
lua_pushnil
(
L
);
setsvalue2s
(
L
,
L
->
top
-
1
,
ts
);
lua_rawseti
(
L
,
-
2
,
n
++
);
/* enumerate the strt, adding elements */
static
const
char
*
const
opts
[]
=
{
"RAM"
,
"ROM"
,
NULL
};
int
opt
=
luaL_checkoption
(
L
,
1
,
"RAM"
,
opts
);
if
(
lua_pushstringsarray
(
L
,
opt
))
{
if
(
lua_getglobal
(
L
,
"table"
)
==
LUA_TTABLE
)
{
lua_getfield
(
L
,
-
1
,
"sort"
);
/* look up table.sort function */
lua_replace
(
L
,
-
2
);
/* dump the table table */
lua_pushvalue
(
L
,
-
2
);
/* duplicate the strt_copy ref */
lua_call
(
L
,
1
,
0
);
/* table.sort(strt_copy) */
}
}
lua_getfield
(
L
,
LUA_GLOBALSINDEX
,
"table"
);
lua_getfield
(
L
,
-
1
,
"sort"
);
/* look up table.sort function */
lua_replace
(
L
,
-
2
);
/* dump the table table */
lua_pushvalue
(
L
,
-
2
);
/* duplicate the strt_copy ref */
lua_call
(
L
,
1
,
0
);
/* table.sort(strt_copy) */
return
1
;
}
...
...
app/lua/ldebug.c
View file @
a92da3c3
...
...
@@ -182,8 +182,7 @@ static void info_tailcall (lua_Debug *ar) {
# define INFO_DELTA_7BITS 0x7F
# define INFO_MAX_LINECNT 126
Table
*
t
=
luaH_new
(
L
,
0
,
0
);
#ifdef LUA_OPTIMIZE_DEBUG
Table
*
t
=
luaH_new
(
L
,
0
,
0
);
int
line
=
0
;
unsigned
char
*
p
=
f
->
l
.
p
->
packedlineinfo
;
if
(
p
)
{
...
...
@@ -203,18 +202,11 @@ static void info_tailcall (lua_Debug *ar) {
setbvalue
(
luaH_setnum
(
L
,
t
,
line
),
1
);
}
}
#else
int
*
lineinfo
=
f
->
l
.
p
->
lineinfo
;
int
i
;
for
(
i
=
0
;
i
<
f
->
l
.
p
->
sizelineinfo
;
i
++
)
setbvalue
(
luaH_setnum
(
L
,
t
,
lineinfo
[
i
]),
1
);
#endif
sethvalue
(
L
,
L
->
top
,
t
);
sethvalue
(
L
,
L
->
top
,
t
);
}
incr_top
(
L
);
}
#ifdef LUA_OPTIMIZE_DEBUG
/*
* This may seem expensive but this is only accessed frequently in traceexec
* and the while loop will be executed roughly half the number of non-blank
...
...
@@ -249,18 +241,17 @@ int luaG_getline (const Proto *f, int pc) {
static
int
stripdebug
(
lua_State
*
L
,
Proto
*
f
,
int
level
)
{
int
len
=
0
,
sizepackedlineinfo
;
TString
*
dummy
;
switch
(
level
)
{
case
3
:
sizepackedlineinfo
=
strlen
(
cast
(
char
*
,
f
->
packedlineinfo
))
+
1
;
f
->
packedlineinfo
=
luaM_freearray
(
L
,
f
->
packedlineinfo
,
sizepackedlineinfo
,
unsigned
char
);
len
+=
sizepackedlineinfo
;
case
2
:
len
+=
f
->
sizelocvars
*
(
sizeof
(
struct
LocVar
)
+
sizeof
(
dummy
->
tsv
)
+
sizeof
(
struct
LocVar
*
));
if
(
f
->
packedlineinfo
)
{
sizepackedlineinfo
=
strlen
(
cast
(
char
*
,
f
->
packedlineinfo
))
+
1
;
f
->
packedlineinfo
=
luaM_freearray
(
L
,
f
->
packedlineinfo
,
sizepackedlineinfo
,
unsigned
char
);
len
+=
sizepackedlineinfo
;
}
case
1
:
f
->
locvars
=
luaM_freearray
(
L
,
f
->
locvars
,
f
->
sizelocvars
,
struct
LocVar
);
f
->
upvalues
=
luaM_freearray
(
L
,
f
->
upvalues
,
f
->
sizeupvalues
,
TString
*
);
len
+=
f
->
sizelocvars
*
(
sizeof
(
struct
LocVar
)
+
sizeof
(
dummy
->
tsv
)
+
sizeof
(
struct
LocVar
*
))
+
f
->
sizeupvalues
*
(
sizeof
(
dummy
->
tsv
)
+
sizeof
(
TString
*
));
len
+=
f
->
sizelocvars
*
sizeof
(
struct
LocVar
)
+
f
->
sizeupvalues
*
sizeof
(
TString
*
);
f
->
sizelocvars
=
0
;
f
->
sizeupvalues
=
0
;
}
...
...
@@ -276,7 +267,6 @@ LUA_API int luaG_stripdebug (lua_State *L, Proto *f, int level, int recv){
len
+=
stripdebug
(
L
,
f
,
level
);
return
len
;
}
#endif
static
int
auxgetinfo
(
lua_State
*
L
,
const
char
*
what
,
lua_Debug
*
ar
,
...
...
@@ -379,9 +369,6 @@ static int precheck (const Proto *pt) {
check
(
!
(
pt
->
is_vararg
&
VARARG_NEEDSARG
)
||
(
pt
->
is_vararg
&
VARARG_HASARG
));
check
(
pt
->
sizeupvalues
<=
pt
->
nups
);
#ifndef LUA_OPTIMIZE_DEBUG
check
(
pt
->
sizelineinfo
==
pt
->
sizecode
||
pt
->
sizelineinfo
==
0
);
#endif
check
(
pt
->
sizecode
>
0
&&
GET_OPCODE
(
pt
->
code
[
pt
->
sizecode
-
1
])
==
OP_RETURN
);
return
1
;
}
...
...
@@ -668,7 +655,7 @@ static int isinstack (CallInfo *ci, const TValue *o) {
void
luaG_typeerror
(
lua_State
*
L
,
const
TValue
*
o
,
const
char
*
op
)
{
const
char
*
name
=
NULL
;
const
char
*
t
=
luaT_typenames
[
basettype
(
o
)];
const
char
*
t
=
luaT_typenames
[
ttnov
(
o
)];
const
char
*
kind
=
(
isinstack
(
L
->
ci
,
o
))
?
getobjname
(
L
,
L
->
ci
,
cast_int
(
o
-
L
->
base
),
&
name
)
:
NULL
;
...
...
@@ -696,8 +683,8 @@ void luaG_aritherror (lua_State *L, const TValue *p1, const TValue *p2) {
int
luaG_ordererror
(
lua_State
*
L
,
const
TValue
*
p1
,
const
TValue
*
p2
)
{
const
char
*
t1
=
luaT_typenames
[
basettype
(
p1
)];
const
char
*
t2
=
luaT_typenames
[
basettype
(
p2
)];
const
char
*
t1
=
luaT_typenames
[
ttnov
(
p1
)];
const
char
*
t2
=
luaT_typenames
[
ttnov
(
p2
)];
if
(
t1
[
2
]
==
t2
[
2
])
luaG_runerror
(
L
,
"attempt to compare two %s values"
,
t1
);
else
...
...
app/lua/ldebug.h
View file @
a92da3c3
...
...
@@ -13,7 +13,6 @@
#define pcRel(pc, p) (cast(int, (pc) - (p)->code) - 1)
#ifdef LUA_OPTIMIZE_DEBUG
# include "lvm.h"
# define getline(f,pc) (((f)->packedlineinfo) ? luaG_getline((f), pc) : 0)
# define INFO_FILL_BYTE 0x7F
...
...
@@ -23,9 +22,6 @@
# define INFO_DELTA_7BITS 0x7F
# define INFO_MAX_LINECNT 126
# define lineInfoTop(fs) ((fs)->f->packedlineinfo + (fs)->lastlineOffset)
#else
# define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
#endif
#define resethookcount(L) (L->hookcount = L->basehookcount)
...
...
@@ -41,9 +37,7 @@ LUAI_FUNC void luaG_runerror (lua_State *L, const char *fmt, ...);
LUAI_FUNC
void
luaG_errormsg
(
lua_State
*
L
);
LUAI_FUNC
int
luaG_checkcode
(
const
Proto
*
pt
);
LUAI_FUNC
int
luaG_checkopenop
(
Instruction
i
);
#ifdef LUA_OPTIMIZE_DEBUG
LUAI_FUNC
int
luaG_getline
(
const
Proto
*
f
,
int
pc
);
LUAI_FUNC
int
luaG_stripdebug
(
lua_State
*
L
,
Proto
*
f
,
int
level
,
int
recv
);
#endif
#endif
app/lua/ldump.c
View file @
a92da3c3
...
...
@@ -228,7 +228,6 @@ static void DumpDebug(const Proto* f, DumpState* D)
{
int
i
,
n
;
#ifdef LUA_OPTIMIZE_DEBUG
n
=
(
D
->
strip
||
f
->
packedlineinfo
==
NULL
)
?
0
:
strlen
(
cast
(
char
*
,
f
->
packedlineinfo
))
+
1
;
DumpInt
(
n
,
D
);
Align4
(
D
);
...
...
@@ -236,15 +235,6 @@ static void DumpDebug(const Proto* f, DumpState* D)
{
DumpBlock
(
f
->
packedlineinfo
,
n
,
D
);
}
#else
n
=
(
D
->
strip
)
?
0
:
f
->
sizelineinfo
;
DumpInt
(
n
,
D
);
Align4
(
D
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
DumpInt
(
f
->
lineinfo
[
i
],
D
);
}
#endif
n
=
(
D
->
strip
)
?
0
:
f
->
sizelocvars
;
DumpInt
(
n
,
D
);
...
...
app/lua/lflash.c
View file @
a92da3c3
...
...
@@ -194,21 +194,20 @@ static int loadLFS (lua_State *L);
static
int
loadLFSgc
(
lua_State
*
L
);
static
void
procFirstPass
(
void
);
/* lua_lfsreload()
and lua_lfsindex() are
exported via l
u
a.h */
/* lua
L
_lfsreload()
is
exported via la
uxlib
.h */
/*
* Library function called by node.flashreload(filename).
*/
LUALIB_API
int
lua_lfsreload
(
lua_State
*
L
)
{
LUALIB_API
void
lua
L
_lfsreload
(
lua_State
*
L
)
{
const
char
*
fn
=
lua_tostring
(
L
,
1
),
*
msg
=
""
;
int
status
;
if
(
G
(
L
)
->
LFSsize
==
0
)
{
lua_pushstring
(
L
,
"No LFS partition allocated"
);
return
1
;
return
;
}
/*
* Do a protected call of loadLFS.
*
...
...
@@ -237,7 +236,7 @@ LUALIB_API int lua_lfsreload (lua_State *L) {
lua_cpcall
(
L
,
&
loadLFSgc
,
NULL
);
lua_settop
(
L
,
0
);
lua_pushstring
(
L
,
msg
);
return
1
;
return
;
}
if
(
status
==
0
)
{
...
...
@@ -257,60 +256,21 @@ LUALIB_API int lua_lfsreload (lua_State *L) {
NODE_ERR
(
msg
);
while
(
1
)
{}
// Force WDT as the ROM software_reset() doesn't seem to work
return
0
;
}
/*
* If the arg is a valid LFS module name then return the LClosure
* pointing to it. Otherwise return:
* - The Unix time that the LFS was built
* - The base address and length of the LFS
* - An array of the module names in the LFS
*/
LUAI_FUNC
int
lua_lfsindex
(
lua_State
*
L
)
{
int
n
=
lua_gettop
(
L
);
LUA_API
void
lua_getlfsconfig
(
lua_State
*
L
,
int
*
config
)
{
if
(
!
config
)
return
;
config
[
0
]
=
(
int
)
flashAddr
;
/* LFS region mapped address */
config
[
1
]
=
flashAddrPhys
;
/* LFS region base flash address */
config
[
2
]
=
G
(
L
)
->
LFSsize
;
/* LFS region actual size */
config
[
3
]
=
(
G
(
L
)
->
ROstrt
.
hash
)
?
cast
(
FlashHeader
*
,
flashAddr
)
->
flash_size
:
0
;
/* LFS region used */
config
[
4
]
=
0
;
/* Not used in Lua 5.1 */
}
/* Return nil + the LFS base address if the LFS size > 0 and it isn't loaded */
if
(
!
(
G
(
L
)
->
ROpvmain
))
{
lua_settop
(
L
,
0
);
lua_pushnil
(
L
);
if
(
G
(
L
)
->
LFSsize
)
{
lua_pushinteger
(
L
,
(
lua_Integer
)
flashAddr
);
lua_pushinteger
(
L
,
flashAddrPhys
);
lua_pushinteger
(
L
,
G
(
L
)
->
LFSsize
);
return
4
;
}
else
{
return
1
;
}
}
/* Push the LClosure of the LFS index function */
Closure
*
cl
=
luaF_newLclosure
(
L
,
0
,
hvalue
(
gt
(
L
)));
cl
->
l
.
p
=
G
(
L
)
->
ROpvmain
;
lua_settop
(
L
,
n
+
1
);
setclvalue
(
L
,
L
->
top
-
1
,
cl
);
/* Move it infront of the arguments and call the index function */
lua_insert
(
L
,
1
);
lua_call
(
L
,
n
,
LUA_MULTRET
);
/* Return it if the response if a single value (the function) */
if
(
lua_gettop
(
L
)
==
1
)
return
1
;
lua_assert
(
lua_gettop
(
L
)
==
2
);
/* Otherwise add the base address of the LFS, and its size bewteen the */
/* Unix time and the module list, then return all 4 params. */
lua_pushinteger
(
L
,
(
lua_Integer
)
flashAddr
);
lua_insert
(
L
,
2
);
lua_pushinteger
(
L
,
flashAddrPhys
);
lua_insert
(
L
,
3
);
lua_pushinteger
(
L
,
cast
(
FlashHeader
*
,
flashAddr
)
->
flash_size
);
lua_insert
(
L
,
4
);
return
5
;
}
/* =====================================================================================
* The following routines use my uzlib which was based on pfalcon's inflate and
* deflate routines. The standard NodeMCU make also makes two host tools uz_zip
...
...
@@ -483,7 +443,7 @@ void procSecondPass (void) {
}
/*
* loadLFS)() is protected called from lua
N_
reload
_reboot
so that it can recover
* loadLFS)() is protected called from lua
L_lfs
reload
()
so that it can recover
* from out of memory and other thrown errors. loadLFSgc() GCs any resources.
*/
static
int
loadLFS
(
lua_State
*
L
)
{
...
...
app/lua/lflash.h
View file @
a92da3c3
...
...
@@ -43,8 +43,5 @@ typedef struct {
}
FlashHeader
;
LUAI_FUNC
void
luaN_init
(
lua_State
*
L
);
LUAI_FUNC
int
luaN_flashSetup
(
lua_State
*
L
);
LUAI_FUNC
int
luaN_reload_reboot
(
lua_State
*
L
);
LUAI_FUNC
int
luaN_index
(
lua_State
*
L
);
#endif
app/lua/lfunc.c
View file @
a92da3c3
...
...
@@ -125,12 +125,7 @@ Proto *luaF_newproto (lua_State *L) {
f
->
numparams
=
0
;
f
->
is_vararg
=
0
;
f
->
maxstacksize
=
0
;
#ifdef LUA_OPTIMIZE_DEBUG
f
->
packedlineinfo
=
NULL
;
#else
f
->
sizelineinfo
=
0
;
f
->
lineinfo
=
NULL
;
#endif
f
->
sizelocvars
=
0
;
f
->
locvars
=
NULL
;
f
->
linedefined
=
0
;
...
...
@@ -146,13 +141,9 @@ void luaF_freeproto (lua_State *L, Proto *f) {
luaM_freearray
(
L
,
f
->
locvars
,
f
->
sizelocvars
,
struct
LocVar
);
luaM_freearray
(
L
,
f
->
upvalues
,
f
->
sizeupvalues
,
TString
*
);
luaM_freearray
(
L
,
f
->
code
,
f
->
sizecode
,
Instruction
);
#ifdef LUA_OPTIMIZE_DEBUG
if
(
f
->
packedlineinfo
)
{
luaM_freearray
(
L
,
f
->
packedlineinfo
,
strlen
(
cast
(
char
*
,
f
->
packedlineinfo
))
+
1
,
unsigned
char
);
}
#else
luaM_freearray
(
L
,
f
->
lineinfo
,
f
->
sizelineinfo
,
int
);
#endif
luaM_free
(
L
,
f
);
}
...
...
app/lua/lgc.c
View file @
a92da3c3
...
...
@@ -327,11 +327,7 @@ static l_mem propagatemark (global_State *g) {
sizeof
(
LocVar
)
*
p
->
sizelocvars
+
sizeof
(
TString
*
)
*
p
->
sizeupvalues
+
sizeof
(
Instruction
)
*
p
->
sizecode
+
#ifdef LUA_OPTIMIZE_DEBUG
(
p
->
packedlineinfo
?
strlen
(
cast
(
char
*
,
p
->
packedlineinfo
))
+
1
:
0
);
#else
sizeof
(
int
)
*
p
->
sizelineinfo
;
#endif
}
default:
lua_assert
(
0
);
return
0
;
}
...
...
@@ -515,7 +511,7 @@ void luaC_freeall (lua_State *L) {
static
void
markmt
(
global_State
*
g
)
{
int
i
;
for
(
i
=
0
;
i
<
NUM
_
TAGS
;
i
++
)
for
(
i
=
0
;
i
<
LUA_
NUMTAGS
;
i
++
)
if
(
g
->
mt
[
i
]
&&
isrwtable
(
g
->
mt
[
i
]))
markobject
(
g
,
g
->
mt
[
i
]);
}
...
...
app/lua/linit.c
View file @
a92da3c3
...
...
@@ -61,7 +61,7 @@ extern LROT_TABLE(math);
#if defined(LUA_CROSS_COMPILER)
extern
LROT_TABLE
(
base_func
);
LROT_BEGIN
(
rotables_meta
,
NULL
,
LROT_MASK_INDEX
)
LROT_TABENTRY
(
_index
,
base_func
)
LROT_TABENTRY
(
_
_index
,
base_func
)
LROT_END
(
rotables_meta
,
NULL
,
LROT_MASK_INDEX
)
extern
LROT_TABLE
(
oslib
);
...
...
app/lua/lmathlib.c
View file @
a92da3c3
...
...
@@ -14,7 +14,6 @@
#include "lauxlib.h"
#include "lualib.h"
#include "lnodemcu.h"
#undef PI
#define PI (3.14159265358979323846)
...
...
Prev
1
2
3
4
Next
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