Commit c04f2578 authored by HuangRui's avatar HuangRui
Browse files

Updated SDK to v0.9.5 and optimized memory.

parent 0420b6d7
...@@ -71,7 +71,7 @@ const luaR_table lua_rotable[] = ...@@ -71,7 +71,7 @@ const luaR_table lua_rotable[] =
{NULL, NULL} {NULL, NULL}
}; };
LUALIB_API void ICACHE_FLASH_ATTR luaL_openlibs (lua_State *L) { LUALIB_API void luaL_openlibs (lua_State *L) {
const luaL_Reg *lib = lualibs; const luaL_Reg *lib = lualibs;
for (; lib->func; lib++) { for (; lib->func; lib++) {
lua_pushcfunction(L, lib->func); lua_pushcfunction(L, lib->func);
......
...@@ -38,7 +38,7 @@ static const int liolib_keys[] = {(int)&luaL_callmeta, (int)&luaL_typerror, (int ...@@ -38,7 +38,7 @@ static const int liolib_keys[] = {(int)&luaL_callmeta, (int)&luaL_typerror, (int
static const char *const fnames[] = {"input", "output"}; static const char *const fnames[] = {"input", "output"};
static int ICACHE_FLASH_ATTR pushresult (lua_State *L, int i, const char *filename) { static int pushresult (lua_State *L, int i, const char *filename) {
int en = fs_error(0); /* calls to Lua API may change this value */ int en = fs_error(0); /* calls to Lua API may change this value */
if (i) { if (i) {
lua_pushboolean(L, 1); lua_pushboolean(L, 1);
...@@ -56,7 +56,7 @@ static int ICACHE_FLASH_ATTR pushresult (lua_State *L, int i, const char *filena ...@@ -56,7 +56,7 @@ static int ICACHE_FLASH_ATTR pushresult (lua_State *L, int i, const char *filena
} }
static void ICACHE_FLASH_ATTR fileerror (lua_State *L, int arg, const char *filename) { static void fileerror (lua_State *L, int arg, const char *filename) {
lua_pushfstring(L, "%s: err(%d)", filename, fs_error(0)); lua_pushfstring(L, "%s: err(%d)", filename, fs_error(0));
luaL_argerror(L, arg, lua_tostring(L, -1)); luaL_argerror(L, arg, lua_tostring(L, -1));
} }
...@@ -65,7 +65,7 @@ static void ICACHE_FLASH_ATTR fileerror (lua_State *L, int arg, const char *file ...@@ -65,7 +65,7 @@ static void ICACHE_FLASH_ATTR fileerror (lua_State *L, int arg, const char *file
#define tofilep(L) ((int *)luaL_checkudata(L, 1, LUA_FILEHANDLE)) #define tofilep(L) ((int *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
static int ICACHE_FLASH_ATTR io_type (lua_State *L) { static int io_type (lua_State *L) {
void *ud; void *ud;
luaL_checkany(L, 1); luaL_checkany(L, 1);
ud = lua_touserdata(L, 1); ud = lua_touserdata(L, 1);
...@@ -80,7 +80,7 @@ static int ICACHE_FLASH_ATTR io_type (lua_State *L) { ...@@ -80,7 +80,7 @@ static int ICACHE_FLASH_ATTR io_type (lua_State *L) {
} }
static int ICACHE_FLASH_ATTR tofile (lua_State *L) { static int tofile (lua_State *L) {
int *f = tofilep(L); int *f = tofilep(L);
if (*f < FS_OPEN_OK) if (*f < FS_OPEN_OK)
luaL_error(L, "attempt to use a closed file"); luaL_error(L, "attempt to use a closed file");
...@@ -94,7 +94,7 @@ static int ICACHE_FLASH_ATTR tofile (lua_State *L) { ...@@ -94,7 +94,7 @@ static int ICACHE_FLASH_ATTR tofile (lua_State *L) {
** before opening the actual file; so, if there is a memory error, the ** before opening the actual file; so, if there is a memory error, the
** file is not left opened. ** file is not left opened.
*/ */
static int *ICACHE_FLASH_ATTR newfile (lua_State *L) { static int *newfile (lua_State *L) {
int *pf = (int *)lua_newuserdata(L, sizeof(int)); int *pf = (int *)lua_newuserdata(L, sizeof(int));
*pf = FS_OPEN_OK - 1; /* file handle is currently `closed' */ *pf = FS_OPEN_OK - 1; /* file handle is currently `closed' */
luaL_getmetatable(L, LUA_FILEHANDLE); luaL_getmetatable(L, LUA_FILEHANDLE);
...@@ -107,7 +107,7 @@ static int *ICACHE_FLASH_ATTR newfile (lua_State *L) { ...@@ -107,7 +107,7 @@ static int *ICACHE_FLASH_ATTR newfile (lua_State *L) {
/* /*
** function to (not) close the standard files stdin, stdout, and stderr ** function to (not) close the standard files stdin, stdout, and stderr
*/ */
static int ICACHE_FLASH_ATTR io_noclose (lua_State *L) { static int io_noclose (lua_State *L) {
lua_pushnil(L); lua_pushnil(L);
lua_pushliteral(L, "cannot close standard file"); lua_pushliteral(L, "cannot close standard file");
return 2; return 2;
...@@ -117,7 +117,7 @@ static int ICACHE_FLASH_ATTR io_noclose (lua_State *L) { ...@@ -117,7 +117,7 @@ static int ICACHE_FLASH_ATTR io_noclose (lua_State *L) {
/* /*
** function to close 'popen' files ** function to close 'popen' files
*/ */
static int ICACHE_FLASH_ATTR io_pclose (lua_State *L) { static int io_pclose (lua_State *L) {
int *p = tofilep(L); int *p = tofilep(L);
int ok = lua_pclose(L, *p); int ok = lua_pclose(L, *p);
*p = FS_OPEN_OK - 1; *p = FS_OPEN_OK - 1;
...@@ -128,7 +128,7 @@ static int ICACHE_FLASH_ATTR io_pclose (lua_State *L) { ...@@ -128,7 +128,7 @@ static int ICACHE_FLASH_ATTR io_pclose (lua_State *L) {
/* /*
** function to close regular files ** function to close regular files
*/ */
static int ICACHE_FLASH_ATTR io_fclose (lua_State *L) { static int io_fclose (lua_State *L) {
int *p = tofilep(L); int *p = tofilep(L);
int ok = (fs_close(*p) == 0); int ok = (fs_close(*p) == 0);
*p = FS_OPEN_OK - 1; *p = FS_OPEN_OK - 1;
...@@ -136,7 +136,7 @@ static int ICACHE_FLASH_ATTR io_fclose (lua_State *L) { ...@@ -136,7 +136,7 @@ static int ICACHE_FLASH_ATTR io_fclose (lua_State *L) {
} }
#endif #endif
static int ICACHE_FLASH_ATTR aux_close (lua_State *L) { static int aux_close (lua_State *L) {
#if LUA_OPTIMIZE_MEMORY != 2 #if LUA_OPTIMIZE_MEMORY != 2
lua_getfenv(L, 1); lua_getfenv(L, 1);
lua_getfield(L, -1, "__close"); lua_getfield(L, -1, "__close");
...@@ -156,7 +156,7 @@ static int ICACHE_FLASH_ATTR aux_close (lua_State *L) { ...@@ -156,7 +156,7 @@ static int ICACHE_FLASH_ATTR aux_close (lua_State *L) {
} }
static int ICACHE_FLASH_ATTR io_close (lua_State *L) { static int io_close (lua_State *L) {
if (lua_isnone(L, 1)) if (lua_isnone(L, 1))
LUA_IO_GETFIELD(IO_OUTPUT); LUA_IO_GETFIELD(IO_OUTPUT);
tofile(L); /* make sure argument is a file */ tofile(L); /* make sure argument is a file */
...@@ -164,7 +164,7 @@ static int ICACHE_FLASH_ATTR io_close (lua_State *L) { ...@@ -164,7 +164,7 @@ static int ICACHE_FLASH_ATTR io_close (lua_State *L) {
} }
static int ICACHE_FLASH_ATTR io_gc (lua_State *L) { static int io_gc (lua_State *L) {
int f = *tofilep(L); int f = *tofilep(L);
/* ignore closed files */ /* ignore closed files */
if (f != FS_OPEN_OK - 1) if (f != FS_OPEN_OK - 1)
...@@ -173,7 +173,7 @@ static int ICACHE_FLASH_ATTR io_gc (lua_State *L) { ...@@ -173,7 +173,7 @@ static int ICACHE_FLASH_ATTR io_gc (lua_State *L) {
} }
static int ICACHE_FLASH_ATTR io_tostring (lua_State *L) { static int io_tostring (lua_State *L) {
int f = *tofilep(L); int f = *tofilep(L);
if (f == FS_OPEN_OK - 1) if (f == FS_OPEN_OK - 1)
lua_pushliteral(L, "file (closed)"); lua_pushliteral(L, "file (closed)");
...@@ -183,7 +183,7 @@ static int ICACHE_FLASH_ATTR io_tostring (lua_State *L) { ...@@ -183,7 +183,7 @@ static int ICACHE_FLASH_ATTR io_tostring (lua_State *L) {
} }
static int ICACHE_FLASH_ATTR io_open (lua_State *L) { static int io_open (lua_State *L) {
const char *filename = luaL_checkstring(L, 1); const char *filename = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r"); const char *mode = luaL_optstring(L, 2, "r");
int *pf = newfile(L); int *pf = newfile(L);
...@@ -197,7 +197,7 @@ static int ICACHE_FLASH_ATTR io_open (lua_State *L) { ...@@ -197,7 +197,7 @@ static int ICACHE_FLASH_ATTR io_open (lua_State *L) {
** correct __close for 'popen' files ** correct __close for 'popen' files
*/ */
#if 0 #if 0
static int ICACHE_FLASH_ATTR io_popen (lua_State *L) { static int io_popen (lua_State *L) {
const char *filename = luaL_checkstring(L, 1); const char *filename = luaL_checkstring(L, 1);
const char *mode = luaL_optstring(L, 2, "r"); const char *mode = luaL_optstring(L, 2, "r");
int *pf = newfile(L); int *pf = newfile(L);
...@@ -206,14 +206,14 @@ static int ICACHE_FLASH_ATTR io_popen (lua_State *L) { ...@@ -206,14 +206,14 @@ static int ICACHE_FLASH_ATTR io_popen (lua_State *L) {
} }
static int ICACHE_FLASH_ATTR io_tmpfile (lua_State *L) { static int io_tmpfile (lua_State *L) {
int *pf = newfile(L); int *pf = newfile(L);
*pf = tmpfile(); *pf = tmpfile();
return (*pf == FS_OPEN_OK - 1) ? pushresult(L, 0, NULL) : 1; return (*pf == FS_OPEN_OK - 1) ? pushresult(L, 0, NULL) : 1;
} }
#endif #endif
static int ICACHE_FLASH_ATTR getiofile (lua_State *L, int findex) { static int getiofile (lua_State *L, int findex) {
int *pf; int *pf;
LUA_IO_GETFIELD(findex); LUA_IO_GETFIELD(findex);
pf = (int *)lua_touserdata(L, -1); pf = (int *)lua_touserdata(L, -1);
...@@ -225,7 +225,7 @@ static int ICACHE_FLASH_ATTR getiofile (lua_State *L, int findex) { ...@@ -225,7 +225,7 @@ static int ICACHE_FLASH_ATTR getiofile (lua_State *L, int findex) {
} }
static int ICACHE_FLASH_ATTR g_iofile (lua_State *L, int f, const char *mode) { static int g_iofile (lua_State *L, int f, const char *mode) {
if (!lua_isnoneornil(L, 1)) { if (!lua_isnoneornil(L, 1)) {
const char *filename = lua_tostring(L, 1); const char *filename = lua_tostring(L, 1);
if (filename) { if (filename) {
...@@ -246,34 +246,34 @@ static int ICACHE_FLASH_ATTR g_iofile (lua_State *L, int f, const char *mode) { ...@@ -246,34 +246,34 @@ static int ICACHE_FLASH_ATTR g_iofile (lua_State *L, int f, const char *mode) {
} }
static int ICACHE_FLASH_ATTR io_input (lua_State *L) { static int io_input (lua_State *L) {
return g_iofile(L, IO_INPUT, "r"); return g_iofile(L, IO_INPUT, "r");
} }
static int ICACHE_FLASH_ATTR io_output (lua_State *L) { static int io_output (lua_State *L) {
return g_iofile(L, IO_OUTPUT, "w"); return g_iofile(L, IO_OUTPUT, "w");
} }
static int ICACHE_FLASH_ATTR io_readline (lua_State *L); static int io_readline (lua_State *L);
static void ICACHE_FLASH_ATTR aux_lines (lua_State *L, int idx, int toclose) { static void aux_lines (lua_State *L, int idx, int toclose) {
lua_pushvalue(L, idx); lua_pushvalue(L, idx);
lua_pushboolean(L, toclose); /* close/not close file when finished */ lua_pushboolean(L, toclose); /* close/not close file when finished */
lua_pushcclosure(L, io_readline, 2); lua_pushcclosure(L, io_readline, 2);
} }
static int ICACHE_FLASH_ATTR f_lines (lua_State *L) { static int f_lines (lua_State *L) {
tofile(L); /* check that it's a valid file handle */ tofile(L); /* check that it's a valid file handle */
aux_lines(L, 1, 0); aux_lines(L, 1, 0);
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR io_lines (lua_State *L) { static int io_lines (lua_State *L) {
if (lua_isnoneornil(L, 1)) { /* no arguments? */ if (lua_isnoneornil(L, 1)) { /* no arguments? */
/* will iterate over default input */ /* will iterate over default input */
LUA_IO_GETFIELD(IO_INPUT); LUA_IO_GETFIELD(IO_INPUT);
...@@ -298,7 +298,7 @@ static int ICACHE_FLASH_ATTR io_lines (lua_State *L) { ...@@ -298,7 +298,7 @@ static int ICACHE_FLASH_ATTR io_lines (lua_State *L) {
*/ */
#if 0 #if 0
static int ICACHE_FLASH_ATTR read_number (lua_State *L, int f) { static int read_number (lua_State *L, int f) {
lua_Number d; lua_Number d;
if (fs_scanf(f, LUA_NUMBER_SCAN, &d) == 1) { if (fs_scanf(f, LUA_NUMBER_SCAN, &d) == 1) {
lua_pushnumber(L, d); lua_pushnumber(L, d);
...@@ -311,7 +311,7 @@ static int ICACHE_FLASH_ATTR read_number (lua_State *L, int f) { ...@@ -311,7 +311,7 @@ static int ICACHE_FLASH_ATTR read_number (lua_State *L, int f) {
} }
#endif #endif
static int ICACHE_FLASH_ATTR test_eof (lua_State *L, int f) { static int test_eof (lua_State *L, int f) {
int c = fs_getc(f); int c = fs_getc(f);
fs_ungetc(c, f); fs_ungetc(c, f);
lua_pushlstring(L, NULL, 0); lua_pushlstring(L, NULL, 0);
...@@ -319,7 +319,7 @@ static int ICACHE_FLASH_ATTR test_eof (lua_State *L, int f) { ...@@ -319,7 +319,7 @@ static int ICACHE_FLASH_ATTR test_eof (lua_State *L, int f) {
} }
#if 0 #if 0
static int ICACHE_FLASH_ATTR read_line (lua_State *L, int f) { static int read_line (lua_State *L, int f) {
luaL_Buffer b; luaL_Buffer b;
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
for (;;) { for (;;) {
...@@ -340,7 +340,7 @@ static int ICACHE_FLASH_ATTR read_line (lua_State *L, int f) { ...@@ -340,7 +340,7 @@ static int ICACHE_FLASH_ATTR read_line (lua_State *L, int f) {
} }
} }
#else #else
static int ICACHE_FLASH_ATTR read_line (lua_State *L, int f) { static int read_line (lua_State *L, int f) {
luaL_Buffer b; luaL_Buffer b;
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
char *p = luaL_prepbuffer(&b); char *p = luaL_prepbuffer(&b);
...@@ -368,7 +368,7 @@ static int ICACHE_FLASH_ATTR read_line (lua_State *L, int f) { ...@@ -368,7 +368,7 @@ static int ICACHE_FLASH_ATTR read_line (lua_State *L, int f) {
} }
#endif #endif
static int ICACHE_FLASH_ATTR read_chars (lua_State *L, int f, size_t n) { static int read_chars (lua_State *L, int f, size_t n) {
size_t rlen; /* how much to read */ size_t rlen; /* how much to read */
size_t nr; /* number of chars actually read */ size_t nr; /* number of chars actually read */
luaL_Buffer b; luaL_Buffer b;
...@@ -386,7 +386,7 @@ static int ICACHE_FLASH_ATTR read_chars (lua_State *L, int f, size_t n) { ...@@ -386,7 +386,7 @@ static int ICACHE_FLASH_ATTR read_chars (lua_State *L, int f, size_t n) {
} }
static int ICACHE_FLASH_ATTR g_read (lua_State *L, int f, int first) { static int g_read (lua_State *L, int f, int first) {
int nargs = lua_gettop(L) - 1; int nargs = lua_gettop(L) - 1;
int success; int success;
int n; int n;
...@@ -435,17 +435,17 @@ static int ICACHE_FLASH_ATTR g_read (lua_State *L, int f, int first) { ...@@ -435,17 +435,17 @@ static int ICACHE_FLASH_ATTR g_read (lua_State *L, int f, int first) {
} }
static int ICACHE_FLASH_ATTR io_read (lua_State *L) { static int io_read (lua_State *L) {
return g_read(L, getiofile(L, IO_INPUT), 1); return g_read(L, getiofile(L, IO_INPUT), 1);
} }
static int ICACHE_FLASH_ATTR f_read (lua_State *L) { static int f_read (lua_State *L) {
return g_read(L, tofile(L), 2); return g_read(L, tofile(L), 2);
} }
static int ICACHE_FLASH_ATTR io_readline (lua_State *L) { static int io_readline (lua_State *L) {
int *pf = (int *)lua_touserdata(L, lua_upvalueindex(1)); int *pf = (int *)lua_touserdata(L, lua_upvalueindex(1));
int sucess; int sucess;
if (pf == NULL || *pf == FS_OPEN_OK - 1){ /* file is already closed? */ if (pf == NULL || *pf == FS_OPEN_OK - 1){ /* file is already closed? */
...@@ -469,7 +469,7 @@ static int ICACHE_FLASH_ATTR io_readline (lua_State *L) { ...@@ -469,7 +469,7 @@ static int ICACHE_FLASH_ATTR io_readline (lua_State *L) {
/* }====================================================== */ /* }====================================================== */
static int ICACHE_FLASH_ATTR g_write (lua_State *L, int f, int arg) { static int g_write (lua_State *L, int f, int arg) {
int nargs = lua_gettop(L) - 1; int nargs = lua_gettop(L) - 1;
int status = 1; int status = 1;
for (; nargs--; arg++) { for (; nargs--; arg++) {
...@@ -491,17 +491,17 @@ static int ICACHE_FLASH_ATTR g_write (lua_State *L, int f, int arg) { ...@@ -491,17 +491,17 @@ static int ICACHE_FLASH_ATTR g_write (lua_State *L, int f, int arg) {
} }
static int ICACHE_FLASH_ATTR io_write (lua_State *L) { static int io_write (lua_State *L) {
return g_write(L, getiofile(L, IO_OUTPUT), 1); return g_write(L, getiofile(L, IO_OUTPUT), 1);
} }
static int ICACHE_FLASH_ATTR f_write (lua_State *L) { static int f_write (lua_State *L) {
return g_write(L, tofile(L), 2); return g_write(L, tofile(L), 2);
} }
static int ICACHE_FLASH_ATTR f_seek (lua_State *L) { static int f_seek (lua_State *L) {
static const int mode[] = {FS_SEEK_SET, FS_SEEK_CUR, FS_SEEK_END}; static const int mode[] = {FS_SEEK_SET, FS_SEEK_CUR, FS_SEEK_END};
static const char *const modenames[] = {"set", "cur", "end", NULL}; static const char *const modenames[] = {"set", "cur", "end", NULL};
int f = tofile(L); int f = tofile(L);
...@@ -517,7 +517,7 @@ static int ICACHE_FLASH_ATTR f_seek (lua_State *L) { ...@@ -517,7 +517,7 @@ static int ICACHE_FLASH_ATTR f_seek (lua_State *L) {
} }
#if 0 #if 0
static int ICACHE_FLASH_ATTR f_setvbuf (lua_State *L) { static int f_setvbuf (lua_State *L) {
static const int mode[] = {_IONBF, _IOFBF, _IOLBF}; static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
static const char *const modenames[] = {"no", "full", "line", NULL}; static const char *const modenames[] = {"no", "full", "line", NULL};
int f = tofile(L); int f = tofile(L);
...@@ -529,12 +529,12 @@ static int ICACHE_FLASH_ATTR f_setvbuf (lua_State *L) { ...@@ -529,12 +529,12 @@ static int ICACHE_FLASH_ATTR f_setvbuf (lua_State *L) {
#endif #endif
static int ICACHE_FLASH_ATTR io_flush (lua_State *L) { static int io_flush (lua_State *L) {
return pushresult(L, fs_flush(getiofile(L, IO_OUTPUT)) == 0, NULL); return pushresult(L, fs_flush(getiofile(L, IO_OUTPUT)) == 0, NULL);
} }
static int ICACHE_FLASH_ATTR f_flush (lua_State *L) { static int f_flush (lua_State *L) {
return pushresult(L, fs_flush(tofile(L)) == 0, NULL); return pushresult(L, fs_flush(tofile(L)) == 0, NULL);
} }
...@@ -560,7 +560,7 @@ const LUA_REG_TYPE iolib[] = { ...@@ -560,7 +560,7 @@ const LUA_REG_TYPE iolib[] = {
}; };
#if LUA_OPTIMIZE_MEMORY == 2 #if LUA_OPTIMIZE_MEMORY == 2
static int ICACHE_FLASH_ATTR luaL_index(lua_State *L) static int luaL_index(lua_State *L)
{ {
return luaR_findfunction(L, iolib_funcs); return luaR_findfunction(L, iolib_funcs);
} }
...@@ -590,7 +590,7 @@ const LUA_REG_TYPE flib[] = { ...@@ -590,7 +590,7 @@ const LUA_REG_TYPE flib[] = {
{LNILKEY, LNILVAL} {LNILKEY, LNILVAL}
}; };
static void ICACHE_FLASH_ATTR createmeta (lua_State *L) { static void createmeta (lua_State *L) {
#if LUA_OPTIMIZE_MEMORY == 0 #if LUA_OPTIMIZE_MEMORY == 0
luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */ luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
lua_pushvalue(L, -1); /* push metatable */ lua_pushvalue(L, -1); /* push metatable */
...@@ -602,7 +602,7 @@ static void ICACHE_FLASH_ATTR createmeta (lua_State *L) { ...@@ -602,7 +602,7 @@ static void ICACHE_FLASH_ATTR createmeta (lua_State *L) {
} }
static void ICACHE_FLASH_ATTR createstdfile (lua_State *L, int f, int k, const char *fname) { static void createstdfile (lua_State *L, int f, int k, const char *fname) {
*newfile(L) = f; *newfile(L) = f;
#if LUA_OPTIMIZE_MEMORY != 2 #if LUA_OPTIMIZE_MEMORY != 2
if (k > 0) { if (k > 0) {
...@@ -620,14 +620,14 @@ static void ICACHE_FLASH_ATTR createstdfile (lua_State *L, int f, int k, const c ...@@ -620,14 +620,14 @@ static void ICACHE_FLASH_ATTR createstdfile (lua_State *L, int f, int k, const c
} }
#if LUA_OPTIMIZE_MEMORY != 2 #if LUA_OPTIMIZE_MEMORY != 2
static void ICACHE_FLASH_ATTR newfenv (lua_State *L, lua_CFunction cls) { static void newfenv (lua_State *L, lua_CFunction cls) {
lua_createtable(L, 0, 1); lua_createtable(L, 0, 1);
lua_pushcfunction(L, cls); lua_pushcfunction(L, cls);
lua_setfield(L, -2, "__close"); lua_setfield(L, -2, "__close");
} }
#endif #endif
LUALIB_API int ICACHE_FLASH_ATTR luaopen_io (lua_State *L) { LUALIB_API int luaopen_io (lua_State *L) {
createmeta(L); createmeta(L);
#if LUA_OPTIMIZE_MEMORY != 2 #if LUA_OPTIMIZE_MEMORY != 2
/* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */ /* create (private) environment (with fields IO_INPUT, IO_OUTPUT, __close) */
......
...@@ -48,7 +48,7 @@ const char *const luaX_tokens [] = { ...@@ -48,7 +48,7 @@ const char *const luaX_tokens [] = {
#define save_and_next(ls) (save(ls, ls->current), next(ls)) #define save_and_next(ls) (save(ls, ls->current), next(ls))
static void ICACHE_FLASH_ATTR save (LexState *ls, int c) { static void save (LexState *ls, int c) {
Mbuffer *b = ls->buff; Mbuffer *b = ls->buff;
if (b->n + 1 > b->buffsize) { if (b->n + 1 > b->buffsize) {
size_t newsize; size_t newsize;
...@@ -61,14 +61,14 @@ static void ICACHE_FLASH_ATTR save (LexState *ls, int c) { ...@@ -61,14 +61,14 @@ static void ICACHE_FLASH_ATTR save (LexState *ls, int c) {
} }
void ICACHE_FLASH_ATTR luaX_init (lua_State *L) { void luaX_init (lua_State *L) {
} }
#define MAXSRC 80 #define MAXSRC 80
const char *ICACHE_FLASH_ATTR luaX_token2str (LexState *ls, int token) { const char *luaX_token2str (LexState *ls, int token) {
if (token < FIRST_RESERVED) { if (token < FIRST_RESERVED) {
lua_assert(token == cast(unsigned char, token)); lua_assert(token == cast(unsigned char, token));
return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) : return (iscntrl(token)) ? luaO_pushfstring(ls->L, "char(%d)", token) :
...@@ -79,7 +79,7 @@ const char *ICACHE_FLASH_ATTR luaX_token2str (LexState *ls, int token) { ...@@ -79,7 +79,7 @@ const char *ICACHE_FLASH_ATTR luaX_token2str (LexState *ls, int token) {
} }
static const char *ICACHE_FLASH_ATTR txtToken (LexState *ls, int token) { static const char *txtToken (LexState *ls, int token) {
switch (token) { switch (token) {
case TK_NAME: case TK_NAME:
case TK_STRING: case TK_STRING:
...@@ -92,7 +92,7 @@ static const char *ICACHE_FLASH_ATTR txtToken (LexState *ls, int token) { ...@@ -92,7 +92,7 @@ static const char *ICACHE_FLASH_ATTR txtToken (LexState *ls, int token) {
} }
void ICACHE_FLASH_ATTR luaX_lexerror (LexState *ls, const char *msg, int token) { void luaX_lexerror (LexState *ls, const char *msg, int token) {
char buff[MAXSRC]; char buff[MAXSRC];
luaO_chunkid(buff, getstr(ls->source), MAXSRC); luaO_chunkid(buff, getstr(ls->source), MAXSRC);
msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg); msg = luaO_pushfstring(ls->L, "%s:%d: %s", buff, ls->linenumber, msg);
...@@ -102,12 +102,12 @@ void ICACHE_FLASH_ATTR luaX_lexerror (LexState *ls, const char *msg, int token) ...@@ -102,12 +102,12 @@ void ICACHE_FLASH_ATTR luaX_lexerror (LexState *ls, const char *msg, int token)
} }
void ICACHE_FLASH_ATTR luaX_syntaxerror (LexState *ls, const char *msg) { void luaX_syntaxerror (LexState *ls, const char *msg) {
luaX_lexerror(ls, msg, ls->t.token); luaX_lexerror(ls, msg, ls->t.token);
} }
TString *ICACHE_FLASH_ATTR luaX_newstring (LexState *ls, const char *str, size_t l) { TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
lua_State *L = ls->L; lua_State *L = ls->L;
TString *ts = luaS_newlstr(L, str, l); TString *ts = luaS_newlstr(L, str, l);
TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */ TValue *o = luaH_setstr(L, ls->fs->h, ts); /* entry for `str' */
...@@ -119,7 +119,7 @@ TString *ICACHE_FLASH_ATTR luaX_newstring (LexState *ls, const char *str, size_t ...@@ -119,7 +119,7 @@ TString *ICACHE_FLASH_ATTR luaX_newstring (LexState *ls, const char *str, size_t
} }
static void ICACHE_FLASH_ATTR inclinenumber (LexState *ls) { static void inclinenumber (LexState *ls) {
int old = ls->current; int old = ls->current;
lua_assert(currIsNewline(ls)); lua_assert(currIsNewline(ls));
next(ls); /* skip `\n' or `\r' */ next(ls); /* skip `\n' or `\r' */
...@@ -130,7 +130,7 @@ static void ICACHE_FLASH_ATTR inclinenumber (LexState *ls) { ...@@ -130,7 +130,7 @@ static void ICACHE_FLASH_ATTR inclinenumber (LexState *ls) {
} }
void ICACHE_FLASH_ATTR luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
ls->decpoint = '.'; ls->decpoint = '.';
ls->L = L; ls->L = L;
ls->lookahead.token = TK_EOS; /* no look-ahead token */ ls->lookahead.token = TK_EOS; /* no look-ahead token */
...@@ -153,7 +153,7 @@ void ICACHE_FLASH_ATTR luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TStrin ...@@ -153,7 +153,7 @@ void ICACHE_FLASH_ATTR luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TStrin
static int ICACHE_FLASH_ATTR check_next (LexState *ls, const char *set) { static int check_next (LexState *ls, const char *set) {
if (!c_strchr(set, ls->current)) if (!c_strchr(set, ls->current))
return 0; return 0;
save_and_next(ls); save_and_next(ls);
...@@ -161,7 +161,7 @@ static int ICACHE_FLASH_ATTR check_next (LexState *ls, const char *set) { ...@@ -161,7 +161,7 @@ static int ICACHE_FLASH_ATTR check_next (LexState *ls, const char *set) {
} }
static void ICACHE_FLASH_ATTR buffreplace (LexState *ls, char from, char to) { static void buffreplace (LexState *ls, char from, char to) {
size_t n = luaZ_bufflen(ls->buff); size_t n = luaZ_bufflen(ls->buff);
char *p = luaZ_buffer(ls->buff); char *p = luaZ_buffer(ls->buff);
while (n--) while (n--)
...@@ -169,7 +169,7 @@ static void ICACHE_FLASH_ATTR buffreplace (LexState *ls, char from, char to) { ...@@ -169,7 +169,7 @@ static void ICACHE_FLASH_ATTR buffreplace (LexState *ls, char from, char to) {
} }
static void ICACHE_FLASH_ATTR trydecpoint (LexState *ls, SemInfo *seminfo) { static void trydecpoint (LexState *ls, SemInfo *seminfo) {
/* format error: try to update decimal point separator */ /* format error: try to update decimal point separator */
struct lconv *cv = localeconv(); struct lconv *cv = localeconv();
char old = ls->decpoint; char old = ls->decpoint;
...@@ -184,7 +184,7 @@ static void ICACHE_FLASH_ATTR trydecpoint (LexState *ls, SemInfo *seminfo) { ...@@ -184,7 +184,7 @@ static void ICACHE_FLASH_ATTR trydecpoint (LexState *ls, SemInfo *seminfo) {
/* LUA_NUMBER */ /* LUA_NUMBER */
static void ICACHE_FLASH_ATTR read_numeral (LexState *ls, SemInfo *seminfo) { static void read_numeral (LexState *ls, SemInfo *seminfo) {
lua_assert(isdigit(ls->current)); lua_assert(isdigit(ls->current));
do { do {
save_and_next(ls); save_and_next(ls);
...@@ -200,7 +200,7 @@ static void ICACHE_FLASH_ATTR read_numeral (LexState *ls, SemInfo *seminfo) { ...@@ -200,7 +200,7 @@ static void ICACHE_FLASH_ATTR read_numeral (LexState *ls, SemInfo *seminfo) {
} }
static int ICACHE_FLASH_ATTR skip_sep (LexState *ls) { static int skip_sep (LexState *ls) {
int count = 0; int count = 0;
int s = ls->current; int s = ls->current;
lua_assert(s == '[' || s == ']'); lua_assert(s == '[' || s == ']');
...@@ -213,7 +213,7 @@ static int ICACHE_FLASH_ATTR skip_sep (LexState *ls) { ...@@ -213,7 +213,7 @@ static int ICACHE_FLASH_ATTR skip_sep (LexState *ls) {
} }
static void ICACHE_FLASH_ATTR read_long_string (LexState *ls, SemInfo *seminfo, int sep) { static void read_long_string (LexState *ls, SemInfo *seminfo, int sep) {
int cont = 0; int cont = 0;
(void)(cont); /* avoid warnings when `cont' is not used */ (void)(cont); /* avoid warnings when `cont' is not used */
save_and_next(ls); /* skip 2nd `[' */ save_and_next(ls); /* skip 2nd `[' */
...@@ -268,7 +268,7 @@ static void ICACHE_FLASH_ATTR read_long_string (LexState *ls, SemInfo *seminfo, ...@@ -268,7 +268,7 @@ static void ICACHE_FLASH_ATTR read_long_string (LexState *ls, SemInfo *seminfo,
} }
static void ICACHE_FLASH_ATTR read_string (LexState *ls, int del, SemInfo *seminfo) { static void read_string (LexState *ls, int del, SemInfo *seminfo) {
save_and_next(ls); save_and_next(ls);
while (ls->current != del) { while (ls->current != del) {
switch (ls->current) { switch (ls->current) {
...@@ -324,7 +324,7 @@ static void ICACHE_FLASH_ATTR read_string (LexState *ls, int del, SemInfo *semin ...@@ -324,7 +324,7 @@ static void ICACHE_FLASH_ATTR read_string (LexState *ls, int del, SemInfo *semin
} }
static int ICACHE_FLASH_ATTR llex (LexState *ls, SemInfo *seminfo) { static int llex (LexState *ls, SemInfo *seminfo) {
luaZ_resetbuffer(ls->buff); luaZ_resetbuffer(ls->buff);
for (;;) { for (;;) {
switch (ls->current) { switch (ls->current) {
...@@ -440,7 +440,7 @@ static int ICACHE_FLASH_ATTR llex (LexState *ls, SemInfo *seminfo) { ...@@ -440,7 +440,7 @@ static int ICACHE_FLASH_ATTR llex (LexState *ls, SemInfo *seminfo) {
} }
void ICACHE_FLASH_ATTR luaX_next (LexState *ls) { void luaX_next (LexState *ls) {
ls->lastline = ls->linenumber; ls->lastline = ls->linenumber;
if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */ if (ls->lookahead.token != TK_EOS) { /* is there a look-ahead token? */
ls->t = ls->lookahead; /* use this one */ ls->t = ls->lookahead; /* use this one */
...@@ -451,7 +451,7 @@ void ICACHE_FLASH_ATTR luaX_next (LexState *ls) { ...@@ -451,7 +451,7 @@ void ICACHE_FLASH_ATTR luaX_next (LexState *ls) {
} }
void ICACHE_FLASH_ATTR luaX_lookahead (LexState *ls) { void luaX_lookahead (LexState *ls) {
lua_assert(ls->lookahead.token == TK_EOS); lua_assert(ls->lookahead.token == TK_EOS);
ls->lookahead.token = llex(ls, &ls->lookahead.seminfo); ls->lookahead.token = llex(ls, &ls->lookahead.seminfo);
} }
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
static int ICACHE_FLASH_ATTR math_abs (lua_State *L) { static int math_abs (lua_State *L) {
#ifdef LUA_NUMBER_INTEGRAL #ifdef LUA_NUMBER_INTEGRAL
lua_Number x = luaL_checknumber(L, 1); lua_Number x = luaL_checknumber(L, 1);
if (x < 0) x = -x; //fails for -2^31 if (x < 0) x = -x; //fails for -2^31
...@@ -36,72 +36,72 @@ static int ICACHE_FLASH_ATTR math_abs (lua_State *L) { ...@@ -36,72 +36,72 @@ static int ICACHE_FLASH_ATTR math_abs (lua_State *L) {
#ifndef LUA_NUMBER_INTEGRAL #ifndef LUA_NUMBER_INTEGRAL
static int ICACHE_FLASH_ATTR math_sin (lua_State *L) { static int math_sin (lua_State *L) {
lua_pushnumber(L, sin(luaL_checknumber(L, 1))); lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_sinh (lua_State *L) { static int math_sinh (lua_State *L) {
lua_pushnumber(L, sinh(luaL_checknumber(L, 1))); lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_cos (lua_State *L) { static int math_cos (lua_State *L) {
lua_pushnumber(L, cos(luaL_checknumber(L, 1))); lua_pushnumber(L, cos(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_cosh (lua_State *L) { static int math_cosh (lua_State *L) {
lua_pushnumber(L, cosh(luaL_checknumber(L, 1))); lua_pushnumber(L, cosh(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_tan (lua_State *L) { static int math_tan (lua_State *L) {
lua_pushnumber(L, tan(luaL_checknumber(L, 1))); lua_pushnumber(L, tan(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_tanh (lua_State *L) { static int math_tanh (lua_State *L) {
lua_pushnumber(L, tanh(luaL_checknumber(L, 1))); lua_pushnumber(L, tanh(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_asin (lua_State *L) { static int math_asin (lua_State *L) {
lua_pushnumber(L, asin(luaL_checknumber(L, 1))); lua_pushnumber(L, asin(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_acos (lua_State *L) { static int math_acos (lua_State *L) {
lua_pushnumber(L, acos(luaL_checknumber(L, 1))); lua_pushnumber(L, acos(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_atan (lua_State *L) { static int math_atan (lua_State *L) {
lua_pushnumber(L, atan(luaL_checknumber(L, 1))); lua_pushnumber(L, atan(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_atan2 (lua_State *L) { static int math_atan2 (lua_State *L) {
lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_ceil (lua_State *L) { static int math_ceil (lua_State *L) {
lua_pushnumber(L, ceil(luaL_checknumber(L, 1))); lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_floor (lua_State *L) { static int math_floor (lua_State *L) {
lua_pushnumber(L, floor(luaL_checknumber(L, 1))); lua_pushnumber(L, floor(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_fmod (lua_State *L) { static int math_fmod (lua_State *L) {
lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_modf (lua_State *L) { static int math_modf (lua_State *L) {
double ip; double ip;
double fp = modf(luaL_checknumber(L, 1), &ip); double fp = modf(luaL_checknumber(L, 1), &ip);
lua_pushnumber(L, ip); lua_pushnumber(L, ip);
...@@ -116,7 +116,7 @@ static int ICACHE_FLASH_ATTR math_modf (lua_State *L) { ...@@ -116,7 +116,7 @@ static int ICACHE_FLASH_ATTR math_modf (lua_State *L) {
// works in both integer and floating point versions of Lua. // works in both integer and floating point versions of Lua.
// This identity function is used for them. // This identity function is used for them.
static int ICACHE_FLASH_ATTR math_identity (lua_State *L) { static int math_identity (lua_State *L) {
lua_pushnumber(L, luaL_checknumber(L, 1)); lua_pushnumber(L, luaL_checknumber(L, 1));
return 1; return 1;
} }
...@@ -125,7 +125,7 @@ static int ICACHE_FLASH_ATTR math_identity (lua_State *L) { ...@@ -125,7 +125,7 @@ static int ICACHE_FLASH_ATTR math_identity (lua_State *L) {
#ifdef LUA_NUMBER_INTEGRAL #ifdef LUA_NUMBER_INTEGRAL
// Integer square root for integer version // Integer square root for integer version
static lua_Number ICACHE_FLASH_ATTR isqrt(lua_Number x) static lua_Number isqrt(lua_Number x)
{ {
lua_Number op, res, one; lua_Number op, res, one;
...@@ -147,7 +147,7 @@ static lua_Number ICACHE_FLASH_ATTR isqrt(lua_Number x) ...@@ -147,7 +147,7 @@ static lua_Number ICACHE_FLASH_ATTR isqrt(lua_Number x)
} }
#endif #endif
static int ICACHE_FLASH_ATTR math_sqrt (lua_State *L) { static int math_sqrt (lua_State *L) {
#ifdef LUA_NUMBER_INTEGRAL #ifdef LUA_NUMBER_INTEGRAL
lua_Number x = luaL_checknumber(L, 1); lua_Number x = luaL_checknumber(L, 1);
luaL_argcheck(L, 0<=x, 1, "negative"); luaL_argcheck(L, 0<=x, 1, "negative");
...@@ -162,7 +162,7 @@ static int ICACHE_FLASH_ATTR math_sqrt (lua_State *L) { ...@@ -162,7 +162,7 @@ static int ICACHE_FLASH_ATTR math_sqrt (lua_State *L) {
# define pow(a,b) luai_ipow(a,b) # define pow(a,b) luai_ipow(a,b)
#endif #endif
static int ICACHE_FLASH_ATTR math_pow (lua_State *L) { static int math_pow (lua_State *L) {
lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2))); lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
return 1; return 1;
} }
...@@ -174,46 +174,46 @@ static int ICACHE_FLASH_ATTR math_pow (lua_State *L) { ...@@ -174,46 +174,46 @@ static int ICACHE_FLASH_ATTR math_pow (lua_State *L) {
#ifndef LUA_NUMBER_INTEGRAL #ifndef LUA_NUMBER_INTEGRAL
static int ICACHE_FLASH_ATTR math_log (lua_State *L) { static int math_log (lua_State *L) {
lua_pushnumber(L, log(luaL_checknumber(L, 1))); lua_pushnumber(L, log(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_log10 (lua_State *L) { static int math_log10 (lua_State *L) {
lua_pushnumber(L, log10(luaL_checknumber(L, 1))); lua_pushnumber(L, log10(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_exp (lua_State *L) { static int math_exp (lua_State *L) {
lua_pushnumber(L, exp(luaL_checknumber(L, 1))); lua_pushnumber(L, exp(luaL_checknumber(L, 1)));
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_deg (lua_State *L) { static int math_deg (lua_State *L) {
lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE); lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE);
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_rad (lua_State *L) { static int math_rad (lua_State *L) {
lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE); lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE);
return 1; return 1;
} }
static int ICACHE_FLASH_ATTR math_frexp (lua_State *L) { static int math_frexp (lua_State *L) {
int e; int e;
lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e)); lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));
lua_pushinteger(L, e); lua_pushinteger(L, e);
return 2; return 2;
} }
static int ICACHE_FLASH_ATTR math_ldexp (lua_State *L) { static int math_ldexp (lua_State *L) {
lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2))); lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
return 1; return 1;
} }
#endif // #ifdef LUA_NUMBER_INTEGRAL #endif // #ifdef LUA_NUMBER_INTEGRAL
static int ICACHE_FLASH_ATTR math_min (lua_State *L) { static int math_min (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */ int n = lua_gettop(L); /* number of arguments */
lua_Number dmin = luaL_checknumber(L, 1); lua_Number dmin = luaL_checknumber(L, 1);
int i; int i;
...@@ -227,7 +227,7 @@ static int ICACHE_FLASH_ATTR math_min (lua_State *L) { ...@@ -227,7 +227,7 @@ static int ICACHE_FLASH_ATTR math_min (lua_State *L) {
} }
static int ICACHE_FLASH_ATTR math_max (lua_State *L) { static int math_max (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */ int n = lua_gettop(L); /* number of arguments */
lua_Number dmax = luaL_checknumber(L, 1); lua_Number dmax = luaL_checknumber(L, 1);
int i; int i;
...@@ -243,7 +243,7 @@ static int ICACHE_FLASH_ATTR math_max (lua_State *L) { ...@@ -243,7 +243,7 @@ static int ICACHE_FLASH_ATTR math_max (lua_State *L) {
#ifdef LUA_NUMBER_INTEGRAL #ifdef LUA_NUMBER_INTEGRAL
static int ICACHE_FLASH_ATTR math_random (lua_State *L) { static int math_random (lua_State *L) {
lua_Number r = (lua_Number)(rand()%RAND_MAX); lua_Number r = (lua_Number)(rand()%RAND_MAX);
switch (lua_gettop(L)) { /* check number of arguments */ switch (lua_gettop(L)) { /* check number of arguments */
...@@ -271,7 +271,7 @@ static int ICACHE_FLASH_ATTR math_random (lua_State *L) { ...@@ -271,7 +271,7 @@ static int ICACHE_FLASH_ATTR math_random (lua_State *L) {
#else #else
static int ICACHE_FLASH_ATTR math_random (lua_State *L) { static int math_random (lua_State *L) {
/* the `%' avoids the (rare) case of r==1, and is needed also because on /* the `%' avoids the (rare) case of r==1, and is needed also because on
some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */ some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */
lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX; lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
...@@ -301,7 +301,7 @@ static int ICACHE_FLASH_ATTR math_random (lua_State *L) { ...@@ -301,7 +301,7 @@ static int ICACHE_FLASH_ATTR math_random (lua_State *L) {
#endif #endif
static int ICACHE_FLASH_ATTR math_randomseed (lua_State *L) { static int math_randomseed (lua_State *L) {
srand(luaL_checkint(L, 1)); srand(luaL_checkint(L, 1));
return 0; return 0;
} }
...@@ -371,7 +371,7 @@ const LUA_REG_TYPE math_map[] = { ...@@ -371,7 +371,7 @@ const LUA_REG_TYPE math_map[] = {
# include "c_limits.h" /* for LONG_MAX */ # include "c_limits.h" /* for LONG_MAX */
#endif #endif
LUALIB_API int ICACHE_FLASH_ATTR luaopen_math (lua_State *L) { LUALIB_API int luaopen_math (lua_State *L) {
#if LUA_OPTIMIZE_MEMORY > 0 #if LUA_OPTIMIZE_MEMORY > 0
return 0; return 0;
#else #else
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
#define MINSIZEARRAY 4 #define MINSIZEARRAY 4
void *ICACHE_FLASH_ATTR luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems, void *luaM_growaux_ (lua_State *L, void *block, int *size, size_t size_elems,
int limit, const char *errormsg) { int limit, const char *errormsg) {
void *newblock; void *newblock;
int newsize; int newsize;
...@@ -63,7 +63,7 @@ void *ICACHE_FLASH_ATTR luaM_growaux_ (lua_State *L, void *block, int *size, siz ...@@ -63,7 +63,7 @@ void *ICACHE_FLASH_ATTR luaM_growaux_ (lua_State *L, void *block, int *size, siz
} }
void *ICACHE_FLASH_ATTR luaM_toobig (lua_State *L) { void *luaM_toobig (lua_State *L) {
luaG_runerror(L, "memory allocation error: block too big"); luaG_runerror(L, "memory allocation error: block too big");
return NULL; /* to avoid warnings */ return NULL; /* to avoid warnings */
} }
...@@ -73,7 +73,7 @@ void *ICACHE_FLASH_ATTR luaM_toobig (lua_State *L) { ...@@ -73,7 +73,7 @@ void *ICACHE_FLASH_ATTR luaM_toobig (lua_State *L) {
/* /*
** generic allocation routine. ** generic allocation routine.
*/ */
void *ICACHE_FLASH_ATTR luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) { void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
global_State *g = G(L); global_State *g = G(L);
lua_assert((osize == 0) == (block == NULL)); lua_assert((osize == 0) == (block == NULL));
block = (*g->frealloc)(g->ud, block, osize, nsize); block = (*g->frealloc)(g->ud, block, osize, nsize);
......
...@@ -237,19 +237,19 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) { ...@@ -237,19 +237,19 @@ static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
#define DLMSG "dynamic libraries not enabled; check your Lua installation" #define DLMSG "dynamic libraries not enabled; check your Lua installation"
static void ICACHE_FLASH_ATTR ll_unloadlib (void *lib) { static void ll_unloadlib (void *lib) {
(void)lib; /* to avoid warnings */ (void)lib; /* to avoid warnings */
} }
static void * ICACHE_FLASH_ATTR ll_load (lua_State *L, const char *path) { static void * ll_load (lua_State *L, const char *path) {
(void)path; /* to avoid warnings */ (void)path; /* to avoid warnings */
lua_pushliteral(L, DLMSG); lua_pushliteral(L, DLMSG);
return NULL; return NULL;
} }
static lua_CFunction ICACHE_FLASH_ATTR ll_sym (lua_State *L, void *lib, const char *sym) { static lua_CFunction ll_sym (lua_State *L, void *lib, const char *sym) {
(void)lib; (void)sym; /* to avoid warnings */ (void)lib; (void)sym; /* to avoid warnings */
lua_pushliteral(L, DLMSG); lua_pushliteral(L, DLMSG);
return NULL; return NULL;
...@@ -260,7 +260,7 @@ static lua_CFunction ICACHE_FLASH_ATTR ll_sym (lua_State *L, void *lib, const ch ...@@ -260,7 +260,7 @@ static lua_CFunction ICACHE_FLASH_ATTR ll_sym (lua_State *L, void *lib, const ch
static void ** ICACHE_FLASH_ATTR ll_register (lua_State *L, const char *path) { static void ** ll_register (lua_State *L, const char *path) {
void **plib; void **plib;
lua_pushfstring(L, "%s%s", LIBPREFIX, path); lua_pushfstring(L, "%s%s", LIBPREFIX, path);
lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */ lua_gettable(L, LUA_REGISTRYINDEX); /* check library in registry? */
...@@ -284,7 +284,7 @@ static void ** ICACHE_FLASH_ATTR ll_register (lua_State *L, const char *path) { ...@@ -284,7 +284,7 @@ static void ** ICACHE_FLASH_ATTR ll_register (lua_State *L, const char *path) {
** __gc tag method: calls library's `ll_unloadlib' function with the lib ** __gc tag method: calls library's `ll_unloadlib' function with the lib
** handle ** handle
*/ */
static int ICACHE_FLASH_ATTR gctm (lua_State *L) { static int gctm (lua_State *L) {
void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB"); void **lib = (void **)luaL_checkudata(L, 1, "_LOADLIB");
if (*lib) ll_unloadlib(*lib); if (*lib) ll_unloadlib(*lib);
*lib = NULL; /* mark library as closed */ *lib = NULL; /* mark library as closed */
...@@ -292,7 +292,7 @@ static int ICACHE_FLASH_ATTR gctm (lua_State *L) { ...@@ -292,7 +292,7 @@ static int ICACHE_FLASH_ATTR gctm (lua_State *L) {
} }
static int ICACHE_FLASH_ATTR ll_loadfunc (lua_State *L, const char *path, const char *sym) { static int ll_loadfunc (lua_State *L, const char *path, const char *sym) {
void **reg = ll_register(L, path); void **reg = ll_register(L, path);
if (*reg == NULL) *reg = ll_load(L, path); if (*reg == NULL) *reg = ll_load(L, path);
if (*reg == NULL) if (*reg == NULL)
...@@ -307,7 +307,7 @@ static int ICACHE_FLASH_ATTR ll_loadfunc (lua_State *L, const char *path, const ...@@ -307,7 +307,7 @@ static int ICACHE_FLASH_ATTR ll_loadfunc (lua_State *L, const char *path, const
} }
static int ICACHE_FLASH_ATTR ll_loadlib (lua_State *L) { static int ll_loadlib (lua_State *L) {
const char *path = luaL_checkstring(L, 1); const char *path = luaL_checkstring(L, 1);
const char *init = luaL_checkstring(L, 2); const char *init = luaL_checkstring(L, 2);
int stat = ll_loadfunc(L, path, init); int stat = ll_loadfunc(L, path, init);
...@@ -336,7 +336,7 @@ static int readable (const char *filename) { ...@@ -336,7 +336,7 @@ static int readable (const char *filename) {
return 1; return 1;
} }
#else #else
static int ICACHE_FLASH_ATTR readable (const char *filename) { static int readable (const char *filename) {
int f = fs_open(filename, FS_RDONLY); /* try to open file */ int f = fs_open(filename, FS_RDONLY); /* try to open file */
if (f < FS_OPEN_OK) return 0; /* open failed */ if (f < FS_OPEN_OK) return 0; /* open failed */
fs_close(f); fs_close(f);
...@@ -344,7 +344,7 @@ static int ICACHE_FLASH_ATTR readable (const char *filename) { ...@@ -344,7 +344,7 @@ static int ICACHE_FLASH_ATTR readable (const char *filename) {
} }
#endif #endif
static const char * ICACHE_FLASH_ATTR pushnexttemplate (lua_State *L, const char *path) { static const char * pushnexttemplate (lua_State *L, const char *path) {
const char *l; const char *l;
while (*path == *LUA_PATHSEP) path++; /* skip separators */ while (*path == *LUA_PATHSEP) path++; /* skip separators */
if (*path == '\0') return NULL; /* no more templates */ if (*path == '\0') return NULL; /* no more templates */
...@@ -355,7 +355,7 @@ static const char * ICACHE_FLASH_ATTR pushnexttemplate (lua_State *L, const char ...@@ -355,7 +355,7 @@ static const char * ICACHE_FLASH_ATTR pushnexttemplate (lua_State *L, const char
} }
static const char * ICACHE_FLASH_ATTR findfile (lua_State *L, const char *name, static const char * findfile (lua_State *L, const char *name,
const char *pname) { const char *pname) {
const char *path; const char *path;
name = luaL_gsub(L, name, ".", LUA_DIRSEP); name = luaL_gsub(L, name, ".", LUA_DIRSEP);
...@@ -378,13 +378,13 @@ static const char * ICACHE_FLASH_ATTR findfile (lua_State *L, const char *name, ...@@ -378,13 +378,13 @@ static const char * ICACHE_FLASH_ATTR findfile (lua_State *L, const char *name,
} }
static void ICACHE_FLASH_ATTR loaderror (lua_State *L, const char *filename) { static void loaderror (lua_State *L, const char *filename) {
luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s", luaL_error(L, "error loading module " LUA_QS " from file " LUA_QS ":\n\t%s",
lua_tostring(L, 1), filename, lua_tostring(L, -1)); lua_tostring(L, 1), filename, lua_tostring(L, -1));
} }
static int ICACHE_FLASH_ATTR loader_Lua (lua_State *L) { static int loader_Lua (lua_State *L) {
const char *filename; const char *filename;
const char *name = luaL_checkstring(L, 1); const char *name = luaL_checkstring(L, 1);
filename = findfile(L, name, "path"); filename = findfile(L, name, "path");
...@@ -410,7 +410,7 @@ static const char *mkfuncname (lua_State *L, const char *modname) { ...@@ -410,7 +410,7 @@ static const char *mkfuncname (lua_State *L, const char *modname) {
} }
static int ICACHE_FLASH_ATTR loader_C (lua_State *L) { static int loader_C (lua_State *L) {
const char *funcname; const char *funcname;
const char *name = luaL_checkstring(L, 1); const char *name = luaL_checkstring(L, 1);
const char *filename = findfile(L, name, "cpath"); const char *filename = findfile(L, name, "cpath");
...@@ -422,7 +422,7 @@ static int ICACHE_FLASH_ATTR loader_C (lua_State *L) { ...@@ -422,7 +422,7 @@ static int ICACHE_FLASH_ATTR loader_C (lua_State *L) {
} }
static int ICACHE_FLASH_ATTR loader_Croot (lua_State *L) { static int loader_Croot (lua_State *L) {
const char *funcname; const char *funcname;
const char *filename; const char *filename;
const char *name = luaL_checkstring(L, 1); const char *name = luaL_checkstring(L, 1);
...@@ -443,7 +443,7 @@ static int ICACHE_FLASH_ATTR loader_Croot (lua_State *L) { ...@@ -443,7 +443,7 @@ static int ICACHE_FLASH_ATTR loader_Croot (lua_State *L) {
} }
static int ICACHE_FLASH_ATTR loader_preload (lua_State *L) { static int loader_preload (lua_State *L) {
const char *name = luaL_checkstring(L, 1); const char *name = luaL_checkstring(L, 1);
lua_getfield(L, LUA_ENVIRONINDEX, "preload"); lua_getfield(L, LUA_ENVIRONINDEX, "preload");
if (!lua_istable(L, -1)) if (!lua_istable(L, -1))
...@@ -459,7 +459,7 @@ static const int sentinel_ = 0; ...@@ -459,7 +459,7 @@ static const int sentinel_ = 0;
#define sentinel ((void *)&sentinel_) #define sentinel ((void *)&sentinel_)
static int ICACHE_FLASH_ATTR ll_require (lua_State *L) { static int ll_require (lua_State *L) {
const char *name = luaL_checkstring(L, 1); const char *name = luaL_checkstring(L, 1);
int i; int i;
lua_settop(L, 1); /* _LOADED table will be at index 2 */ lua_settop(L, 1); /* _LOADED table will be at index 2 */
...@@ -521,7 +521,7 @@ static int ICACHE_FLASH_ATTR ll_require (lua_State *L) { ...@@ -521,7 +521,7 @@ static int ICACHE_FLASH_ATTR ll_require (lua_State *L) {
*/ */
static void ICACHE_FLASH_ATTR setfenv (lua_State *L) { static void setfenv (lua_State *L) {
lua_Debug ar; lua_Debug ar;
if (lua_getstack(L, 1, &ar) == 0 || if (lua_getstack(L, 1, &ar) == 0 ||
lua_getinfo(L, "f", &ar) == 0 || /* get calling function */ lua_getinfo(L, "f", &ar) == 0 || /* get calling function */
...@@ -533,7 +533,7 @@ static void ICACHE_FLASH_ATTR setfenv (lua_State *L) { ...@@ -533,7 +533,7 @@ static void ICACHE_FLASH_ATTR setfenv (lua_State *L) {
} }
static void ICACHE_FLASH_ATTR dooptions (lua_State *L, int n) { static void dooptions (lua_State *L, int n) {
int i; int i;
for (i = 2; i <= n; i++) { for (i = 2; i <= n; i++) {
lua_pushvalue(L, i); /* get option (a function) */ lua_pushvalue(L, i); /* get option (a function) */
...@@ -543,7 +543,7 @@ static void ICACHE_FLASH_ATTR dooptions (lua_State *L, int n) { ...@@ -543,7 +543,7 @@ static void ICACHE_FLASH_ATTR dooptions (lua_State *L, int n) {
} }
static void ICACHE_FLASH_ATTR modinit (lua_State *L, const char *modname) { static void modinit (lua_State *L, const char *modname) {
const char *dot; const char *dot;
lua_pushvalue(L, -1); lua_pushvalue(L, -1);
lua_setfield(L, -2, "_M"); /* module._M = module */ lua_setfield(L, -2, "_M"); /* module._M = module */
...@@ -558,7 +558,7 @@ static void ICACHE_FLASH_ATTR modinit (lua_State *L, const char *modname) { ...@@ -558,7 +558,7 @@ static void ICACHE_FLASH_ATTR modinit (lua_State *L, const char *modname) {
} }
static int ICACHE_FLASH_ATTR ll_module (lua_State *L) { static int ll_module (lua_State *L) {
const char *modname = luaL_checkstring(L, 1); const char *modname = luaL_checkstring(L, 1);
if (luaR_findglobal(modname, c_strlen(modname))) if (luaR_findglobal(modname, c_strlen(modname)))
return 0; return 0;
...@@ -608,7 +608,7 @@ static int ll_seeall (lua_State *L) { ...@@ -608,7 +608,7 @@ static int ll_seeall (lua_State *L) {
/* auxiliary mark (for internal use) */ /* auxiliary mark (for internal use) */
#define AUXMARK "\1" #define AUXMARK "\1"
static void ICACHE_FLASH_ATTR setpath (lua_State *L, const char *fieldname, const char *envname, static void setpath (lua_State *L, const char *fieldname, const char *envname,
const char *def) { const char *def) {
const char *path = c_getenv(envname); const char *path = c_getenv(envname);
if (path == NULL) /* no environment variable? */ if (path == NULL) /* no environment variable? */
...@@ -643,13 +643,15 @@ static const lua_CFunction loaders[] = ...@@ -643,13 +643,15 @@ static const lua_CFunction loaders[] =
{loader_preload, loader_Lua, loader_C, loader_Croot, NULL}; {loader_preload, loader_Lua, loader_C, loader_Croot, NULL};
#if LUA_OPTIMIZE_MEMORY > 0 #if LUA_OPTIMIZE_MEMORY > 0
const luaR_entry lmt[] = { #define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const LUA_REG_TYPE lmt[] = {
{LRO_STRKEY("__gc"), LRO_FUNCVAL(gctm)}, {LRO_STRKEY("__gc"), LRO_FUNCVAL(gctm)},
{LRO_NILKEY, LRO_NILVAL} {LRO_NILKEY, LRO_NILVAL}
}; };
#endif #endif
LUALIB_API int ICACHE_FLASH_ATTR luaopen_package (lua_State *L) { LUALIB_API int luaopen_package (lua_State *L) {
int i; int i;
/* create new type _LOADLIB */ /* create new type _LOADLIB */
#if LUA_OPTIMIZE_MEMORY == 0 #if LUA_OPTIMIZE_MEMORY == 0
......
...@@ -32,7 +32,7 @@ const TValue luaO_nilobject_ = {LUA_TVALUE_NIL}; ...@@ -32,7 +32,7 @@ const TValue luaO_nilobject_ = {LUA_TVALUE_NIL};
** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
** eeeee != 0 and (xxx) otherwise. ** eeeee != 0 and (xxx) otherwise.
*/ */
int ICACHE_FLASH_ATTR luaO_int2fb (unsigned int x) { int luaO_int2fb (unsigned int x) {
int e = 0; /* expoent */ int e = 0; /* expoent */
while (x >= 16) { while (x >= 16) {
x = (x+1) >> 1; x = (x+1) >> 1;
...@@ -44,14 +44,14 @@ int ICACHE_FLASH_ATTR luaO_int2fb (unsigned int x) { ...@@ -44,14 +44,14 @@ int ICACHE_FLASH_ATTR luaO_int2fb (unsigned int x) {
/* converts back */ /* converts back */
int ICACHE_FLASH_ATTR luaO_fb2int (int x) { int luaO_fb2int (int x) {
int e = (x >> 3) & 31; int e = (x >> 3) & 31;
if (e == 0) return x; if (e == 0) return x;
else return ((x & 7)+8) << (e - 1); else return ((x & 7)+8) << (e - 1);
} }
int ICACHE_FLASH_ATTR luaO_log2 (unsigned int x) { int luaO_log2 (unsigned int x) {
static const lu_byte log_2[256] = { static const lu_byte log_2[256] = {
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
...@@ -69,7 +69,7 @@ int ICACHE_FLASH_ATTR luaO_log2 (unsigned int x) { ...@@ -69,7 +69,7 @@ int ICACHE_FLASH_ATTR luaO_log2 (unsigned int x) {
} }
int ICACHE_FLASH_ATTR luaO_rawequalObj (const TValue *t1, const TValue *t2) { int luaO_rawequalObj (const TValue *t1, const TValue *t2) {
if (ttype(t1) != ttype(t2)) return 0; if (ttype(t1) != ttype(t2)) return 0;
else switch (ttype(t1)) { else switch (ttype(t1)) {
case LUA_TNIL: case LUA_TNIL:
...@@ -89,7 +89,7 @@ int ICACHE_FLASH_ATTR luaO_rawequalObj (const TValue *t1, const TValue *t2) { ...@@ -89,7 +89,7 @@ int ICACHE_FLASH_ATTR luaO_rawequalObj (const TValue *t1, const TValue *t2) {
} }
int ICACHE_FLASH_ATTR luaO_str2d (const char *s, lua_Number *result) { int luaO_str2d (const char *s, lua_Number *result) {
char *endptr; char *endptr;
*result = lua_str2number(s, &endptr); *result = lua_str2number(s, &endptr);
if (endptr == s) return 0; /* conversion failed */ if (endptr == s) return 0; /* conversion failed */
...@@ -103,14 +103,14 @@ int ICACHE_FLASH_ATTR luaO_str2d (const char *s, lua_Number *result) { ...@@ -103,14 +103,14 @@ int ICACHE_FLASH_ATTR luaO_str2d (const char *s, lua_Number *result) {
static void ICACHE_FLASH_ATTR pushstr (lua_State *L, const char *str) { static void pushstr (lua_State *L, const char *str) {
setsvalue2s(L, L->top, luaS_new(L, str)); setsvalue2s(L, L->top, luaS_new(L, str));
incr_top(L); incr_top(L);
} }
/* this function handles only `%d', `%c', %f, %p, and `%s' formats */ /* this function handles only `%d', `%c', %f, %p, and `%s' formats */
const char *ICACHE_FLASH_ATTR luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
int n = 1; int n = 1;
pushstr(L, ""); pushstr(L, "");
for (;;) { for (;;) {
...@@ -171,7 +171,7 @@ const char *ICACHE_FLASH_ATTR luaO_pushvfstring (lua_State *L, const char *fmt, ...@@ -171,7 +171,7 @@ const char *ICACHE_FLASH_ATTR luaO_pushvfstring (lua_State *L, const char *fmt,
} }
const char *ICACHE_FLASH_ATTR luaO_pushfstring (lua_State *L, const char *fmt, ...) { const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
const char *msg; const char *msg;
va_list argp; va_list argp;
va_start(argp, fmt); va_start(argp, fmt);
...@@ -181,7 +181,7 @@ const char *ICACHE_FLASH_ATTR luaO_pushfstring (lua_State *L, const char *fmt, . ...@@ -181,7 +181,7 @@ const char *ICACHE_FLASH_ATTR luaO_pushfstring (lua_State *L, const char *fmt, .
} }
void ICACHE_FLASH_ATTR luaO_chunkid (char *out, const char *source, size_t bufflen) { void luaO_chunkid (char *out, const char *source, size_t bufflen) {
if (*source == '=') { if (*source == '=') {
c_strncpy(out, source+1, bufflen); /* remove first char */ c_strncpy(out, source+1, bufflen); /* remove first char */
out[bufflen-1] = '\0'; /* ensures null termination */ out[bufflen-1] = '\0'; /* ensures null termination */
......
This diff is collapsed.
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#undef LREGISTER #undef LREGISTER
#if (MIN_OPT_LEVEL > 0) && (LUA_OPTIMIZE_MEMORY >= MIN_OPT_LEVEL) #if (MIN_OPT_LEVEL > 0) && (LUA_OPTIMIZE_MEMORY >= MIN_OPT_LEVEL)
#define LUA_REG_TYPE luaR_entry #define LUA_REG_TYPE luaR_entry ICACHE_FLASH_ATTR
#define LSTRKEY LRO_STRKEY #define LSTRKEY LRO_STRKEY
#define LNUMKEY LRO_NUMKEY #define LNUMKEY LRO_NUMKEY
#define LNILKEY LRO_NILKEY #define LNILKEY LRO_NILKEY
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
extern const luaR_table lua_rotable[]; extern const luaR_table lua_rotable[];
/* Find a global "read only table" in the constant lua_rotable array */ /* Find a global "read only table" in the constant lua_rotable array */
void* ICACHE_FLASH_ATTR luaR_findglobal(const char *name, unsigned len) { void* luaR_findglobal(const char *name, unsigned len) {
unsigned i; unsigned i;
if (c_strlen(name) > LUA_MAX_ROTABLE_NAME) if (c_strlen(name) > LUA_MAX_ROTABLE_NAME)
...@@ -29,7 +29,7 @@ void* ICACHE_FLASH_ATTR luaR_findglobal(const char *name, unsigned len) { ...@@ -29,7 +29,7 @@ void* ICACHE_FLASH_ATTR luaR_findglobal(const char *name, unsigned len) {
} }
/* Find an entry in a rotable and return it */ /* Find an entry in a rotable and return it */
static const TValue* ICACHE_FLASH_ATTR luaR_auxfind(const luaR_entry *pentry, const char *strkey, luaR_numkey numkey, unsigned *ppos) { static const TValue* luaR_auxfind(const luaR_entry *pentry, const char *strkey, luaR_numkey numkey, unsigned *ppos) {
const TValue *res = NULL; const TValue *res = NULL;
unsigned i = 0; unsigned i = 0;
...@@ -48,7 +48,7 @@ static const TValue* ICACHE_FLASH_ATTR luaR_auxfind(const luaR_entry *pentry, co ...@@ -48,7 +48,7 @@ static const TValue* ICACHE_FLASH_ATTR luaR_auxfind(const luaR_entry *pentry, co
return res; return res;
} }
int ICACHE_FLASH_ATTR luaR_findfunction(lua_State *L, const luaR_entry *ptable) { int luaR_findfunction(lua_State *L, const luaR_entry *ptable) {
const TValue *res = NULL; const TValue *res = NULL;
const char *key = luaL_checkstring(L, 2); const char *key = luaL_checkstring(L, 2);
...@@ -64,12 +64,12 @@ int ICACHE_FLASH_ATTR luaR_findfunction(lua_State *L, const luaR_entry *ptable) ...@@ -64,12 +64,12 @@ int ICACHE_FLASH_ATTR luaR_findfunction(lua_State *L, const luaR_entry *ptable)
/* Find an entry in a rotable and return its type /* Find an entry in a rotable and return its type
If "strkey" is not NULL, the function will look for a string key, If "strkey" is not NULL, the function will look for a string key,
otherwise it will look for a number key */ otherwise it will look for a number key */
const TValue* ICACHE_FLASH_ATTR luaR_findentry(void *data, const char *strkey, luaR_numkey numkey, unsigned *ppos) { const TValue* luaR_findentry(void *data, const char *strkey, luaR_numkey numkey, unsigned *ppos) {
return luaR_auxfind((const luaR_entry*)data, strkey, numkey, ppos); return luaR_auxfind((const luaR_entry*)data, strkey, numkey, ppos);
} }
/* Find the metatable of a given table */ /* Find the metatable of a given table */
void* ICACHE_FLASH_ATTR luaR_getmeta(void *data) { void* luaR_getmeta(void *data) {
#ifdef LUA_META_ROTABLES #ifdef LUA_META_ROTABLES
const TValue *res = luaR_auxfind((const luaR_entry*)data, "__metatable", 0, NULL); const TValue *res = luaR_auxfind((const luaR_entry*)data, "__metatable", 0, NULL);
return res && ttisrotable(res) ? rvalue(res) : NULL; return res && ttisrotable(res) ? rvalue(res) : NULL;
...@@ -78,7 +78,7 @@ void* ICACHE_FLASH_ATTR luaR_getmeta(void *data) { ...@@ -78,7 +78,7 @@ void* ICACHE_FLASH_ATTR luaR_getmeta(void *data) {
#endif #endif
} }
static void ICACHE_FLASH_ATTR luaR_next_helper(lua_State *L, const luaR_entry *pentries, int pos, TValue *key, TValue *val) { static void luaR_next_helper(lua_State *L, const luaR_entry *pentries, int pos, TValue *key, TValue *val) {
setnilvalue(key); setnilvalue(key);
setnilvalue(val); setnilvalue(val);
if (pentries[pos].key.type != LUA_TNIL) { if (pentries[pos].key.type != LUA_TNIL) {
...@@ -91,7 +91,7 @@ static void ICACHE_FLASH_ATTR luaR_next_helper(lua_State *L, const luaR_entry *p ...@@ -91,7 +91,7 @@ static void ICACHE_FLASH_ATTR luaR_next_helper(lua_State *L, const luaR_entry *p
} }
} }
/* next (used for iteration) */ /* next (used for iteration) */
void ICACHE_FLASH_ATTR luaR_next(lua_State *L, void *data, TValue *key, TValue *val) { void luaR_next(lua_State *L, void *data, TValue *key, TValue *val) {
const luaR_entry* pentries = (const luaR_entry*)data; const luaR_entry* pentries = (const luaR_entry*)data;
char strkey[LUA_MAX_ROTABLE_NAME + 1], *pstrkey = NULL; char strkey[LUA_MAX_ROTABLE_NAME + 1], *pstrkey = NULL;
luaR_numkey numkey = 0; luaR_numkey numkey = 0;
...@@ -115,7 +115,7 @@ void ICACHE_FLASH_ATTR luaR_next(lua_State *L, void *data, TValue *key, TValue * ...@@ -115,7 +115,7 @@ void ICACHE_FLASH_ATTR luaR_next(lua_State *L, void *data, TValue *key, TValue *
} }
/* Convert a Lua string to a C string */ /* Convert a Lua string to a C string */
void ICACHE_FLASH_ATTR luaR_getcstr(char *dest, const TString *src, size_t maxsize) { void luaR_getcstr(char *dest, const TString *src, size_t maxsize) {
if (src->tsv.len+1 > maxsize) if (src->tsv.len+1 > maxsize)
dest[0] = '\0'; dest[0] = '\0';
else { else {
...@@ -129,7 +129,7 @@ void ICACHE_FLASH_ATTR luaR_getcstr(char *dest, const TString *src, size_t maxsi ...@@ -129,7 +129,7 @@ void ICACHE_FLASH_ATTR luaR_getcstr(char *dest, const TString *src, size_t maxsi
#include "compiler.h" #include "compiler.h"
int ICACHE_FLASH_ATTR luaR_isrotable(void *p) { int luaR_isrotable(void *p) {
return RODATA_START_ADDRESS <= (char*)p && (char*)p <= RODATA_END_ADDRESS; return RODATA_START_ADDRESS <= (char*)p && (char*)p <= RODATA_END_ADDRESS;
} }
#endif #endif
...@@ -38,7 +38,7 @@ typedef struct LG { ...@@ -38,7 +38,7 @@ typedef struct LG {
static void ICACHE_FLASH_ATTR stack_init (lua_State *L1, lua_State *L) { static void stack_init (lua_State *L1, lua_State *L) {
/* initialize CallInfo array */ /* initialize CallInfo array */
L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo); L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo);
L1->ci = L1->base_ci; L1->ci = L1->base_ci;
...@@ -57,7 +57,7 @@ static void ICACHE_FLASH_ATTR stack_init (lua_State *L1, lua_State *L) { ...@@ -57,7 +57,7 @@ static void ICACHE_FLASH_ATTR stack_init (lua_State *L1, lua_State *L) {
} }
static void ICACHE_FLASH_ATTR freestack (lua_State *L, lua_State *L1) { static void freestack (lua_State *L, lua_State *L1) {
luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo); luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo);
luaM_freearray(L, L1->stack, L1->stacksize, TValue); luaM_freearray(L, L1->stack, L1->stacksize, TValue);
} }
...@@ -66,7 +66,7 @@ static void ICACHE_FLASH_ATTR freestack (lua_State *L, lua_State *L1) { ...@@ -66,7 +66,7 @@ static void ICACHE_FLASH_ATTR freestack (lua_State *L, lua_State *L1) {
/* /*
** open parts that may cause memory-allocation errors ** open parts that may cause memory-allocation errors
*/ */
static void ICACHE_FLASH_ATTR f_luaopen (lua_State *L, void *ud) { static void f_luaopen (lua_State *L, void *ud) {
global_State *g = G(L); global_State *g = G(L);
UNUSED(ud); UNUSED(ud);
stack_init(L, L); /* init stack */ stack_init(L, L); /* init stack */
...@@ -80,7 +80,7 @@ static void ICACHE_FLASH_ATTR f_luaopen (lua_State *L, void *ud) { ...@@ -80,7 +80,7 @@ static void ICACHE_FLASH_ATTR f_luaopen (lua_State *L, void *ud) {
} }
static void ICACHE_FLASH_ATTR preinit_state (lua_State *L, global_State *g) { static void preinit_state (lua_State *L, global_State *g) {
G(L) = g; G(L) = g;
L->stack = NULL; L->stack = NULL;
L->stacksize = 0; L->stacksize = 0;
...@@ -101,7 +101,7 @@ static void ICACHE_FLASH_ATTR preinit_state (lua_State *L, global_State *g) { ...@@ -101,7 +101,7 @@ static void ICACHE_FLASH_ATTR preinit_state (lua_State *L, global_State *g) {
} }
static void ICACHE_FLASH_ATTR close_state (lua_State *L) { static void close_state (lua_State *L) {
global_State *g = G(L); global_State *g = G(L);
luaF_close(L, L->stack); /* close all upvalues for this thread */ luaF_close(L, L->stack); /* close all upvalues for this thread */
luaC_freeall(L); /* collect all objects */ luaC_freeall(L); /* collect all objects */
...@@ -115,7 +115,7 @@ static void ICACHE_FLASH_ATTR close_state (lua_State *L) { ...@@ -115,7 +115,7 @@ static void ICACHE_FLASH_ATTR close_state (lua_State *L) {
} }
lua_State *ICACHE_FLASH_ATTR luaE_newthread (lua_State *L) { lua_State *luaE_newthread (lua_State *L) {
lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State))); lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));
luaC_link(L, obj2gco(L1), LUA_TTHREAD); luaC_link(L, obj2gco(L1), LUA_TTHREAD);
setthvalue(L, L->top, L1); /* put thread on stack */ setthvalue(L, L->top, L1); /* put thread on stack */
...@@ -133,7 +133,7 @@ lua_State *ICACHE_FLASH_ATTR luaE_newthread (lua_State *L) { ...@@ -133,7 +133,7 @@ lua_State *ICACHE_FLASH_ATTR luaE_newthread (lua_State *L) {
} }
void ICACHE_FLASH_ATTR luaE_freethread (lua_State *L, lua_State *L1) { void luaE_freethread (lua_State *L, lua_State *L1) {
luaF_close(L1, L1->stack); /* close all upvalues for this thread */ luaF_close(L1, L1->stack); /* close all upvalues for this thread */
lua_assert(L1->openupval == NULL); lua_assert(L1->openupval == NULL);
luai_userstatefree(L1); luai_userstatefree(L1);
...@@ -142,7 +142,7 @@ void ICACHE_FLASH_ATTR luaE_freethread (lua_State *L, lua_State *L1) { ...@@ -142,7 +142,7 @@ void ICACHE_FLASH_ATTR luaE_freethread (lua_State *L, lua_State *L1) {
} }
LUA_API lua_State *ICACHE_FLASH_ATTR lua_newstate (lua_Alloc f, void *ud) { LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
int i; int i;
lua_State *L; lua_State *L;
global_State *g; global_State *g;
...@@ -205,7 +205,7 @@ LUA_API lua_State *ICACHE_FLASH_ATTR lua_newstate (lua_Alloc f, void *ud) { ...@@ -205,7 +205,7 @@ LUA_API lua_State *ICACHE_FLASH_ATTR lua_newstate (lua_Alloc f, void *ud) {
} }
static void ICACHE_FLASH_ATTR callallgcTM (lua_State *L, void *ud) { static void callallgcTM (lua_State *L, void *ud) {
UNUSED(ud); UNUSED(ud);
luaC_callGCTM(L); /* call GC metamethods for all udata */ luaC_callGCTM(L); /* call GC metamethods for all udata */
} }
...@@ -214,15 +214,15 @@ static void ICACHE_FLASH_ATTR callallgcTM (lua_State *L, void *ud) { ...@@ -214,15 +214,15 @@ static void ICACHE_FLASH_ATTR callallgcTM (lua_State *L, void *ud) {
extern lua_State *luaL_newstate (void); extern lua_State *luaL_newstate (void);
static lua_State *lua_crtstate; static lua_State *lua_crtstate;
lua_State *ICACHE_FLASH_ATTR lua_open(void) { lua_State *lua_open(void) {
lua_crtstate = luaL_newstate(); lua_crtstate = luaL_newstate();
return lua_crtstate; return lua_crtstate;
} }
lua_State *ICACHE_FLASH_ATTR lua_getstate(void) { lua_State *lua_getstate(void) {
return lua_crtstate; return lua_crtstate;
} }
LUA_API void ICACHE_FLASH_ATTR lua_close (lua_State *L) { LUA_API void lua_close (lua_State *L) {
#ifndef LUA_CROSS_COMPILER #ifndef LUA_CROSS_COMPILER
lua_sethook( L, NULL, 0, 0 ); lua_sethook( L, NULL, 0, 0 );
lua_crtstate = NULL; lua_crtstate = NULL;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#define LUAS_READONLY_STRING 1 #define LUAS_READONLY_STRING 1
#define LUAS_REGULAR_STRING 0 #define LUAS_REGULAR_STRING 0
void ICACHE_FLASH_ATTR luaS_resize (lua_State *L, int newsize) { void luaS_resize (lua_State *L, int newsize) {
stringtable *tb; stringtable *tb;
int i; int i;
tb = &G(L)->strt; tb = &G(L)->strt;
...@@ -51,7 +51,7 @@ void ICACHE_FLASH_ATTR luaS_resize (lua_State *L, int newsize) { ...@@ -51,7 +51,7 @@ void ICACHE_FLASH_ATTR luaS_resize (lua_State *L, int newsize) {
unset_resizing_strings_gc(L); unset_resizing_strings_gc(L);
} }
static TString *ICACHE_FLASH_ATTR newlstr (lua_State *L, const char *str, size_t l, static TString *newlstr (lua_State *L, const char *str, size_t l,
unsigned int h, int readonly) { unsigned int h, int readonly) {
TString *ts; TString *ts;
stringtable *tb; stringtable *tb;
...@@ -80,7 +80,7 @@ static TString *ICACHE_FLASH_ATTR newlstr (lua_State *L, const char *str, size_t ...@@ -80,7 +80,7 @@ static TString *ICACHE_FLASH_ATTR newlstr (lua_State *L, const char *str, size_t
} }
static TString *ICACHE_FLASH_ATTR luaS_newlstr_helper (lua_State *L, const char *str, size_t l, int readonly) { static TString *luaS_newlstr_helper (lua_State *L, const char *str, size_t l, int readonly) {
GCObject *o; GCObject *o;
unsigned int h = cast(unsigned int, l); /* seed */ unsigned int h = cast(unsigned int, l); /* seed */
size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */ size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
...@@ -100,7 +100,7 @@ static TString *ICACHE_FLASH_ATTR luaS_newlstr_helper (lua_State *L, const char ...@@ -100,7 +100,7 @@ static TString *ICACHE_FLASH_ATTR luaS_newlstr_helper (lua_State *L, const char
return newlstr(L, str, l, h, readonly); /* not found */ return newlstr(L, str, l, h, readonly); /* not found */
} }
static int ICACHE_FLASH_ATTR lua_is_ptr_in_ro_area(const char *p) { static int lua_is_ptr_in_ro_area(const char *p) {
#ifdef LUA_CROSS_COMPILER #ifdef LUA_CROSS_COMPILER
return 0; return 0;
#else #else
...@@ -111,7 +111,7 @@ static int ICACHE_FLASH_ATTR lua_is_ptr_in_ro_area(const char *p) { ...@@ -111,7 +111,7 @@ static int ICACHE_FLASH_ATTR lua_is_ptr_in_ro_area(const char *p) {
#endif #endif
} }
TString *ICACHE_FLASH_ATTR luaS_newlstr (lua_State *L, const char *str, size_t l) { TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
// If the pointer is in a read-only memory and the string is at least 4 chars in length, // If the pointer is in a read-only memory and the string is at least 4 chars in length,
// create it as a read-only string instead // create it as a read-only string instead
if(lua_is_ptr_in_ro_area(str) && l+1 > sizeof(char**) && l == c_strlen(str)) if(lua_is_ptr_in_ro_area(str) && l+1 > sizeof(char**) && l == c_strlen(str))
...@@ -121,7 +121,7 @@ TString *ICACHE_FLASH_ATTR luaS_newlstr (lua_State *L, const char *str, size_t l ...@@ -121,7 +121,7 @@ TString *ICACHE_FLASH_ATTR luaS_newlstr (lua_State *L, const char *str, size_t l
} }
LUAI_FUNC TString *ICACHE_FLASH_ATTR luaS_newrolstr (lua_State *L, const char *str, size_t l) { LUAI_FUNC TString *luaS_newrolstr (lua_State *L, const char *str, size_t l) {
if(l+1 > sizeof(char**) && l == c_strlen(str)) if(l+1 > sizeof(char**) && l == c_strlen(str))
return luaS_newlstr_helper(L, str, l, LUAS_READONLY_STRING); return luaS_newlstr_helper(L, str, l, LUAS_READONLY_STRING);
else // no point in creating a RO string, as it would actually be larger else // no point in creating a RO string, as it would actually be larger
...@@ -129,7 +129,7 @@ LUAI_FUNC TString *ICACHE_FLASH_ATTR luaS_newrolstr (lua_State *L, const char *s ...@@ -129,7 +129,7 @@ LUAI_FUNC TString *ICACHE_FLASH_ATTR luaS_newrolstr (lua_State *L, const char *s
} }
Udata *ICACHE_FLASH_ATTR luaS_newudata (lua_State *L, size_t s, Table *e) { Udata *luaS_newudata (lua_State *L, size_t s, Table *e) {
Udata *u; Udata *u;
if (s > MAX_SIZET - sizeof(Udata)) if (s > MAX_SIZET - sizeof(Udata))
luaM_toobig(L); luaM_toobig(L);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -28,7 +28,7 @@ const char *const luaT_typenames[] = { ...@@ -28,7 +28,7 @@ const char *const luaT_typenames[] = {
}; };
void ICACHE_FLASH_ATTR luaT_init (lua_State *L) { void luaT_init (lua_State *L) {
static const char *const luaT_eventname[] = { /* ORDER TM */ static const char *const luaT_eventname[] = { /* ORDER TM */
"__index", "__newindex", "__index", "__newindex",
"__gc", "__mode", "__eq", "__gc", "__mode", "__eq",
...@@ -48,7 +48,7 @@ void ICACHE_FLASH_ATTR luaT_init (lua_State *L) { ...@@ -48,7 +48,7 @@ void ICACHE_FLASH_ATTR luaT_init (lua_State *L) {
** function to be used with macro "fasttm": optimized for absence of ** function to be used with macro "fasttm": optimized for absence of
** tag methods ** tag methods
*/ */
const TValue *ICACHE_FLASH_ATTR luaT_gettm (Table *events, TMS event, TString *ename) { const TValue *luaT_gettm (Table *events, TMS event, TString *ename) {
const TValue *tm = luaR_isrotable(events) ? luaH_getstr_ro(events, ename) : luaH_getstr(events, ename); const TValue *tm = luaR_isrotable(events) ? luaH_getstr_ro(events, ename) : luaH_getstr(events, ename);
lua_assert(event <= TM_EQ); lua_assert(event <= TM_EQ);
if (ttisnil(tm)) { /* no tag method? */ if (ttisnil(tm)) { /* no tag method? */
...@@ -60,7 +60,7 @@ const TValue *ICACHE_FLASH_ATTR luaT_gettm (Table *events, TMS event, TString *e ...@@ -60,7 +60,7 @@ const TValue *ICACHE_FLASH_ATTR luaT_gettm (Table *events, TMS event, TString *e
} }
const TValue *ICACHE_FLASH_ATTR luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) { const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, TMS event) {
Table *mt; Table *mt;
switch (ttype(o)) { switch (ttype(o)) {
case LUA_TTABLE: case LUA_TTABLE:
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment