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
310faf7f
Unverified
Commit
310faf7f
authored
Sep 07, 2019
by
Terry Ellison
Committed by
GitHub
Sep 07, 2019
Browse files
Merge pull request #2886 from nodemcu/dev
Next master drop
parents
68c425c0
a08e74d9
Changes
368
Hide whitespace changes
Inline
Side-by-side
app/lua/lstring.h
View file @
310faf7f
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
#define sizeudata(u) (sizeof(union Udata)+(u)->len)
#define sizeudata(u) (sizeof(union Udata)+(u)->len)
#define luaS_new(L, s) (luaS_newlstr(L, s,
c_
strlen(s)))
#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
(sizeof(s)/sizeof(char))-1))
(sizeof(s)/sizeof(char))-1))
...
...
app/lua/lstrlib.c
View file @
310faf7f
...
@@ -10,17 +10,17 @@
...
@@ -10,17 +10,17 @@
#define LUAC_CROSS_FILE
#define LUAC_CROSS_FILE
#include "lua.h"
#include "lua.h"
#include
C_HEADER_STDIO
#include
<stdio.h>
#include
C_HEADER_STRING
#include
<string.h>
#include "lauxlib.h"
#include "lauxlib.h"
#include "lualib.h"
#include "lualib.h"
#include "lrotable.h"
/* macro to `unsign' a character */
/* macro to `unsign' a character */
#define uchar(c) ((unsigned char)(c))
#define uchar(c) ((unsigned char)(c))
static
int
str_len
(
lua_State
*
L
)
{
static
int
str_len
(
lua_State
*
L
)
{
size_t
l
;
size_t
l
;
luaL_checklstring
(
L
,
1
,
&
l
);
luaL_checklstring
(
L
,
1
,
&
l
);
...
@@ -352,7 +352,7 @@ static const char *match_capture (MatchState *ms, const char *s, int l) {
...
@@ -352,7 +352,7 @@ static const char *match_capture (MatchState *ms, const char *s, int l) {
l
=
check_capture
(
ms
,
l
);
l
=
check_capture
(
ms
,
l
);
len
=
ms
->
capture
[
l
].
len
;
len
=
ms
->
capture
[
l
].
len
;
if
((
size_t
)(
ms
->
src_end
-
s
)
>=
len
&&
if
((
size_t
)(
ms
->
src_end
-
s
)
>=
len
&&
c_
memcmp
(
ms
->
capture
[
l
].
init
,
s
,
len
)
==
0
)
memcmp
(
ms
->
capture
[
l
].
init
,
s
,
len
)
==
0
)
return
s
+
len
;
return
s
+
len
;
else
return
NULL
;
else
return
NULL
;
}
}
...
@@ -447,7 +447,7 @@ static const char *lmemfind (const char *s1, size_t l1,
...
@@ -447,7 +447,7 @@ static const char *lmemfind (const char *s1, size_t l1,
l1
=
l1
-
l2
;
/* `s2' cannot be found after that */
l1
=
l1
-
l2
;
/* `s2' cannot be found after that */
while
(
l1
>
0
&&
(
init
=
(
const
char
*
)
memchr
(
s1
,
*
s2
,
l1
))
!=
NULL
)
{
while
(
l1
>
0
&&
(
init
=
(
const
char
*
)
memchr
(
s1
,
*
s2
,
l1
))
!=
NULL
)
{
init
++
;
/* 1st char is already checked */
init
++
;
/* 1st char is already checked */
if
(
c_
memcmp
(
init
,
s2
+
1
,
l2
)
==
0
)
if
(
memcmp
(
init
,
s2
+
1
,
l2
)
==
0
)
return
init
-
1
;
return
init
-
1
;
else
{
/* correct `l1' and `s1' to try again */
else
{
/* correct `l1' and `s1' to try again */
l1
-=
init
-
s1
;
l1
-=
init
-
s1
;
...
@@ -496,7 +496,7 @@ static int str_find_aux (lua_State *L, int find) {
...
@@ -496,7 +496,7 @@ static int str_find_aux (lua_State *L, int find) {
if
(
init
<
0
)
init
=
0
;
if
(
init
<
0
)
init
=
0
;
else
if
((
size_t
)(
init
)
>
l1
)
init
=
(
ptrdiff_t
)
l1
;
else
if
((
size_t
)(
init
)
>
l1
)
init
=
(
ptrdiff_t
)
l1
;
if
(
find
&&
(
lua_toboolean
(
L
,
4
)
||
/* explicit request? */
if
(
find
&&
(
lua_toboolean
(
L
,
4
)
||
/* explicit request? */
c_
strpbrk
(
p
,
SPECIALS
)
==
NULL
))
{
/* or no special characters? */
strpbrk
(
p
,
SPECIALS
)
==
NULL
))
{
/* or no special characters? */
/* do a plain search */
/* do a plain search */
const
char
*
s2
=
lmemfind
(
s
+
init
,
l1
-
init
,
p
,
l2
);
const
char
*
s2
=
lmemfind
(
s
+
init
,
l1
-
init
,
p
,
l2
);
if
(
s2
)
{
if
(
s2
)
{
...
@@ -576,7 +576,7 @@ static int gmatch (lua_State *L) {
...
@@ -576,7 +576,7 @@ static int gmatch (lua_State *L) {
return
1
;
return
1
;
}
}
#if
LUA_OPTIMIZE_MEMORY == 0 || !defined(
LUA_COMPAT_GFIND
)
#if
ndef
LUA_COMPAT_GFIND
static
int
gfind_nodef
(
lua_State
*
L
)
{
static
int
gfind_nodef
(
lua_State
*
L
)
{
return
luaL_error
(
L
,
LUA_QL
(
"string.gfind"
)
" was renamed to "
return
luaL_error
(
L
,
LUA_QL
(
"string.gfind"
)
" was renamed to "
LUA_QL
(
"string.gmatch"
));
LUA_QL
(
"string.gmatch"
));
...
@@ -723,7 +723,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
...
@@ -723,7 +723,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
static
const
char
*
scanformat
(
lua_State
*
L
,
const
char
*
strfrmt
,
char
*
form
)
{
static
const
char
*
scanformat
(
lua_State
*
L
,
const
char
*
strfrmt
,
char
*
form
)
{
const
char
*
p
=
strfrmt
;
const
char
*
p
=
strfrmt
;
while
(
*
p
!=
'\0'
&&
c_
strchr
(
FLAGS
,
*
p
)
!=
NULL
)
p
++
;
/* skip flags */
while
(
*
p
!=
'\0'
&&
strchr
(
FLAGS
,
*
p
)
!=
NULL
)
p
++
;
/* skip flags */
if
((
size_t
)(
p
-
strfrmt
)
>=
sizeof
(
FLAGS
))
if
((
size_t
)(
p
-
strfrmt
)
>=
sizeof
(
FLAGS
))
luaL_error
(
L
,
"invalid format (repeated flags)"
);
luaL_error
(
L
,
"invalid format (repeated flags)"
);
if
(
isdigit
(
uchar
(
*
p
)))
p
++
;
/* skip width */
if
(
isdigit
(
uchar
(
*
p
)))
p
++
;
/* skip width */
...
@@ -736,7 +736,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
...
@@ -736,7 +736,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
if
(
isdigit
(
uchar
(
*
p
)))
if
(
isdigit
(
uchar
(
*
p
)))
luaL_error
(
L
,
"invalid format (width or precision too long)"
);
luaL_error
(
L
,
"invalid format (width or precision too long)"
);
*
(
form
++
)
=
'%'
;
*
(
form
++
)
=
'%'
;
c_
strncpy
(
form
,
strfrmt
,
p
-
strfrmt
+
1
);
strncpy
(
form
,
strfrmt
,
p
-
strfrmt
+
1
);
form
+=
p
-
strfrmt
+
1
;
form
+=
p
-
strfrmt
+
1
;
*
form
=
'\0'
;
*
form
=
'\0'
;
return
p
;
return
p
;
...
@@ -744,9 +744,9 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
...
@@ -744,9 +744,9 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
static
void
addintlen
(
char
*
form
)
{
static
void
addintlen
(
char
*
form
)
{
size_t
l
=
c_
strlen
(
form
);
size_t
l
=
strlen
(
form
);
char
spec
=
form
[
l
-
1
];
char
spec
=
form
[
l
-
1
];
c_
strcpy
(
form
+
l
-
1
,
LUA_INTFRMLEN
);
strcpy
(
form
+
l
-
1
,
LUA_INTFRMLEN
);
form
[
l
+
sizeof
(
LUA_INTFRMLEN
)
-
2
]
=
spec
;
form
[
l
+
sizeof
(
LUA_INTFRMLEN
)
-
2
]
=
spec
;
form
[
l
+
sizeof
(
LUA_INTFRMLEN
)
-
1
]
=
'\0'
;
form
[
l
+
sizeof
(
LUA_INTFRMLEN
)
-
1
]
=
'\0'
;
}
}
...
@@ -773,23 +773,23 @@ static int str_format (lua_State *L) {
...
@@ -773,23 +773,23 @@ static int str_format (lua_State *L) {
strfrmt
=
scanformat
(
L
,
strfrmt
,
form
);
strfrmt
=
scanformat
(
L
,
strfrmt
,
form
);
switch
(
*
strfrmt
++
)
{
switch
(
*
strfrmt
++
)
{
case
'c'
:
{
case
'c'
:
{
c_
sprintf
(
buff
,
form
,
(
int
)
luaL_checknumber
(
L
,
arg
));
sprintf
(
buff
,
form
,
(
int
)
luaL_checknumber
(
L
,
arg
));
break
;
break
;
}
}
case
'd'
:
case
'i'
:
{
case
'd'
:
case
'i'
:
{
addintlen
(
form
);
addintlen
(
form
);
c_
sprintf
(
buff
,
form
,
(
LUA_INTFRM_T
)
luaL_checknumber
(
L
,
arg
));
sprintf
(
buff
,
form
,
(
LUA_INTFRM_T
)
luaL_checknumber
(
L
,
arg
));
break
;
break
;
}
}
case
'o'
:
case
'u'
:
case
'x'
:
case
'X'
:
{
case
'o'
:
case
'u'
:
case
'x'
:
case
'X'
:
{
addintlen
(
form
);
addintlen
(
form
);
c_
sprintf
(
buff
,
form
,
(
unsigned
LUA_INTFRM_T
)
luaL_checknumber
(
L
,
arg
));
sprintf
(
buff
,
form
,
(
unsigned
LUA_INTFRM_T
)
luaL_checknumber
(
L
,
arg
));
break
;
break
;
}
}
#if !defined LUA_NUMBER_INTEGRAL
#if !defined LUA_NUMBER_INTEGRAL
case
'e'
:
case
'E'
:
case
'f'
:
case
'e'
:
case
'E'
:
case
'f'
:
case
'g'
:
case
'G'
:
{
case
'g'
:
case
'G'
:
{
c_
sprintf
(
buff
,
form
,
(
double
)
luaL_checknumber
(
L
,
arg
));
sprintf
(
buff
,
form
,
(
double
)
luaL_checknumber
(
L
,
arg
));
break
;
break
;
}
}
#endif
#endif
...
@@ -800,7 +800,7 @@ static int str_format (lua_State *L) {
...
@@ -800,7 +800,7 @@ static int str_format (lua_State *L) {
case
's'
:
{
case
's'
:
{
size_t
l
;
size_t
l
;
const
char
*
s
=
luaL_checklstring
(
L
,
arg
,
&
l
);
const
char
*
s
=
luaL_checklstring
(
L
,
arg
,
&
l
);
if
(
!
c_
strchr
(
form
,
'.'
)
&&
l
>=
100
)
{
if
(
!
strchr
(
form
,
'.'
)
&&
l
>=
100
)
{
/* no precision and string is too long to be formatted;
/* no precision and string is too long to be formatted;
keep original string */
keep original string */
lua_pushvalue
(
L
,
arg
);
lua_pushvalue
(
L
,
arg
);
...
@@ -808,7 +808,7 @@ static int str_format (lua_State *L) {
...
@@ -808,7 +808,7 @@ static int str_format (lua_State *L) {
continue
;
/* skip the `addsize' at the end */
continue
;
/* skip the `addsize' at the end */
}
}
else
{
else
{
c_
sprintf
(
buff
,
form
,
s
);
sprintf
(
buff
,
form
,
s
);
break
;
break
;
}
}
}
}
...
@@ -817,74 +817,44 @@ static int str_format (lua_State *L) {
...
@@ -817,74 +817,44 @@ static int str_format (lua_State *L) {
LUA_QL
(
"format"
),
*
(
strfrmt
-
1
));
LUA_QL
(
"format"
),
*
(
strfrmt
-
1
));
}
}
}
}
luaL_addlstring
(
&
b
,
buff
,
c_
strlen
(
buff
));
luaL_addlstring
(
&
b
,
buff
,
strlen
(
buff
));
}
}
}
}
luaL_pushresult
(
&
b
);
luaL_pushresult
(
&
b
);
return
1
;
return
1
;
}
}
#undef MIN_OPT_LEVEL
LROT_PUBLIC_BEGIN
(
strlib
)
#define MIN_OPT_LEVEL 1
LROT_FUNCENTRY
(
byte
,
str_byte
)
#include "lrodefs.h"
LROT_FUNCENTRY
(
char
,
str_char
)
const
LUA_REG_TYPE
strlib
[]
=
{
LROT_FUNCENTRY
(
dump
,
str_dump
)
{
LSTRKEY
(
"byte"
),
LFUNCVAL
(
str_byte
)},
LROT_FUNCENTRY
(
find
,
str_find
)
{
LSTRKEY
(
"char"
),
LFUNCVAL
(
str_char
)},
LROT_FUNCENTRY
(
format
,
str_format
)
{
LSTRKEY
(
"dump"
),
LFUNCVAL
(
str_dump
)},
#ifdef LUA_COMPAT_GFIND
{
LSTRKEY
(
"find"
),
LFUNCVAL
(
str_find
)},
LROT_FUNCENTRY
(
gfind
,
gmatch
)
{
LSTRKEY
(
"format"
),
LFUNCVAL
(
str_format
)},
#if LUA_OPTIMIZE_MEMORY > 0 && defined(LUA_COMPAT_GFIND)
{
LSTRKEY
(
"gfind"
),
LFUNCVAL
(
gmatch
)},
#else
#else
{
LSTRKEY
(
"gfind"
),
LFUNCVAL
(
gfind_nodef
)},
LROT_FUNCENTRY
(
gfind
,
gfind_nodef
)
#endif
{
LSTRKEY
(
"gmatch"
),
LFUNCVAL
(
gmatch
)},
{
LSTRKEY
(
"gsub"
),
LFUNCVAL
(
str_gsub
)},
{
LSTRKEY
(
"len"
),
LFUNCVAL
(
str_len
)},
{
LSTRKEY
(
"lower"
),
LFUNCVAL
(
str_lower
)},
{
LSTRKEY
(
"match"
),
LFUNCVAL
(
str_match
)},
{
LSTRKEY
(
"rep"
),
LFUNCVAL
(
str_rep
)},
{
LSTRKEY
(
"reverse"
),
LFUNCVAL
(
str_reverse
)},
{
LSTRKEY
(
"sub"
),
LFUNCVAL
(
str_sub
)},
{
LSTRKEY
(
"upper"
),
LFUNCVAL
(
str_upper
)},
#if LUA_OPTIMIZE_MEMORY > 0
{
LSTRKEY
(
"__index"
),
LROVAL
(
strlib
)},
#endif
{
LNILKEY
,
LNILVAL
}
};
#if LUA_OPTIMIZE_MEMORY != 2
static
void
createmetatable
(
lua_State
*
L
)
{
lua_createtable
(
L
,
0
,
1
);
/* create metatable for strings */
lua_pushliteral
(
L
,
""
);
/* dummy string */
lua_pushvalue
(
L
,
-
2
);
lua_setmetatable
(
L
,
-
2
);
/* set string metatable */
lua_pop
(
L
,
1
);
/* pop dummy string */
lua_pushvalue
(
L
,
-
2
);
/* string library... */
lua_setfield
(
L
,
-
2
,
"__index"
);
/* ...is the __index metamethod */
lua_pop
(
L
,
1
);
/* pop metatable */
}
#endif
#endif
LROT_FUNCENTRY
(
gmatch
,
gmatch
)
LROT_FUNCENTRY
(
gsub
,
str_gsub
)
LROT_FUNCENTRY
(
len
,
str_len
)
LROT_FUNCENTRY
(
lower
,
str_lower
)
LROT_FUNCENTRY
(
match
,
str_match
)
LROT_FUNCENTRY
(
rep
,
str_rep
)
LROT_FUNCENTRY
(
reverse
,
str_reverse
)
LROT_FUNCENTRY
(
sub
,
str_sub
)
LROT_FUNCENTRY
(
upper
,
str_upper
)
LROT_TABENTRY
(
__index
,
strlib
)
LROT_END
(
strlib
,
NULL
,
0
)
// OR DO WE NEED LRTO_MASK_INDEX **TODO**
/*
/*
** Open string library
** Open string library
*/
*/
LUALIB_API
int
luaopen_string
(
lua_State
*
L
)
{
LUALIB_API
int
luaopen_string
(
lua_State
*
L
)
{
#if LUA_OPTIMIZE_MEMORY == 0
luaL_register
(
L
,
LUA_STRLIBNAME
,
strlib
);
#if defined(LUA_COMPAT_GFIND)
lua_getfield
(
L
,
-
1
,
"gmatch"
);
lua_setfield
(
L
,
-
2
,
"gfind"
);
#endif
createmetatable
(
L
);
return
1
;
#else
lua_pushliteral
(
L
,
""
);
lua_pushliteral
(
L
,
""
);
lua_pushrotable
(
L
,
(
void
*
)
strlib
);
lua_pushrotable
(
L
,
LROT_TABLEREF
(
strlib
)
)
;
lua_setmetatable
(
L
,
-
2
);
lua_setmetatable
(
L
,
-
2
);
lua_pop
(
L
,
1
);
lua_pop
(
L
,
1
);
return
0
;
return
0
;
#endif
}
}
app/lua/ltable.c
View file @
310faf7f
...
@@ -23,8 +23,8 @@
...
@@ -23,8 +23,8 @@
#define LUAC_CROSS_FILE
#define LUAC_CROSS_FILE
#include "lua.h"
#include "lua.h"
#include
C_HEADER_MATH
#include
<math.h>
#include
C_HEADER_STRING
#include
<string.h>
#include "ldebug.h"
#include "ldebug.h"
#include "ldo.h"
#include "ldo.h"
...
@@ -86,7 +86,7 @@ static Node *hashnum (const Table *t, lua_Number n) {
...
@@ -86,7 +86,7 @@ static Node *hashnum (const Table *t, lua_Number n) {
int
i
;
int
i
;
if
(
luai_numeq
(
n
,
0
))
/* avoid problems with -0 */
if
(
luai_numeq
(
n
,
0
))
/* avoid problems with -0 */
return
gnode
(
t
,
0
);
return
gnode
(
t
,
0
);
c_
memcpy
(
a
,
&
n
,
sizeof
(
a
));
memcpy
(
a
,
&
n
,
sizeof
(
a
));
for
(
i
=
1
;
i
<
numints
;
i
++
)
a
[
0
]
+=
a
[
i
];
for
(
i
=
1
;
i
<
numints
;
i
++
)
a
[
0
]
+=
a
[
i
];
return
hashmod
(
t
,
a
[
0
]);
return
hashmod
(
t
,
a
[
0
]);
}
}
...
@@ -580,7 +580,7 @@ const TValue *luaH_getnum (Table *t, int key) {
...
@@ -580,7 +580,7 @@ const TValue *luaH_getnum (Table *t, int key) {
/* same thing for rotables */
/* same thing for rotables */
const
TValue
*
luaH_getnum_ro
(
void
*
t
,
int
key
)
{
const
TValue
*
luaH_getnum_ro
(
void
*
t
,
int
key
)
{
const
TValue
*
res
=
luaR_findentryN
(
t
,
key
,
NULL
);
const
TValue
*
res
=
NULL
;
// integer values not supported:
luaR_findentryN(t, key, NULL);
return
res
?
res
:
luaO_nilobject
;
return
res
?
res
:
luaO_nilobject
;
}
}
...
@@ -739,11 +739,7 @@ int luaH_getn (Table *t) {
...
@@ -739,11 +739,7 @@ int luaH_getn (Table *t) {
/* same thing for rotables */
/* same thing for rotables */
int
luaH_getn_ro
(
void
*
t
)
{
int
luaH_getn_ro
(
void
*
t
)
{
int
i
=
1
,
len
=
0
;
return
0
;
// Integer Keys are not currently supported for ROTables
while
(
luaR_findentryN
(
t
,
i
++
,
NULL
))
len
++
;
return
len
;
}
}
int
luaH_isdummy
(
Node
*
n
)
{
return
n
==
dummynode
;
}
int
luaH_isdummy
(
Node
*
n
)
{
return
n
==
dummynode
;
}
...
...
app/lua/ltablib.c
View file @
310faf7f
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
#include "lauxlib.h"
#include "lauxlib.h"
#include "lualib.h"
#include "lualib.h"
#include "lrotable.h"
#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))
#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))
...
@@ -265,22 +266,18 @@ static int sort (lua_State *L) {
...
@@ -265,22 +266,18 @@ static int sort (lua_State *L) {
/* }====================================================== */
/* }====================================================== */
#undef MIN_OPT_LEVEL
LROT_PUBLIC_BEGIN
(
tab_funcs
)
#define MIN_OPT_LEVEL 1
LROT_FUNCENTRY
(
concat
,
tconcat
)
#include "lrodefs.h"
LROT_FUNCENTRY
(
foreach
,
foreach
)
const
LUA_REG_TYPE
tab_funcs
[]
=
{
LROT_FUNCENTRY
(
foreachi
,
foreachi
)
{
LSTRKEY
(
"concat"
),
LFUNCVAL
(
tconcat
)},
LROT_FUNCENTRY
(
getn
,
getn
)
{
LSTRKEY
(
"foreach"
),
LFUNCVAL
(
foreach
)},
LROT_FUNCENTRY
(
maxn
,
maxn
)
{
LSTRKEY
(
"foreachi"
),
LFUNCVAL
(
foreachi
)},
LROT_FUNCENTRY
(
insert
,
tinsert
)
{
LSTRKEY
(
"getn"
),
LFUNCVAL
(
getn
)},
LROT_FUNCENTRY
(
remove
,
tremove
)
{
LSTRKEY
(
"maxn"
),
LFUNCVAL
(
maxn
)},
LROT_FUNCENTRY
(
setn
,
setn
)
{
LSTRKEY
(
"insert"
),
LFUNCVAL
(
tinsert
)},
LROT_FUNCENTRY
(
sort
,
sort
)
{
LSTRKEY
(
"remove"
),
LFUNCVAL
(
tremove
)},
LROT_END
(
tab_funcs
,
NULL
,
0
)
{
LSTRKEY
(
"setn"
),
LFUNCVAL
(
setn
)},
{
LSTRKEY
(
"sort"
),
LFUNCVAL
(
sort
)},
{
LNILKEY
,
LNILVAL
}
};
LUALIB_API
int
luaopen_table
(
lua_State
*
L
)
{
LUALIB_API
int
luaopen_table
(
lua_State
*
L
)
{
LREGISTER
(
L
,
LUA_TABLIBNAME
,
tab_funcs
)
;
return
1
;
}
}
app/lua/ltm.c
View file @
310faf7f
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#define LUAC_CROSS_FILE
#define LUAC_CROSS_FILE
#include "lua.h"
#include "lua.h"
#include
C_HEADER_STRING
#include
<string.h>
#include "lobject.h"
#include "lobject.h"
#include "lstate.h"
#include "lstate.h"
...
...
app/lua/lua.c
View file @
310faf7f
...
@@ -5,10 +5,9 @@
...
@@ -5,10 +5,9 @@
*/
*/
// #include "c_signal.h"
#include <stdio.h>
#include "c_stdio.h"
#include <stdlib.h>
#include "c_stdlib.h"
#include <string.h>
#include "c_string.h"
#include "user_interface.h"
#include "user_interface.h"
#include "user_version.h"
#include "user_version.h"
#include "driver/readline.h"
#include "driver/readline.h"
...
@@ -22,9 +21,7 @@
...
@@ -22,9 +21,7 @@
#include "lauxlib.h"
#include "lauxlib.h"
#include "lualib.h"
#include "lualib.h"
#include "legc.h"
#include "legc.h"
#ifdef LUA_FLASH_STORE
#include "lflash.h"
#include "lflash.h"
#endif
#include "os_type.h"
#include "os_type.h"
lua_State
*
globalL
=
NULL
;
lua_State
*
globalL
=
NULL
;
...
@@ -34,9 +31,9 @@ static const char *progname = LUA_PROGNAME;
...
@@ -34,9 +31,9 @@ static const char *progname = LUA_PROGNAME;
static
void
l_message
(
const
char
*
pname
,
const
char
*
msg
)
{
static
void
l_message
(
const
char
*
pname
,
const
char
*
msg
)
{
#if defined(LUA_USE_STDIO)
#if defined(LUA_USE_STDIO)
if
(
pname
)
c_
fprintf
(
c_stderr
,
"%s: "
,
pname
);
if
(
pname
)
fprintf
(
c_stderr
,
"%s: "
,
pname
);
c_
fprintf
(
c_stderr
,
"%s
\n
"
,
msg
);
fprintf
(
c_stderr
,
"%s
\n
"
,
msg
);
c_
fflush
(
c_stderr
);
fflush
(
c_stderr
);
#else
#else
if
(
pname
)
luai_writestringerror
(
"%s: "
,
pname
);
if
(
pname
)
luai_writestringerror
(
"%s: "
,
pname
);
luai_writestringerror
(
"%s
\n
"
,
msg
);
luai_writestringerror
(
"%s
\n
"
,
msg
);
...
@@ -124,7 +121,7 @@ static int dofsfile (lua_State *L, const char *name) {
...
@@ -124,7 +121,7 @@ static int dofsfile (lua_State *L, const char *name) {
static
int
dostring
(
lua_State
*
L
,
const
char
*
s
,
const
char
*
name
)
{
static
int
dostring
(
lua_State
*
L
,
const
char
*
s
,
const
char
*
name
)
{
int
status
=
luaL_loadbuffer
(
L
,
s
,
c_
strlen
(
s
),
name
)
||
docall
(
L
,
0
,
1
);
int
status
=
luaL_loadbuffer
(
L
,
s
,
strlen
(
s
),
name
)
||
docall
(
L
,
0
,
1
);
return
report
(
L
,
status
);
return
report
(
L
,
status
);
}
}
...
@@ -150,7 +147,7 @@ static int incomplete (lua_State *L, int status) {
...
@@ -150,7 +147,7 @@ static int incomplete (lua_State *L, int status) {
size_t
lmsg
;
size_t
lmsg
;
const
char
*
msg
=
lua_tolstring
(
L
,
-
1
,
&
lmsg
);
const
char
*
msg
=
lua_tolstring
(
L
,
-
1
,
&
lmsg
);
const
char
*
tp
=
msg
+
lmsg
-
(
sizeof
(
LUA_QL
(
"<eof>"
))
-
1
);
const
char
*
tp
=
msg
+
lmsg
-
(
sizeof
(
LUA_QL
(
"<eof>"
))
-
1
);
if
(
c_
strstr
(
msg
,
LUA_QL
(
"<eof>"
))
==
tp
)
{
if
(
strstr
(
msg
,
LUA_QL
(
"<eof>"
))
==
tp
)
{
lua_pop
(
L
,
1
);
lua_pop
(
L
,
1
);
return
1
;
return
1
;
}
}
...
@@ -216,7 +213,7 @@ static int runargs (lua_State *L, char **argv, int n) {
...
@@ -216,7 +213,7 @@ static int runargs (lua_State *L, char **argv, int n) {
int
memlimit
=
0
;
int
memlimit
=
0
;
if
(
*
limit
==
'\0'
)
limit
=
argv
[
++
i
];
if
(
*
limit
==
'\0'
)
limit
=
argv
[
++
i
];
lua_assert
(
limit
!=
NULL
);
lua_assert
(
limit
!=
NULL
);
memlimit
=
c_
atoi
(
limit
);
memlimit
=
atoi
(
limit
);
lua_gc
(
L
,
LUA_GCSETMEMLIMIT
,
memlimit
);
lua_gc
(
L
,
LUA_GCSETMEMLIMIT
,
memlimit
);
break
;
break
;
}
}
...
@@ -309,7 +306,7 @@ int lua_main (int argc, char **argv) {
...
@@ -309,7 +306,7 @@ int lua_main (int argc, char **argv) {
gLoad
.
L
=
L
;
gLoad
.
L
=
L
;
gLoad
.
firstline
=
1
;
gLoad
.
firstline
=
1
;
gLoad
.
done
=
0
;
gLoad
.
done
=
0
;
gLoad
.
line
=
c_
malloc
(
LUA_MAXINPUT
);
gLoad
.
line
=
malloc
(
LUA_MAXINPUT
);
gLoad
.
len
=
LUA_MAXINPUT
;
gLoad
.
len
=
LUA_MAXINPUT
;
gLoad
.
line_position
=
0
;
gLoad
.
line_position
=
0
;
gLoad
.
prmt
=
get_prompt
(
L
,
1
);
gLoad
.
prmt
=
get_prompt
(
L
,
1
);
...
@@ -326,7 +323,7 @@ int lua_main (int argc, char **argv) {
...
@@ -326,7 +323,7 @@ int lua_main (int argc, char **argv) {
int
lua_put_line
(
const
char
*
s
,
size_t
l
)
{
int
lua_put_line
(
const
char
*
s
,
size_t
l
)
{
if
(
s
==
NULL
||
++
l
>
LUA_MAXINPUT
||
gLoad
.
line_position
>
0
)
if
(
s
==
NULL
||
++
l
>
LUA_MAXINPUT
||
gLoad
.
line_position
>
0
)
return
0
;
return
0
;
c_
memcpy
(
gLoad
.
line
,
s
,
l
);
memcpy
(
gLoad
.
line
,
s
,
l
);
gLoad
.
line
[
l
]
=
'\0'
;
gLoad
.
line
[
l
]
=
'\0'
;
gLoad
.
line_position
=
l
;
gLoad
.
line_position
=
l
;
gLoad
.
done
=
1
;
gLoad
.
done
=
1
;
...
@@ -338,7 +335,7 @@ void lua_handle_input (bool force)
...
@@ -338,7 +335,7 @@ void lua_handle_input (bool force)
{
{
while
(
gLoad
.
L
&&
(
force
||
readline
(
&
gLoad
)))
{
while
(
gLoad
.
L
&&
(
force
||
readline
(
&
gLoad
)))
{
NODE_DBG
(
"Handle Input: first=%u, pos=%u, len=%u, actual=%u, line=%s
\n
"
,
gLoad
.
firstline
,
NODE_DBG
(
"Handle Input: first=%u, pos=%u, len=%u, actual=%u, line=%s
\n
"
,
gLoad
.
firstline
,
gLoad
.
line_position
,
gLoad
.
len
,
c_
strlen
(
gLoad
.
line
),
gLoad
.
line
);
gLoad
.
line_position
,
gLoad
.
len
,
strlen
(
gLoad
.
line
),
gLoad
.
line
);
dojob
(
&
gLoad
);
dojob
(
&
gLoad
);
force
=
false
;
force
=
false
;
}
}
...
@@ -359,7 +356,7 @@ static void dojob(lua_Load *load){
...
@@ -359,7 +356,7 @@ static void dojob(lua_Load *load){
do
{
do
{
if
(
load
->
done
==
1
){
if
(
load
->
done
==
1
){
l
=
c_
strlen
(
b
);
l
=
strlen
(
b
);
if
(
l
>
0
&&
b
[
l
-
1
]
==
'\n'
)
/* line ends with newline? */
if
(
l
>
0
&&
b
[
l
-
1
]
==
'\n'
)
/* line ends with newline? */
b
[
l
-
1
]
=
'\0'
;
/* remove it */
b
[
l
-
1
]
=
'\0'
;
/* remove it */
if
(
load
->
firstline
&&
b
[
0
]
==
'='
)
/* first line starts with `=' ? */
if
(
load
->
firstline
&&
b
[
0
]
==
'='
)
/* first line starts with `=' ? */
...
@@ -403,8 +400,8 @@ static void dojob(lua_Load *load){
...
@@ -403,8 +400,8 @@ static void dojob(lua_Load *load){
load
->
done
=
0
;
load
->
done
=
0
;
load
->
line_position
=
0
;
load
->
line_position
=
0
;
c_
memset
(
load
->
line
,
0
,
load
->
len
);
memset
(
load
->
line
,
0
,
load
->
len
);
c_
puts
(
load
->
prmt
);
puts
(
load
->
prmt
);
}
}
#ifndef uart_putc
#ifndef uart_putc
...
@@ -470,7 +467,7 @@ static bool readline(lua_Load *load){
...
@@ -470,7 +467,7 @@ static bool readline(lua_Load *load){
if
(
load
->
line_position
==
0
)
if
(
load
->
line_position
==
0
)
{
{
/* Get a empty line, then go to get a new line */
/* Get a empty line, then go to get a new line */
c_
puts
(
load
->
prmt
);
puts
(
load
->
prmt
);
continue
;
continue
;
}
else
{
}
else
{
load
->
done
=
1
;
load
->
done
=
1
;
...
...
app/lua/lua.h
View file @
310faf7f
...
@@ -11,16 +11,10 @@
...
@@ -11,16 +11,10 @@
#ifdef LUAC_CROSS_FILE
#ifdef LUAC_CROSS_FILE
#include "luac_cross.h"
#include "luac_cross.h"
#endif
#endif
#ifdef LUA_CROSS_COMPILER
#include <stdint.h>
#include <stdarg.h>
#include "stdarg.h"
#include <stddef.h>
#include "stddef.h"
#include <ctype.h>
#include "ctype.h"
#else
#include "c_stdarg.h"
#include "c_stddef.h"
#include "c_types.h"
#include <ctype.h>
#endif
#include "luaconf.h"
#include "luaconf.h"
...
...
app/lua/luac_cross.h
View file @
310faf7f
...
@@ -6,73 +6,14 @@
...
@@ -6,73 +6,14 @@
#define luac_cross_h
#define luac_cross_h
#ifdef LUA_CROSS_COMPILER
#ifdef LUA_CROSS_COMPILER
#define C_HEADER_ASSERT <assert.h>
#define C_HEADER_CTYPE <ctype.h>
#define C_HEADER_ERRNO <errno.h>
#define C_HEADER_FCNTL <fcntl.h>
#define C_HEADER_LOCALE <locale.h>
#define C_HEADER_MATH <math.h>
#define C_HEADER_STDIO <stdio.h>
#define C_HEADER_STDLIB <stdlib.h>
#define C_HEADER_STRING <string.h>
#define C_HEADER_TIME <time.h>
#define ICACHE_RODATA_ATTR
#define ICACHE_RODATA_ATTR
#define c_abs abs
#define c_exit exit
#define c_fclose fclose
#define c_feof feof
#define c_ferror ferror
#define c_fopen fopen
#define c_fread fread
#define c_free free
#define c_freopen freopen
#define c_getc getc
#define c_getenv getenv
#define c_malloc malloc
#define c_memcmp memcmp
#define c_memcpy memcpy
#define c_printf printf
#define c_puts puts
#define c_reader reader
#define c_realloc realloc
#define c_sprintf sprintf
#define c_stderr stderr
#define c_stderr stderr
#define c_stdin stdin
#define c_stdin stdin
#define c_stdout stdout
#define c_stdout stdout
#define c_strcat strcat
#define c_strchr strchr
#define c_strcmp strcmp
#define c_strcoll strcoll
#define c_strcpy strcpy
#define c_strcspn strcspn
#define c_strerror strerror
#define c_strlen strlen
#define c_strncat strncat
#define c_strncmp strncmp
#define c_strncpy strncpy
#define c_strpbrk strpbrk
#define c_strrchr strrchr
#define c_strstr strstr
double
c_strtod
(
const
char
*
__n
,
char
**
__end_PTR
);
#define c_ungetc ungetc
#define c_strtol strtol
#define c_strtoul strtoul
#define dbg_printf printf
#define dbg_printf printf
#else
#else
#define C_HEADER_ASSERT "c_assert.h"
#define C_HEADER_CTYPE "c_ctype.h"
#define C_HEADER_ERRNO "c_errno.h"
#define C_HEADER_FCNTL "c_fcntl.h"
#define C_HEADER_LOCALE "c_locale.h"
#define C_HEADER_MATH "c_math.h"
#define C_HEADER_STDIO "c_stdio.h"
#define C_HEADER_STDLIB "c_stdlib.h"
#define C_HEADER_STRING "c_string.h"
#define C_HEADER_TIME "c_time.h"
#endif
/* LUA_CROSS_COMPILER */
#endif
/* LUA_CROSS_COMPILER */
#endif
/* luac_cross_h */
#endif
/* luac_cross_h */
app/lua/luac_cross/Makefile
View file @
310faf7f
...
@@ -8,12 +8,12 @@
...
@@ -8,12 +8,12 @@
summary
?=
@true
summary
?=
@true
CCFLAGS
:=
-I
..
-I
../../include
-I
../../libc
-I
../../uzlib
CCFLAGS
:=
-I
..
-I
../../include
-I
../../uzlib
LDFLAGS
:=
-L
$(SDK_DIR)
/lib
-L
$(SDK_DIR)
/ld
-lm
-ldl
-Wl
,-Map
=
mapfile
LDFLAGS
:=
-L
$(SDK_DIR)
/lib
-L
$(SDK_DIR)
/ld
-lm
-ldl
-Wl
,-Map
=
mapfile
CCFLAGS
+=
-Wall
CCFLAGS
+=
-Wall
DEFINES
+=
-DLUA_CROSS_COMPILER
-DLUA_OPTIMIZE_MEMORY
=
2
DEFINES
+=
-DLUA_CROSS_COMPILER
TARGET
=
host
TARGET
=
host
...
@@ -33,13 +33,12 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c
...
@@ -33,13 +33,12 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c
lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c lparser.c
\
lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c lparser.c
\
lrotable.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c
\
lrotable.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c
\
ltm.c lundump.c lvm.c lzio.c
ltm.c lundump.c lvm.c lzio.c
LIBCSRC
:=
c_stdlib.c
UZSRC
:=
uzlib_deflate.c crc32.c
UZSRC
:=
uzlib_deflate.c crc32.c
#
#
# This relies on the files being unique on the vpath
# This relies on the files being unique on the vpath
#
#
SRC
:=
$(LUACSRC)
$(LUASRC)
$(LIBCSRC)
$(UZSRC)
SRC
:=
$(LUACSRC)
$(LUASRC)
$(UZSRC)
vpath %.c .
:
..:../../libc:../../uzlib
vpath %.c .
:
..:../../libc:../../uzlib
ODIR
:=
.output/
$(TARGET)
/
$(FLAVOR)
/obj
ODIR
:=
.output/
$(TARGET)
/
$(FLAVOR)
/obj
...
@@ -54,7 +53,7 @@ CC := $(WRAPCC) gcc
...
@@ -54,7 +53,7 @@ CC := $(WRAPCC) gcc
ECHO
:=
echo
ECHO
:=
echo
BUILD_TYPE
:=
$(
shell
$(CC)
$(EXTRA_CCFLAGS)
-E
-dM
- <../../
../app/
include/user_config.h |
grep
LUA_NUMBER_INTEGRAL |
wc
-l
)
BUILD_TYPE
:=
$(
shell
$(CC)
$(EXTRA_CCFLAGS)
-E
-dM
- <../../include/user_config.h |
grep
LUA_NUMBER_INTEGRAL |
wc
-l
)
ifeq
($(BUILD_TYPE),0)
ifeq
($(BUILD_TYPE),0)
IMAGE
:=
../../../luac.cross
IMAGE
:=
../../../luac.cross
else
else
...
...
app/lua/luac_cross/lflashimg.c
View file @
310faf7f
...
@@ -7,17 +7,15 @@
...
@@ -7,17 +7,15 @@
#define LUAC_CROSS_FILE
#define LUAC_CROSS_FILE
#include "luac_cross.h"
#include "luac_cross.h"
#include
C_HEADER_CTYPE
#include
<ctype.h>
#include
C_HEADER_STDIO
#include
<stdio.h>
#include
C_HEADER_STDLIB
#include
<stdlib.h>
#include
C_HEADER_STRING
#include
<string.h>
#define lflashimg_c
#define lflashimg_c
#define LUA_CORE
#define LUA_CORE
#include "lobject.h"
#include "lobject.h"
#include "lstring.h"
#include "lstring.h"
#undef LUA_FLASH_STORE
#define LUA_FLASH_STORE
#include "lflash.h"
#include "lflash.h"
#include "uzlib.h"
#include "uzlib.h"
...
...
app/lua/luac_cross/liolib.c
View file @
310faf7f
...
@@ -12,12 +12,12 @@
...
@@ -12,12 +12,12 @@
#define liolib_c
#define liolib_c
#define LUA_LIB
#define LUA_LIB
#define LUA_OPTIMIZE_MEMORY 2
#include "lua.h"
#include "lua.h"
#include "lauxlib.h"
#include "lauxlib.h"
#include "lualib.h"
#include "lualib.h"
#include "lrotable.h"
#define IO_INPUT 1
#define IO_INPUT 1
#define IO_OUTPUT 2
#define IO_OUTPUT 2
...
@@ -439,36 +439,31 @@ static int f_flush (lua_State *L) {
...
@@ -439,36 +439,31 @@ static int f_flush (lua_State *L) {
return
pushresult
(
L
,
fflush
(
tofile
(
L
))
==
0
,
NULL
);
return
pushresult
(
L
,
fflush
(
tofile
(
L
))
==
0
,
NULL
);
}
}
#define MIN_OPT_LEVEL 2
LROT_PUBLIC_BEGIN
(
iolib
)
#include "lrodefs.h"
LROT_FUNCENTRY
(
close
,
io_close
)
const
LUA_REG_TYPE
iolib_funcs
[]
=
{
LROT_FUNCENTRY
(
flush
,
io_flush
)
{
LSTRKEY
(
"close"
),
LFUNCVAL
(
io_close
)},
LROT_FUNCENTRY
(
input
,
io_input
)
{
LSTRKEY
(
"flush"
),
LFUNCVAL
(
io_flush
)},
LROT_FUNCENTRY
(
lines
,
io_lines
)
{
LSTRKEY
(
"input"
),
LFUNCVAL
(
io_input
)},
LROT_FUNCENTRY
(
open
,
io_open
)
{
LSTRKEY
(
"lines"
),
LFUNCVAL
(
io_lines
)},
LROT_FUNCENTRY
(
output
,
io_output
)
{
LSTRKEY
(
"open"
),
LFUNCVAL
(
io_open
)},
LROT_FUNCENTRY
(
read
,
io_read
)
{
LSTRKEY
(
"output"
),
LFUNCVAL
(
io_output
)},
LROT_FUNCENTRY
(
type
,
io_type
)
{
LSTRKEY
(
"read"
),
LFUNCVAL
(
io_read
)},
LROT_FUNCENTRY
(
write
,
io_write
)
{
LSTRKEY
(
"type"
),
LFUNCVAL
(
io_type
)},
LROT_TABENTRY
(
__index
,
iolib
)
{
LSTRKEY
(
"write"
),
LFUNCVAL
(
io_write
)},
LROT_END
(
iolib
,
NULL
,
0
)
{
LSTRKEY
(
"__index"
),
LROVAL
(
iolib_funcs
)},
{
LNILKEY
,
LNILVAL
}
LROT_BEGIN
(
flib
)
};
LROT_FUNCENTRY
(
close
,
io_close
)
LROT_FUNCENTRY
(
flush
,
f_flush
)
#include "lrodefs.h"
LROT_FUNCENTRY
(
lines
,
f_lines
)
const
LUA_REG_TYPE
flib
[]
=
{
LROT_FUNCENTRY
(
read
,
f_read
)
{
LSTRKEY
(
"close"
),
LFUNCVAL
(
io_close
)},
LROT_FUNCENTRY
(
seek
,
f_seek
)
{
LSTRKEY
(
"flush"
),
LFUNCVAL
(
f_flush
)},
LROT_FUNCENTRY
(
setvbuf
,
f_setvbuf
)
{
LSTRKEY
(
"lines"
),
LFUNCVAL
(
f_lines
)},
LROT_FUNCENTRY
(
write
,
f_write
)
{
LSTRKEY
(
"read"
),
LFUNCVAL
(
f_read
)},
LROT_FUNCENTRY
(
__gc
,
io_gc
)
{
LSTRKEY
(
"seek"
),
LFUNCVAL
(
f_seek
)},
LROT_FUNCENTRY
(
__tostring
,
io_tostring
)
{
LSTRKEY
(
"setvbuf"
),
LFUNCVAL
(
f_setvbuf
)},
LROT_TABENTRY
(
__index
,
flib
)
{
LSTRKEY
(
"write"
),
LFUNCVAL
(
f_write
)},
LROT_END
(
flib
,
NULL
,
LROT_MASK_GC_INDEX
)
{
LSTRKEY
(
"__gc"
),
LFUNCVAL
(
io_gc
)},
{
LSTRKEY
(
"__tostring"
),
LFUNCVAL
(
io_tostring
)},
{
LSTRKEY
(
"__index"
),
LROVAL
(
flib
)},
{
LNILKEY
,
LNILVAL
}
};
static
const
luaL_Reg
io_base
[]
=
{{
NULL
,
NULL
}};
static
const
luaL_Reg
io_base
[]
=
{{
NULL
,
NULL
}};
...
@@ -481,12 +476,12 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
...
@@ -481,12 +476,12 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
}
}
LUALIB_API
int
luaopen_io
(
lua_State
*
L
)
{
LUALIB_API
int
luaopen_io
(
lua_State
*
L
)
{
luaL_rometatable
(
L
,
LUA_FILEHANDLE
,
(
void
*
)
flib
);
/* create metatable for file handles */
luaL_rometatable
(
L
,
LUA_FILEHANDLE
,
LROT_TABLEREF
(
flib
)
)
;
/* create metatable for file handles */
luaL_register_light
(
L
,
LUA_IOLIBNAME
,
io_base
);
luaL_register_light
(
L
,
LUA_IOLIBNAME
,
io_base
);
lua_pushvalue
(
L
,
-
1
);
lua_pushvalue
(
L
,
-
1
);
lua_setmetatable
(
L
,
-
2
);
lua_setmetatable
(
L
,
-
2
);
lua_pushliteral
(
L
,
"__index"
);
lua_pushliteral
(
L
,
"__index"
);
lua_pushrotable
(
L
,
(
void
*
)
iolib_funcs
);
lua_pushrotable
(
L
,
LROT_TABLEREF
(
iolib
)
);
lua_rawset
(
L
,
-
3
);
lua_rawset
(
L
,
-
3
);
/* create (and set) default files */
/* create (and set) default files */
...
...
app/lua/luac_cross/loslib.c
View file @
310faf7f
...
@@ -7,11 +7,11 @@
...
@@ -7,11 +7,11 @@
#define LUAC_CROSS_FILE
#define LUAC_CROSS_FILE
#include "luac_cross.h"
#include "luac_cross.h"
#include
C_HEADER_ERRNO
#include
<errno.h>
#include
C_HEADER_LOCALE
#include
<locale.h>
#include
C_HEADER_STDLIB
#include
<stdlib.h>
#include
C_HEADER_STRING
#include
<string.h>
#include
C_HEADER_TIME
#include
<time.h>
#define loslib_c
#define loslib_c
#define LUA_LIB
#define LUA_LIB
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#include "lauxlib.h"
#include "lauxlib.h"
#include "lualib.h"
#include "lualib.h"
#include "lrotable.h"
static
int
os_pushresult
(
lua_State
*
L
,
int
i
,
const
char
*
filename
)
{
static
int
os_pushresult
(
lua_State
*
L
,
int
i
,
const
char
*
filename
)
{
int
en
=
errno
;
/* calls to Lua API may change this value */
int
en
=
errno
;
/* calls to Lua API may change this value */
...
@@ -216,33 +217,28 @@ static int os_setlocale (lua_State *L) {
...
@@ -216,33 +217,28 @@ static int os_setlocale (lua_State *L) {
static
int
os_exit
(
lua_State
*
L
)
{
static
int
os_exit
(
lua_State
*
L
)
{
c_
exit
(
luaL_optint
(
L
,
1
,
EXIT_SUCCESS
));
exit
(
luaL_optint
(
L
,
1
,
EXIT_SUCCESS
));
}
}
#undef MIN_OPT_LEVEL
LROT_PUBLIC_BEGIN
(
oslib
)
#define MIN_OPT_LEVEL 1
LROT_FUNCENTRY
(
clock
,
os_clock
)
#include "lrodefs.h"
LROT_FUNCENTRY
(
date
,
os_date
)
const
LUA_REG_TYPE
syslib
[]
=
{
{
LSTRKEY
(
"clock"
),
LFUNCVAL
(
os_clock
)},
{
LSTRKEY
(
"date"
),
LFUNCVAL
(
os_date
)},
#if !defined LUA_NUMBER_INTEGRAL
#if !defined LUA_NUMBER_INTEGRAL
{
LSTRKE
Y
(
"
difftime
"
),
LFUNCVAL
(
os_difftime
)
},
LROT_FUNCENTR
Y
(
difftime
,
os_difftime
)
#endif
#endif
{
LSTRKEY
(
"execute"
),
LFUNCVAL
(
os_execute
)},
LROT_FUNCENTRY
(
execute
,
os_execute
)
{
LSTRKEY
(
"exit"
),
LFUNCVAL
(
os_exit
)},
LROT_FUNCENTRY
(
exit
,
os_exit
)
{
LSTRKEY
(
"getenv"
),
LFUNCVAL
(
os_getenv
)},
LROT_FUNCENTRY
(
getenv
,
os_getenv
)
{
LSTRKEY
(
"remove"
),
LFUNCVAL
(
os_remove
)},
LROT_FUNCENTRY
(
remove
,
os_remove
)
{
LSTRKEY
(
"rename"
),
LFUNCVAL
(
os_rename
)},
LROT_FUNCENTRY
(
rename
,
os_rename
)
{
LSTRKEY
(
"setlocale"
),
LFUNCVAL
(
os_setlocale
)},
LROT_FUNCENTRY
(
setlocale
,
os_setlocale
)
{
LSTRKEY
(
"time"
),
LFUNCVAL
(
os_time
)},
LROT_FUNCENTRY
(
time
,
os_time
)
{
LSTRKEY
(
"tmpname"
),
LFUNCVAL
(
os_tmpname
)},
LROT_FUNCENTRY
(
tmpname
,
os_tmpname
)
{
LNILKEY
,
LNILVAL
}
LROT_END
(
oslib
,
NULL
,
0
)
};
/* }====================================================== */
/* }====================================================== */
LUALIB_API
int
luaopen_os
(
lua_State
*
L
)
{
LUALIB_API
int
luaopen_os
(
lua_State
*
L
)
{
LREGISTER
(
L
,
LUA_OSLIBNAME
,
syslib
)
;
return
1
;
}
}
app/lua/luac_cross/luac.c
View file @
310faf7f
...
@@ -7,10 +7,10 @@
...
@@ -7,10 +7,10 @@
#define LUAC_CROSS_FILE
#define LUAC_CROSS_FILE
#include "luac_cross.h"
#include "luac_cross.h"
#include
C_HEADER_ERRNO
#include
<errno.h>
#include
C_HEADER_STDIO
#include
<stdio.h>
#include
C_HEADER_STDLIB
#include
<stdlib.h>
#include
C_HEADER_STRING
#include
<string.h>
#include <time.h>
#include <time.h>
#define luac_c
#define luac_c
...
...
app/lua/luac_cross/mingw32-Makefile.mak
View file @
310faf7f
...
@@ -38,12 +38,11 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c
...
@@ -38,12 +38,11 @@ LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c
lmathlib.c
lmem.c
loadlib.c
lobject.c
lopcodes.c
lparser.c
\
lmathlib.c
lmem.c
loadlib.c
lobject.c
lopcodes.c
lparser.c
\
lrotable.c
lstate.c
lstring.c
lstrlib.c
ltable.c
ltablib.c
\
lrotable.c
lstate.c
lstring.c
lstrlib.c
ltable.c
ltablib.c
\
ltm.c
lundump.c
lvm.c
lzio.c
ltm.c
lundump.c
lvm.c
lzio.c
LIBCSRC
:=
c_stdlib.c
UZSRC
:=
uzlib_deflate.c crc32.c
UZSRC
:=
uzlib_deflate.c crc32.c
#
#
# This relies on the files being unique on the vpath
# This relies on the files being unique on the vpath
#
#
SRC
:=
$(LUACSRC)
$(LUASRC)
$(LIBCSRC)
$(UZSRC)
SRC
:=
$(LUACSRC)
$(LUASRC)
$(UZSRC)
vpath %.c .
:
..:../../libc:../../uzlib
vpath %.c .
:
..:../../libc:../../uzlib
...
...
app/lua/luac_cross/print.c
View file @
310faf7f
...
@@ -7,8 +7,8 @@
...
@@ -7,8 +7,8 @@
#define LUAC_CROSS_FILE
#define LUAC_CROSS_FILE
#include "luac_cross.h"
#include "luac_cross.h"
#include
C_HEADER_CTYPE
#include
<ctype.h>
#include
C_HEADER_STDIO
#include
<stdio.h>
#define luac_c
#define luac_c
#define LUA_CORE
#define LUA_CORE
...
...
app/lua/luaconf.h
View file @
310faf7f
...
@@ -8,13 +8,9 @@
...
@@ -8,13 +8,9 @@
#ifndef lconfig_h
#ifndef lconfig_h
#define lconfig_h
#define lconfig_h
#ifdef LUA_CROSS_COMPILER
#include <limits.h>
#include <limits.h>
#include <stddef.h>
#include <stddef.h>
#else
#include <stdbool.h>
#include "c_limits.h"
#include "c_stddef.h"
#endif
#include "user_config.h"
#include "user_config.h"
/*
/*
...
@@ -262,11 +258,7 @@
...
@@ -262,11 +258,7 @@
#define lua_stdin_is_tty() isatty(0)
#define lua_stdin_is_tty() isatty(0)
#elif defined(LUA_WIN)
#elif defined(LUA_WIN)
#include <io.h>
#include <io.h>
#ifdef LUA_CROSS_COMPILER
#include <stdio.h>
#include <stdio.h>
#else
#include "c_stdio.h"
#endif
#define lua_stdin_is_tty() _isatty(_fileno(stdin))
#define lua_stdin_is_tty() _isatty(_fileno(stdin))
#else
#else
...
@@ -317,11 +309,11 @@
...
@@ -317,11 +309,11 @@
#define lua_saveline(L,idx) \
#define lua_saveline(L,idx) \
if (lua_strlen(L,idx) > 0)
/* non-empty line? */
\
if (lua_strlen(L,idx) > 0)
/* non-empty line? */
\
add_history(lua_tostring(L, idx));
/* add it to history */
add_history(lua_tostring(L, idx));
/* add it to history */
#define lua_freeline(L,b) ((void)L,
c_
free(b))
#define lua_freeline(L,b) ((void)L, free(b))
#else // #if defined(LUA_CROSS_COMPILER) && defined(LUA_USE_READLINE)
#else // #if defined(LUA_CROSS_COMPILER) && defined(LUA_USE_READLINE)
#define lua_readline(L,b,p) \
#define lua_readline(L,b,p) \
((void)L,
c_
fputs(p, c_stdout),
c_
fflush(c_stdout),
/* show prompt */
\
((void)L, fputs(p, c_stdout), fflush(c_stdout),
/* show prompt */
\
c_
fgets(b, LUA_MAXINPUT, c_stdin) != NULL)
/* get line */
fgets(b, LUA_MAXINPUT, c_stdin) != NULL)
/* get line */
#define lua_saveline(L,idx) { (void)L; (void)idx; }
#define lua_saveline(L,idx) { (void)L; (void)idx; }
#define lua_freeline(L,b) { (void)L; (void)b; }
#define lua_freeline(L,b) { (void)L; (void)b; }
#endif // #if defined(LUA_USE_READLINE)
#endif // #if defined(LUA_USE_READLINE)
...
@@ -342,8 +334,8 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
...
@@ -342,8 +334,8 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
** avoids including 'stdio.h' everywhere.)
** avoids including 'stdio.h' everywhere.)
*/
*/
#if !defined(LUA_USE_STDIO)
#if !defined(LUA_USE_STDIO)
#define luai_writestring(s, l)
c_
puts(s)
#define luai_writestring(s, l) puts(s)
#define luai_writeline()
c_
puts("\n")
#define luai_writeline() puts("\n")
#endif // defined(LUA_USE_STDIO)
#endif // defined(LUA_USE_STDIO)
/*
/*
...
@@ -622,31 +614,23 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
...
@@ -622,31 +614,23 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
#define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_FMT "%.14g"
#define LUA_NUMBER_FMT "%.14g"
#endif // #if defined LUA_NUMBER_INTEGRAL
#endif // #if defined LUA_NUMBER_INTEGRAL
#define lua_number2str(s,n)
c_
sprintf((s), LUA_NUMBER_FMT, (n))
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
#define LUAI_MAXNUMBER2STR 32
/* 16 digits, sign, point, and \0 */
#define LUAI_MAXNUMBER2STR 32
/* 16 digits, sign, point, and \0 */
#if defined LUA_NUMBER_INTEGRAL
#if defined LUA_NUMBER_INTEGRAL
#if !defined LUA_INTEGRAL_LONGLONG
#if !defined LUA_INTEGRAL_LONGLONG
#define lua_str2number(s,p)
c_
strtol((s), (p), 10)
#define lua_str2number(s,p) strtol((s), (p), 10)
#else
#else
#define lua_str2number(s,p)
c_
strtoll((s), (p), 10)
#define lua_str2number(s,p) strtoll((s), (p), 10)
#endif // #if !defined LUA_INTEGRAL_LONGLONG
#endif // #if !defined LUA_INTEGRAL_LONGLONG
#else
#else
#ifdef _MSC_VER //what's wrong with stdlib strtod?
#define lua_str2number(s,p) strtod((s), (p))
#define lua_str2number(s,p) strtod((s), (p))
#else
#define lua_str2number(s,p) c_strtod((s), (p))
#endif
#endif // #if defined LUA_NUMBER_INTEGRAL
#endif // #if defined LUA_NUMBER_INTEGRAL
/*
/*
@@ The luai_num* macros define the primitive operations over numbers.
@@ The luai_num* macros define the primitive operations over numbers.
*/
*/
#if defined(LUA_CORE) || defined(LUA_LIB)
#if defined(LUA_CORE) || defined(LUA_LIB)
#ifdef LUA_CROSS_COMPILER
#include <math.h>
#include <math.h>
#else
#include "c_math.h"
#endif
#define luai_numadd(a,b) ((a)+(b))
#define luai_numadd(a,b) ((a)+(b))
#define luai_numsub(a,b) ((a)-(b))
#define luai_numsub(a,b) ((a)-(b))
#define luai_nummul(a,b) ((a)*(b))
#define luai_nummul(a,b) ((a)*(b))
...
@@ -801,7 +785,7 @@ union luai_Cast { double l_d; long l_l; };
...
@@ -801,7 +785,7 @@ union luai_Cast { double l_d; long l_l; };
#include <unistd.h>
#include <unistd.h>
#define LUA_TMPNAMBUFSIZE 32
#define LUA_TMPNAMBUFSIZE 32
#define lua_tmpnam(b,e) { \
#define lua_tmpnam(b,e) { \
c_
strcpy(b, "/tmp/lua_XXXXXX"); \
strcpy(b, "/tmp/lua_XXXXXX"); \
e = mkstemp(b); \
e = mkstemp(b); \
if (e != -1) close(e); \
if (e != -1) close(e); \
e = (e == -1); }
e = (e == -1); }
...
@@ -821,7 +805,7 @@ union luai_Cast { double l_d; long l_l; };
...
@@ -821,7 +805,7 @@ union luai_Cast { double l_d; long l_l; };
*/
*/
#if defined(LUA_USE_POPEN)
#if defined(LUA_USE_POPEN)
#define lua_popen(L,c,m) ((void)L,
c_
fflush(NULL), popen(c,m))
#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
#define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
#define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
#elif defined(LUA_WIN)
#elif defined(LUA_WIN)
...
@@ -910,8 +894,8 @@ union luai_Cast { double l_d; long l_l; };
...
@@ -910,8 +894,8 @@ union luai_Cast { double l_d; long l_l; };
** without modifying the main part of the file.
** without modifying the main part of the file.
*/
*/
#if
LUA_OPTIMIZE_MEMORY == 2 &&
defined(LUA_USE_POPEN)
#if defined(LUA_USE_POPEN)
#error "Pipes not supported
in aggresive optimization mode (LUA_OPTIMIZE_MEMORY=2)
"
#error "Pipes not supported
NodeMCU firmware
"
#endif
#endif
#endif
#endif
app/lua/lundump.c
View file @
310faf7f
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
#define LUAC_CROSS_FILE
#define LUAC_CROSS_FILE
#include "lua.h"
#include "lua.h"
#include
C_HEADER_STRING
#include
<string.h>
#include "ldebug.h"
#include "ldebug.h"
#include "ldo.h"
#include "ldo.h"
...
@@ -309,7 +309,7 @@ static void LoadHeader(LoadState* S)
...
@@ -309,7 +309,7 @@ static void LoadHeader(LoadState* S)
S
->
numsize
=
h
[
10
]
=
s
[
10
];
/* length of lua_Number */
S
->
numsize
=
h
[
10
]
=
s
[
10
];
/* length of lua_Number */
S
->
toflt
=
(
s
[
11
]
>
intck
);
/* check if conversion from int lua_Number to flt is needed */
S
->
toflt
=
(
s
[
11
]
>
intck
);
/* check if conversion from int lua_Number to flt is needed */
if
(
S
->
toflt
)
s
[
11
]
=
h
[
11
];
if
(
S
->
toflt
)
s
[
11
]
=
h
[
11
];
IF
(
c_
memcmp
(
h
,
s
,
LUAC_HEADERSIZE
)
!=
0
,
"bad header"
);
IF
(
memcmp
(
h
,
s
,
LUAC_HEADERSIZE
)
!=
0
,
"bad header"
);
}
}
/*
/*
...
@@ -338,7 +338,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
...
@@ -338,7 +338,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
void
luaU_header
(
char
*
h
)
void
luaU_header
(
char
*
h
)
{
{
int
x
=
1
;
int
x
=
1
;
c_
memcpy
(
h
,
LUA_SIGNATURE
,
sizeof
(
LUA_SIGNATURE
)
-
1
);
memcpy
(
h
,
LUA_SIGNATURE
,
sizeof
(
LUA_SIGNATURE
)
-
1
);
h
+=
sizeof
(
LUA_SIGNATURE
)
-
1
;
h
+=
sizeof
(
LUA_SIGNATURE
)
-
1
;
*
h
++=
(
char
)
LUAC_VERSION
;
*
h
++=
(
char
)
LUAC_VERSION
;
*
h
++=
(
char
)
LUAC_FORMAT
;
*
h
++=
(
char
)
LUAC_FORMAT
;
...
...
app/lua/lundump.h
View file @
310faf7f
...
@@ -7,11 +7,7 @@
...
@@ -7,11 +7,7 @@
#ifndef lundump_h
#ifndef lundump_h
#define lundump_h
#define lundump_h
#ifdef LUA_CROSS_COMPILER
#include <stdint.h>
#include <stdint.h>
#else
#include "c_stdint.h"
#endif
#include "lobject.h"
#include "lobject.h"
#include "lzio.h"
#include "lzio.h"
...
...
app/lua/lvm.c
View file @
310faf7f
...
@@ -10,9 +10,9 @@
...
@@ -10,9 +10,9 @@
#define LUAC_CROSS_FILE
#define LUAC_CROSS_FILE
#include "lua.h"
#include "lua.h"
#include
C_HEADER_STDIO
#include
<stdio.h>
#include
C_HEADER_STRING
#include
<string.h>
#include
C_HEADER_MATH
#include
<math.h>
#include "ldebug.h"
#include "ldebug.h"
#include "ldo.h"
#include "ldo.h"
...
@@ -252,10 +252,10 @@ static int l_strcmp (const TString *ls, const TString *rs) {
...
@@ -252,10 +252,10 @@ static int l_strcmp (const TString *ls, const TString *rs) {
const
char
*
r
=
getstr
(
rs
);
const
char
*
r
=
getstr
(
rs
);
size_t
lr
=
rs
->
tsv
.
len
;
size_t
lr
=
rs
->
tsv
.
len
;
for
(;;)
{
for
(;;)
{
int
temp
=
c_
strcoll
(
l
,
r
);
int
temp
=
strcoll
(
l
,
r
);
if
(
temp
!=
0
)
return
temp
;
if
(
temp
!=
0
)
return
temp
;
else
{
/* strings are equal up to a `\0' */
else
{
/* strings are equal up to a `\0' */
size_t
len
=
c_
strlen
(
l
);
/* index of first `\0' in both strings */
size_t
len
=
strlen
(
l
);
/* index of first `\0' in both strings */
if
(
len
==
lr
)
/* r is finished? */
if
(
len
==
lr
)
/* r is finished? */
return
(
len
==
ll
)
?
0
:
1
;
return
(
len
==
ll
)
?
0
:
1
;
else
if
(
len
==
ll
)
/* l is finished? */
else
if
(
len
==
ll
)
/* l is finished? */
...
@@ -363,7 +363,7 @@ void luaV_concat (lua_State *L, int total, int last) {
...
@@ -363,7 +363,7 @@ void luaV_concat (lua_State *L, int total, int last) {
tl
=
0
;
tl
=
0
;
for
(
i
=
n
;
i
>
0
;
i
--
)
{
/* concat all strings */
for
(
i
=
n
;
i
>
0
;
i
--
)
{
/* concat all strings */
size_t
l
=
tsvalue
(
top
-
i
)
->
len
;
size_t
l
=
tsvalue
(
top
-
i
)
->
len
;
c_
memcpy
(
buffer
+
tl
,
svalue
(
top
-
i
),
l
);
memcpy
(
buffer
+
tl
,
svalue
(
top
-
i
),
l
);
tl
+=
l
;
tl
+=
l
;
}
}
setsvalue2s
(
L
,
top
-
n
,
luaS_newlstr
(
L
,
buffer
,
tl
));
setsvalue2s
(
L
,
top
-
n
,
luaS_newlstr
(
L
,
buffer
,
tl
));
...
...
app/lua/lzio.c
View file @
310faf7f
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#define LUAC_CROSS_FILE
#define LUAC_CROSS_FILE
#include "lua.h"
#include "lua.h"
#include
C_HEADER_STRING
#include
<string.h>
#include "llimits.h"
#include "llimits.h"
#include "lmem.h"
#include "lmem.h"
...
@@ -62,7 +62,7 @@ size_t luaZ_read (ZIO *z, void *b, size_t n) {
...
@@ -62,7 +62,7 @@ size_t luaZ_read (ZIO *z, void *b, size_t n) {
return
n
;
/* return number of missing bytes */
return
n
;
/* return number of missing bytes */
m
=
(
n
<=
z
->
n
)
?
n
:
z
->
n
;
/* min. between n and z->n */
m
=
(
n
<=
z
->
n
)
?
n
:
z
->
n
;
/* min. between n and z->n */
if
(
b
)
if
(
b
)
c_
memcpy
(
b
,
z
->
p
,
m
);
memcpy
(
b
,
z
->
p
,
m
);
z
->
n
-=
m
;
z
->
n
-=
m
;
z
->
i
+=
m
;
z
->
i
+=
m
;
z
->
p
+=
m
;
z
->
p
+=
m
;
...
...
Prev
1
…
3
4
5
6
7
8
9
10
11
…
19
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