Actually include standard Lua modules.
This commit is contained in:
parent
3503a1ec95
commit
991965e242
|
@ -15,7 +15,7 @@
|
||||||
#include "lauxlib.h"
|
#include "lauxlib.h"
|
||||||
#include "luaconf.h"
|
#include "luaconf.h"
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
BUILTIN_LIB_INIT( BASE, "", luaopen_base);
|
BUILTIN_LIB_INIT( BASE, "", luaopen_base);
|
||||||
BUILTIN_LIB_INIT( LOADLIB, LUA_LOADLIBNAME, luaopen_package);
|
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);
|
BUILTIN_LIB_INIT( IO, LUA_IOLIBNAME, luaopen_io);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (LUA_USE_BUILTIN_STRING)
|
#if defined (CONFIG_LUA_BUILTIN_STRING)
|
||||||
extern const luaR_entry strlib[];
|
extern const luaR_entry strlib[];
|
||||||
BUILTIN_LIB_INIT( STRING, LUA_STRLIBNAME, luaopen_string);
|
BUILTIN_LIB_INIT( STRING, LUA_STRLIBNAME, luaopen_string);
|
||||||
BUILTIN_LIB( STRING, LUA_STRLIBNAME, strlib);
|
BUILTIN_LIB( STRING, LUA_STRLIBNAME, strlib);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(LUA_USE_BUILTIN_TABLE)
|
#if defined(CONFIG_LUA_BUILTIN_TABLE)
|
||||||
extern const luaR_entry tab_funcs[];
|
extern const luaR_entry tab_funcs[];
|
||||||
BUILTIN_LIB_INIT( TABLE, LUA_TABLIBNAME, luaopen_table);
|
BUILTIN_LIB_INIT( TABLE, LUA_TABLIBNAME, luaopen_table);
|
||||||
BUILTIN_LIB( TABLE, LUA_TABLIBNAME, tab_funcs);
|
BUILTIN_LIB( TABLE, LUA_TABLIBNAME, tab_funcs);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(LUA_USE_BUILTIN_DEBUG) || defined(LUA_USE_BUILTIN_DEBUG_MINIMAL)
|
#if defined(CONFIG_LUA_BUILTIN_DEBUG)
|
||||||
extern const luaR_entry dblib[];
|
extern const luaR_entry dblib[];
|
||||||
BUILTIN_LIB_INIT( DBG, LUA_DBLIBNAME, luaopen_debug);
|
BUILTIN_LIB_INIT( DBG, LUA_DBLIBNAME, luaopen_debug);
|
||||||
BUILTIN_LIB( DBG, LUA_DBLIBNAME, dblib);
|
BUILTIN_LIB( DBG, LUA_DBLIBNAME, dblib);
|
||||||
|
@ -47,12 +47,12 @@ extern const luaR_entry syslib[];
|
||||||
BUILTIN_LIB( OS, LUA_OSLIBNAME, syslib);
|
BUILTIN_LIB( OS, LUA_OSLIBNAME, syslib);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(LUA_USE_BUILTIN_COROUTINE)
|
#if defined(CONFIG_LUA_BUILTIN_COROUTINE)
|
||||||
extern const luaR_entry co_funcs[];
|
extern const luaR_entry co_funcs[];
|
||||||
BUILTIN_LIB( CO, LUA_COLIBNAME, co_funcs);
|
BUILTIN_LIB( CO, LUA_COLIBNAME, co_funcs);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(LUA_USE_BUILTIN_MATH)
|
#if defined(CONFIG_LUA_BUILTIN_MATH)
|
||||||
extern const luaR_entry math_map[];
|
extern const luaR_entry math_map[];
|
||||||
BUILTIN_LIB( MATH, LUA_MATHLIBNAME, math_map);
|
BUILTIN_LIB( MATH, LUA_MATHLIBNAME, math_map);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,4 +4,5 @@ CFLAGS+=\
|
||||||
-DLUA_OPTIMIZE_MEMORY=2 \
|
-DLUA_OPTIMIZE_MEMORY=2 \
|
||||||
-DMIN_OPT_LEVEL=2 \
|
-DMIN_OPT_LEVEL=2 \
|
||||||
-DLUA_OPTIMIZE_DEBUG=$(CONFIG_LUA_OPTIMIZE_DEBUG) \
|
-DLUA_OPTIMIZE_DEBUG=$(CONFIG_LUA_OPTIMIZE_DEBUG) \
|
||||||
|
-DLUA_USE_STDIO \
|
||||||
|
|
||||||
|
|
|
@ -592,14 +592,14 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {
|
||||||
*size = 1;
|
*size = 1;
|
||||||
return "\n";
|
return "\n";
|
||||||
}
|
}
|
||||||
if (c_feof(lf->f)) return NULL;
|
if (feof(lf->f)) return NULL;
|
||||||
*size = c_fread(lf->buff, 1, sizeof(lf->buff), lf->f);
|
*size = fread(lf->buff, 1, sizeof(lf->buff), lf->f);
|
||||||
return (*size > 0) ? lf->buff : NULL;
|
return (*size > 0) ? lf->buff : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int errfile (lua_State *L, const char *what, int fnameindex) {
|
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;
|
const char *filename = lua_tostring(L, fnameindex) + 1;
|
||||||
lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
|
lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
|
||||||
lua_remove(L, fnameindex);
|
lua_remove(L, fnameindex);
|
||||||
|
@ -615,30 +615,30 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
|
||||||
lf.extraline = 0;
|
lf.extraline = 0;
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
lua_pushliteral(L, "=stdin");
|
lua_pushliteral(L, "=stdin");
|
||||||
lf.f = c_stdin;
|
lf.f = stdin;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lua_pushfstring(L, "@%s", filename);
|
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);
|
if (lf.f == NULL) return errfile(L, "open", fnameindex);
|
||||||
}
|
}
|
||||||
c = c_getc(lf.f);
|
c = getc(lf.f);
|
||||||
if (c == '#') { /* Unix exec. file? */
|
if (c == '#') { /* Unix exec. file? */
|
||||||
lf.extraline = 1;
|
lf.extraline = 1;
|
||||||
while ((c = c_getc(lf.f)) != EOF && c != '\n') ; /* skip first line */
|
while ((c = getc(lf.f)) != EOF && c != '\n') ; /* skip first line */
|
||||||
if (c == '\n') c = c_getc(lf.f);
|
if (c == '\n') c = getc(lf.f);
|
||||||
}
|
}
|
||||||
if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */
|
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);
|
if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
|
||||||
/* skip eventual `#!...' */
|
/* 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;
|
lf.extraline = 0;
|
||||||
}
|
}
|
||||||
c_ungetc(c, lf.f);
|
ungetc(c, lf.f);
|
||||||
status = lua_load(L, getF, &lf, lua_tostring(L, -1));
|
status = lua_load(L, getF, &lf, lua_tostring(L, -1));
|
||||||
readstatus = c_ferror(lf.f);
|
readstatus = ferror(lf.f);
|
||||||
if (filename) c_fclose(lf.f); /* close file (even in case of errors) */
|
if (filename) fclose(lf.f); /* close file (even in case of errors) */
|
||||||
if (readstatus) {
|
if (readstatus) {
|
||||||
lua_settop(L, fnameindex); /* ignore results from `lua_load' */
|
lua_settop(L, fnameindex); /* ignore results from `lua_load' */
|
||||||
return errfile(L, "read", fnameindex);
|
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) {
|
static int panic (lua_State *L) {
|
||||||
(void)L; /* to avoid warnings */
|
(void)L; /* to avoid warnings */
|
||||||
#if defined(LUA_USE_STDIO)
|
#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));
|
lua_tostring(L, -1));
|
||||||
#else
|
#else
|
||||||
luai_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
|
luai_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
|
||||||
|
|
|
@ -41,8 +41,8 @@ static int luaB_print (lua_State *L) {
|
||||||
return luaL_error(L, LUA_QL("tostring") " must return a string to "
|
return luaL_error(L, LUA_QL("tostring") " must return a string to "
|
||||||
LUA_QL("print"));
|
LUA_QL("print"));
|
||||||
#if defined(LUA_USE_STDIO)
|
#if defined(LUA_USE_STDIO)
|
||||||
if (i>1) c_fputs("\t", c_stdout);
|
if (i>1) fputs("\t", stdout);
|
||||||
c_fputs(s, c_stdout);
|
fputs(s, stdout);
|
||||||
#else
|
#else
|
||||||
if (i>1) luai_writestring("\t", 1);
|
if (i>1) luai_writestring("\t", 1);
|
||||||
luai_writestring(s, strlen(s));
|
luai_writestring(s, strlen(s));
|
||||||
|
@ -50,7 +50,7 @@ static int luaB_print (lua_State *L) {
|
||||||
lua_pop(L, 1); /* pop result */
|
lua_pop(L, 1); /* pop result */
|
||||||
}
|
}
|
||||||
#if defined(LUA_USE_STDIO)
|
#if defined(LUA_USE_STDIO)
|
||||||
c_fputs("\n", c_stdout);
|
fputs("\n", stdout);
|
||||||
#else
|
#else
|
||||||
luai_writeline();
|
luai_writeline();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,7 +25,7 @@ static int db_getregistry (lua_State *L) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
|
#ifndef CONFIG_LUA_USE_BUILTIN_DEBUG_MINIMAL
|
||||||
|
|
||||||
static int db_getmetatable (lua_State *L) {
|
static int db_getmetatable (lua_State *L) {
|
||||||
luaL_checkany(L, 1);
|
luaL_checkany(L, 1);
|
||||||
|
@ -85,7 +85,7 @@ static lua_State *getthread (lua_State *L, int *arg) {
|
||||||
return L;
|
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) {
|
static void treatstackoption (lua_State *L, lua_State *L1, const char *fname) {
|
||||||
if (L == L1) {
|
if (L == L1) {
|
||||||
|
@ -305,8 +305,8 @@ static int db_debug (lua_State *L) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char buffer[LUA_MAXINPUT];
|
char buffer[LUA_MAXINPUT];
|
||||||
#if defined(LUA_USE_STDIO)
|
#if defined(LUA_USE_STDIO)
|
||||||
c_fputs("lua_debug> ", c_stderr);
|
fputs("lua_debug> ", stderr);
|
||||||
if (c_fgets(buffer, sizeof(buffer), c_stdin) == 0 ||
|
if (fgets(buffer, sizeof(buffer), stdin) == 0 ||
|
||||||
#else
|
#else
|
||||||
// luai_writestringerror("%s", "lua_debug>");
|
// luai_writestringerror("%s", "lua_debug>");
|
||||||
if (lua_readline(L, buffer, "lua_debug>") == 0 ||
|
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)") ||
|
if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
|
||||||
lua_pcall(L, 0, 0, 0)) {
|
lua_pcall(L, 0, 0, 0)) {
|
||||||
#if defined(LUA_USE_STDIO)
|
#if defined(LUA_USE_STDIO)
|
||||||
c_fputs(lua_tostring(L, -1), c_stderr);
|
fputs(lua_tostring(L, -1), stderr);
|
||||||
c_fputs("\n", c_stderr);
|
fputs("\n", stderr);
|
||||||
#else
|
#else
|
||||||
luai_writestringerror("%s\n", lua_tostring(L, -1));
|
luai_writestringerror("%s\n", lua_tostring(L, -1));
|
||||||
#endif
|
#endif
|
||||||
|
@ -386,7 +386,7 @@ static int db_errorfb (lua_State *L) {
|
||||||
#define MIN_OPT_LEVEL 1
|
#define MIN_OPT_LEVEL 1
|
||||||
#include "lrodefs.h"
|
#include "lrodefs.h"
|
||||||
const LUA_REG_TYPE dblib[] = {
|
const LUA_REG_TYPE dblib[] = {
|
||||||
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
|
#ifndef CONFIG_LUA_USE_BUILTIN_DEBUG_MINIMAL
|
||||||
{LSTRKEY("debug"), LFUNCVAL(db_debug)},
|
{LSTRKEY("debug"), LFUNCVAL(db_debug)},
|
||||||
{LSTRKEY("getfenv"), LFUNCVAL(db_getfenv)},
|
{LSTRKEY("getfenv"), LFUNCVAL(db_getfenv)},
|
||||||
{LSTRKEY("gethook"), LFUNCVAL(db_gethook)},
|
{LSTRKEY("gethook"), LFUNCVAL(db_gethook)},
|
||||||
|
@ -394,7 +394,7 @@ const LUA_REG_TYPE dblib[] = {
|
||||||
{LSTRKEY("getlocal"), LFUNCVAL(db_getlocal)},
|
{LSTRKEY("getlocal"), LFUNCVAL(db_getlocal)},
|
||||||
#endif
|
#endif
|
||||||
{LSTRKEY("getregistry"), LFUNCVAL(db_getregistry)},
|
{LSTRKEY("getregistry"), LFUNCVAL(db_getregistry)},
|
||||||
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
|
#ifndef CONFIG_LUA_USE_BUILTIN_DEBUG_MINIMAL
|
||||||
{LSTRKEY("getmetatable"), LFUNCVAL(db_getmetatable)},
|
{LSTRKEY("getmetatable"), LFUNCVAL(db_getmetatable)},
|
||||||
{LSTRKEY("getupvalue"), LFUNCVAL(db_getupvalue)},
|
{LSTRKEY("getupvalue"), LFUNCVAL(db_getupvalue)},
|
||||||
{LSTRKEY("setfenv"), LFUNCVAL(db_setfenv)},
|
{LSTRKEY("setfenv"), LFUNCVAL(db_setfenv)},
|
||||||
|
|
|
@ -48,7 +48,7 @@ static void laction (int i) {
|
||||||
|
|
||||||
static void print_usage (void) {
|
static void print_usage (void) {
|
||||||
#if defined(LUA_USE_STDIO)
|
#if defined(LUA_USE_STDIO)
|
||||||
c_fprintf(c_stderr,
|
fprintf(stderr,
|
||||||
#else
|
#else
|
||||||
luai_writestringerror(
|
luai_writestringerror(
|
||||||
#endif
|
#endif
|
||||||
|
@ -64,16 +64,16 @@ static void print_usage (void) {
|
||||||
,
|
,
|
||||||
progname);
|
progname);
|
||||||
#if defined(LUA_USE_STDIO)
|
#if defined(LUA_USE_STDIO)
|
||||||
c_fflush(c_stderr);
|
fflush(stderr);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
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(stderr, "%s: ", pname);
|
||||||
c_fprintf(c_stderr, "%s\n", msg);
|
fprintf(stderr, "%s\n", msg);
|
||||||
c_fflush(c_stderr);
|
fflush(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);
|
||||||
|
@ -260,8 +260,8 @@ static void dotty (lua_State *L) {
|
||||||
lua_settop(L, 0); /* clear stack */
|
lua_settop(L, 0); /* clear stack */
|
||||||
|
|
||||||
#if defined(LUA_USE_STDIO)
|
#if defined(LUA_USE_STDIO)
|
||||||
c_fputs("\n", c_stdout);
|
fputs("\n", stdout);
|
||||||
c_fflush(c_stdout);
|
fflush(stdout);
|
||||||
#else
|
#else
|
||||||
luai_writeline();
|
luai_writeline();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,51 @@
|
||||||
menu "NodeMCU modules"
|
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
|
config LUA_MODULE_NODE
|
||||||
bool "Node module"
|
bool "Node module"
|
||||||
default "y"
|
default "y"
|
||||||
|
|
Loading…
Reference in New Issue