Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
991965e2
Commit
991965e2
authored
Oct 04, 2016
by
Johny Mattsson
Browse files
Actually include standard Lua modules.
parent
3503a1ec
Changes
7
Hide whitespace changes
Inline
Side-by-side
components/base_nodemcu/linit.c
View file @
991965e2
...
...
@@ -15,7 +15,7 @@
#include "lauxlib.h"
#include "luaconf.h"
#include "module.h"
#include "sdkconfig.h"
BUILTIN_LIB_INIT
(
BASE
,
""
,
luaopen_base
);
BUILTIN_LIB_INIT
(
LOADLIB
,
LUA_LOADLIBNAME
,
luaopen_package
);
...
...
@@ -24,19 +24,19 @@ BUILTIN_LIB_INIT( LOADLIB, LUA_LOADLIBNAME, luaopen_package);
BUILTIN_LIB_INIT
(
IO
,
LUA_IOLIBNAME
,
luaopen_io
);
#endif
#if defined (
LUA_USE
_BUILTIN_STRING)
#if defined (
CONFIG_LUA
_BUILTIN_STRING)
extern
const
luaR_entry
strlib
[];
BUILTIN_LIB_INIT
(
STRING
,
LUA_STRLIBNAME
,
luaopen_string
);
BUILTIN_LIB
(
STRING
,
LUA_STRLIBNAME
,
strlib
);
#endif
#if defined(
LUA_USE
_BUILTIN_TABLE)
#if defined(
CONFIG_LUA
_BUILTIN_TABLE)
extern
const
luaR_entry
tab_funcs
[];
BUILTIN_LIB_INIT
(
TABLE
,
LUA_TABLIBNAME
,
luaopen_table
);
BUILTIN_LIB
(
TABLE
,
LUA_TABLIBNAME
,
tab_funcs
);
#endif
#if defined(
LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE
_BUILTIN_DEBUG
_MINIMAL
)
#if defined(
CONFIG_LUA
_BUILTIN_DEBUG)
extern
const
luaR_entry
dblib
[];
BUILTIN_LIB_INIT
(
DBG
,
LUA_DBLIBNAME
,
luaopen_debug
);
BUILTIN_LIB
(
DBG
,
LUA_DBLIBNAME
,
dblib
);
...
...
@@ -47,12 +47,12 @@ extern const luaR_entry syslib[];
BUILTIN_LIB
(
OS
,
LUA_OSLIBNAME
,
syslib
);
#endif
#if defined(
LUA_USE
_BUILTIN_COROUTINE)
#if defined(
CONFIG_LUA
_BUILTIN_COROUTINE)
extern
const
luaR_entry
co_funcs
[];
BUILTIN_LIB
(
CO
,
LUA_COLIBNAME
,
co_funcs
);
#endif
#if defined(
LUA_USE
_BUILTIN_MATH)
#if defined(
CONFIG_LUA
_BUILTIN_MATH)
extern
const
luaR_entry
math_map
[];
BUILTIN_LIB
(
MATH
,
LUA_MATHLIBNAME
,
math_map
);
#endif
...
...
components/lua/Makefile.projbuild
View file @
991965e2
...
...
@@ -4,4 +4,5 @@ CFLAGS+=\
-DLUA_OPTIMIZE_MEMORY
=
2
\
-DMIN_OPT_LEVEL
=
2
\
-DLUA_OPTIMIZE_DEBUG
=
$(CONFIG_LUA_OPTIMIZE_DEBUG)
\
-DLUA_USE_STDIO
\
components/lua/lauxlib.c
View file @
991965e2
...
...
@@ -592,14 +592,14 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {
*
size
=
1
;
return
"
\n
"
;
}
if
(
c_
feof
(
lf
->
f
))
return
NULL
;
*
size
=
c_
fread
(
lf
->
buff
,
1
,
sizeof
(
lf
->
buff
),
lf
->
f
);
if
(
feof
(
lf
->
f
))
return
NULL
;
*
size
=
fread
(
lf
->
buff
,
1
,
sizeof
(
lf
->
buff
),
lf
->
f
);
return
(
*
size
>
0
)
?
lf
->
buff
:
NULL
;
}
static
int
errfile
(
lua_State
*
L
,
const
char
*
what
,
int
fnameindex
)
{
const
char
*
serr
=
c_
strerror
(
errno
);
const
char
*
serr
=
strerror
(
errno
);
const
char
*
filename
=
lua_tostring
(
L
,
fnameindex
)
+
1
;
lua_pushfstring
(
L
,
"cannot %s %s: %s"
,
what
,
filename
,
serr
);
lua_remove
(
L
,
fnameindex
);
...
...
@@ -615,30 +615,30 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
lf
.
extraline
=
0
;
if
(
filename
==
NULL
)
{
lua_pushliteral
(
L
,
"=stdin"
);
lf
.
f
=
c_
stdin
;
lf
.
f
=
stdin
;
}
else
{
lua_pushfstring
(
L
,
"@%s"
,
filename
);
lf
.
f
=
c_
fopen
(
filename
,
"r"
);
lf
.
f
=
fopen
(
filename
,
"r"
);
if
(
lf
.
f
==
NULL
)
return
errfile
(
L
,
"open"
,
fnameindex
);
}
c
=
c_
getc
(
lf
.
f
);
c
=
getc
(
lf
.
f
);
if
(
c
==
'#'
)
{
/* Unix exec. file? */
lf
.
extraline
=
1
;
while
((
c
=
c_
getc
(
lf
.
f
))
!=
EOF
&&
c
!=
'\n'
)
;
/* skip first line */
if
(
c
==
'\n'
)
c
=
c_
getc
(
lf
.
f
);
while
((
c
=
getc
(
lf
.
f
))
!=
EOF
&&
c
!=
'\n'
)
;
/* skip first line */
if
(
c
==
'\n'
)
c
=
getc
(
lf
.
f
);
}
if
(
c
==
LUA_SIGNATURE
[
0
]
&&
filename
)
{
/* binary file? */
lf
.
f
=
c_
freopen
(
filename
,
"rb"
,
lf
.
f
);
/* reopen in binary mode */
lf
.
f
=
freopen
(
filename
,
"rb"
,
lf
.
f
);
/* reopen in binary mode */
if
(
lf
.
f
==
NULL
)
return
errfile
(
L
,
"reopen"
,
fnameindex
);
/* skip eventual `#!...' */
while
((
c
=
c_
getc
(
lf
.
f
))
!=
EOF
&&
c
!=
LUA_SIGNATURE
[
0
])
;
while
((
c
=
getc
(
lf
.
f
))
!=
EOF
&&
c
!=
LUA_SIGNATURE
[
0
])
;
lf
.
extraline
=
0
;
}
c_
ungetc
(
c
,
lf
.
f
);
ungetc
(
c
,
lf
.
f
);
status
=
lua_load
(
L
,
getF
,
&
lf
,
lua_tostring
(
L
,
-
1
));
readstatus
=
c_
ferror
(
lf
.
f
);
if
(
filename
)
c_
fclose
(
lf
.
f
);
/* close file (even in case of errors) */
readstatus
=
ferror
(
lf
.
f
);
if
(
filename
)
fclose
(
lf
.
f
);
/* close file (even in case of errors) */
if
(
readstatus
)
{
lua_settop
(
L
,
fnameindex
);
/* ignore results from `lua_load' */
return
errfile
(
L
,
"read"
,
fnameindex
);
...
...
@@ -813,7 +813,7 @@ LUALIB_API void luaL_assertfail(const char *file, int line, const char *message)
static
int
panic
(
lua_State
*
L
)
{
(
void
)
L
;
/* to avoid warnings */
#if defined(LUA_USE_STDIO)
c_
fprintf
(
c_
stderr
,
"PANIC: unprotected error in call to Lua API (%s)
\n
"
,
fprintf
(
stderr
,
"PANIC: unprotected error in call to Lua API (%s)
\n
"
,
lua_tostring
(
L
,
-
1
));
#else
luai_writestringerror
(
"PANIC: unprotected error in call to Lua API (%s)
\n
"
,
...
...
components/lua/lbaselib.c
View file @
991965e2
...
...
@@ -41,8 +41,8 @@ static int luaB_print (lua_State *L) {
return
luaL_error
(
L
,
LUA_QL
(
"tostring"
)
" must return a string to "
LUA_QL
(
"print"
));
#if defined(LUA_USE_STDIO)
if
(
i
>
1
)
c_
fputs
(
"
\t
"
,
c_
stdout
);
c_
fputs
(
s
,
c_
stdout
);
if
(
i
>
1
)
fputs
(
"
\t
"
,
stdout
);
fputs
(
s
,
stdout
);
#else
if
(
i
>
1
)
luai_writestring
(
"
\t
"
,
1
);
luai_writestring
(
s
,
strlen
(
s
));
...
...
@@ -50,7 +50,7 @@ static int luaB_print (lua_State *L) {
lua_pop
(
L
,
1
);
/* pop result */
}
#if defined(LUA_USE_STDIO)
c_
fputs
(
"
\n
"
,
c_
stdout
);
fputs
(
"
\n
"
,
stdout
);
#else
luai_writeline
();
#endif
...
...
components/lua/ldblib.c
View file @
991965e2
...
...
@@ -25,7 +25,7 @@ static int db_getregistry (lua_State *L) {
return
1
;
}
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
#ifndef
CONFIG_
LUA_USE_BUILTIN_DEBUG_MINIMAL
static
int
db_getmetatable
(
lua_State
*
L
)
{
luaL_checkany
(
L
,
1
);
...
...
@@ -85,7 +85,7 @@ static lua_State *getthread (lua_State *L, int *arg) {
return
L
;
}
}
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
#ifndef
CONFIG_
LUA_USE_BUILTIN_DEBUG_MINIMAL
static
void
treatstackoption
(
lua_State
*
L
,
lua_State
*
L1
,
const
char
*
fname
)
{
if
(
L
==
L1
)
{
...
...
@@ -305,8 +305,8 @@ static int db_debug (lua_State *L) {
for
(;;)
{
char
buffer
[
LUA_MAXINPUT
];
#if defined(LUA_USE_STDIO)
c_
fputs
(
"lua_debug> "
,
c_
stderr
);
if
(
c_
fgets
(
buffer
,
sizeof
(
buffer
),
c_
stdin
)
==
0
||
fputs
(
"lua_debug> "
,
stderr
);
if
(
fgets
(
buffer
,
sizeof
(
buffer
),
stdin
)
==
0
||
#else
// luai_writestringerror("%s", "lua_debug>");
if
(
lua_readline
(
L
,
buffer
,
"lua_debug>"
)
==
0
||
...
...
@@ -316,8 +316,8 @@ static int db_debug (lua_State *L) {
if
(
luaL_loadbuffer
(
L
,
buffer
,
strlen
(
buffer
),
"=(debug command)"
)
||
lua_pcall
(
L
,
0
,
0
,
0
))
{
#if defined(LUA_USE_STDIO)
c_
fputs
(
lua_tostring
(
L
,
-
1
),
c_
stderr
);
c_
fputs
(
"
\n
"
,
c_
stderr
);
fputs
(
lua_tostring
(
L
,
-
1
),
stderr
);
fputs
(
"
\n
"
,
stderr
);
#else
luai_writestringerror
(
"%s
\n
"
,
lua_tostring
(
L
,
-
1
));
#endif
...
...
@@ -386,7 +386,7 @@ static int db_errorfb (lua_State *L) {
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const
LUA_REG_TYPE
dblib
[]
=
{
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
#ifndef
CONFIG_
LUA_USE_BUILTIN_DEBUG_MINIMAL
{
LSTRKEY
(
"debug"
),
LFUNCVAL
(
db_debug
)},
{
LSTRKEY
(
"getfenv"
),
LFUNCVAL
(
db_getfenv
)},
{
LSTRKEY
(
"gethook"
),
LFUNCVAL
(
db_gethook
)},
...
...
@@ -394,7 +394,7 @@ const LUA_REG_TYPE dblib[] = {
{
LSTRKEY
(
"getlocal"
),
LFUNCVAL
(
db_getlocal
)},
#endif
{
LSTRKEY
(
"getregistry"
),
LFUNCVAL
(
db_getregistry
)},
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
#ifndef
CONFIG_
LUA_USE_BUILTIN_DEBUG_MINIMAL
{
LSTRKEY
(
"getmetatable"
),
LFUNCVAL
(
db_getmetatable
)},
{
LSTRKEY
(
"getupvalue"
),
LFUNCVAL
(
db_getupvalue
)},
{
LSTRKEY
(
"setfenv"
),
LFUNCVAL
(
db_setfenv
)},
...
...
components/lua/lua.c
View file @
991965e2
...
...
@@ -48,7 +48,7 @@ static void laction (int i) {
static void print_usage (void) {
#if defined(LUA_USE_STDIO)
c_
fprintf(
c_
stderr,
fprintf(stderr,
#else
luai_writestringerror(
#endif
...
...
@@ -64,16 +64,16 @@ static void print_usage (void) {
,
progname
);
#if defined(LUA_USE_STDIO)
c_
fflush
(
c_
stderr
);
fflush
(
stderr
);
#endif
}
#endif
static
void
l_message
(
const
char
*
pname
,
const
char
*
msg
)
{
#if defined(LUA_USE_STDIO)
if
(
pname
)
c_
fprintf
(
c_
stderr
,
"%s: "
,
pname
);
c_
fprintf
(
c_
stderr
,
"%s
\n
"
,
msg
);
c_
fflush
(
c_
stderr
);
if
(
pname
)
fprintf
(
stderr
,
"%s: "
,
pname
);
fprintf
(
stderr
,
"%s
\n
"
,
msg
);
fflush
(
stderr
);
#else
if
(
pname
)
luai_writestringerror
(
"%s: "
,
pname
);
luai_writestringerror
(
"%s
\n
"
,
msg
);
...
...
@@ -260,8 +260,8 @@ static void dotty (lua_State *L) {
lua_settop(L, 0); /* clear stack */
#if defined(LUA_USE_STDIO)
c_
fputs("\n",
c_
stdout);
c_
fflush(
c_
stdout);
fputs("\n", stdout);
fflush(stdout);
#else
luai_writeline();
#endif
...
...
components/modules/Kconfig
View file @
991965e2
menu "NodeMCU modules"
menu "Core Lua modules"
config LUA_BUILTIN_STRING
bool "String module"
default "y"
help
Includes the string module (recommended).
config LUA_BUILTIN_TABLE
bool "Table module"
default "y"
help
Includes the table module (recommended).
config LUA_BUILTIN_COROUTINE
bool "Coroutine module"
default "y"
help
Includes the coroutine module (recommended).
config LUA_BUILTIN_MATH
bool "Math module"
default "y"
help
Includes the math module (recommended).
config LUA_BUILTIN_DEBUG
bool "Debug module"
default "n"
help
Includes the debug module.
config LUA_BUILTIN_DEBUG_EXTENDED
depends on LUA_BUILTIN_DEBUG
bool "Extended debug support
default "n"
help
Includes the full debug module, rather than just getregistry and traceback.
config LUA_BUILTIN_DEBUG_MINIMAL
depends on LUA_BUILTIN_DEBUG
bool
default !LUA_BUILTIN_DEBUG_EXTENDED
endmenu
config LUA_MODULE_NODE
bool "Node module"
default "y"
...
...
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