Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
5d28de85
Commit
5d28de85
authored
Nov 06, 2015
by
Johny Mattsson
Browse files
Merge pull request #722 from TerryE/luac-cross.2
Moving luac cross from master to dev
parents
10c4ac14
0beee5c1
Changes
44
Hide whitespace changes
Inline
Side-by-side
app/include/user_modules.h
View file @
5d28de85
...
...
@@ -8,8 +8,10 @@
// #define LUA_USE_BUILTIN_IO // for io.xxx(), partially work
// #define LUA_USE_BUILTIN_OS // for os.xxx(), not work
// #define LUA_USE_BUILTIN_DEBUG // for debug.xxx(), not work
// #define LUA_USE_BUILTIN_DEBUG
#define LUA_USE_BUILTIN_DEBUG_MINIMAL // for debug.getregistry() and debug.traceback()
#ifndef LUA_CROSS_COMPILER
#define LUA_USE_MODULES
#ifdef LUA_USE_MODULES
...
...
@@ -46,5 +48,6 @@
//#define LUA_USE_MODULES_HX711
#endif
/* LUA_USE_MODULES */
#endif
#endif
/* __USER_MODULES_H__ */
app/libc/c_stdlib.c
View file @
5d28de85
//#include "user_interface.h"
#include "user_config.h"
#ifdef LUA_CROSS_COMPILER
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#define ICACHE_RODATA_ATTR
#define TRUE 1
#define FALSE 0
#else
#include "c_stdlib.h"
#include "c_stdio.h"
#include "c_types.h"
#include "c_string.h"
#include "user_interface.h"
#include "user_config.h"
// const char *lua_init_value = "print(\"Hello world\")";
const
char
*
lua_init_value
=
"@init.lua"
;
...
...
@@ -21,7 +32,6 @@ const char *c_getenv(const char *__string)
}
return
NULL
;
}
// make sure there is enough memory before real malloc, otherwise malloc will panic and reset
// void *c_malloc(size_t __size){
// if(__size>system_get_free_heap_size()){
...
...
@@ -43,7 +53,8 @@ const char *c_getenv(const char *__string)
// // NODE_ERR("free1: %d\n", system_get_free_heap_size());
// os_free(p);
// // NODE_ERR("-free1: %d\n", system_get_free_heap_size());
// }
// }c_stdlib.s
// int c_rand(void){
...
...
@@ -55,9 +66,8 @@ const char *c_getenv(const char *__string)
// }
#include <_ansi.h>
//#include <reent.h>
#include <string.h>
//#include "mprec.h"
#endif
double
powersOf10
[]
ICACHE_STORE_ATTR
ICACHE_RODATA_ATTR
=
/* Table giving binary powers of 10. Entry */
{
10
.,
/* is 10^2^i. Used to convert decimal */
...
...
app/lua/lapi.c
View file @
5d28de85
...
...
@@ -4,17 +4,15 @@
** See Copyright Notice in lua.h
*/
//#include "c_assert.h"
#include "c_math.h"
#include "c_stdarg.h"
#include "c_string.h"
#define lapi_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
//#include C_HEADER_ASSERT
#include C_HEADER_MATH
#include C_HEADER_STRING
#include "lapi.h"
#include "ldebug.h"
#include "ldo.h"
...
...
app/lua/lauxlib.c
View file @
5d28de85
...
...
@@ -4,14 +4,18 @@
** See Copyright Notice in lua.h
*/
#define LUAC_CROSS_FILE
#include "c_ctype.h"
// #include "c_errno.h"
#include "c_stdarg.h"
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_string.h"
#include "lua.h"
#include C_HEADER_CTYPE
#include C_HEADER_ERRNO
#include C_HEADER_STDIO
#include C_HEADER_STDLIB
#include C_HEADER_STRING
#ifndef LUA_CROSS_COMPILER
#include "flash_fs.h"
#else
#endif
/* This file uses only the official API of Lua.
** Any function declared here could be written as an application function.
...
...
@@ -20,8 +24,6 @@
#define lauxlib_c
#define LUA_LIB
#include "lua.h"
#include "lrotable.h"
#include "lauxlib.h"
...
...
@@ -573,7 +575,7 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
** =======================================================
*/
#if
0
#if
def LUA_CROSS_COMPILER
typedef
struct
LoadF
{
int
extraline
;
...
...
@@ -647,7 +649,7 @@ LUALIB_API int luaL_loadfile (lua_State *L, const char *filename) {
#else
#include
"c_fcntl.h"
#include
C_HEADER_FCNTL
typedef
struct
LoadFSF
{
int
extraline
;
...
...
app/lua/lauxlib.h
View file @
5d28de85
...
...
@@ -9,11 +9,14 @@
#define lauxlib_h
//#include "c_stddef.h"
#include "c_stdio.h"
#include "lua.h"
#ifdef LUA_CROSS_COMPILER
#include <stdio.h>
#else
#include "c_stdio.h"
#endif
#if defined(LUA_COMPAT_GETN)
LUALIB_API
int
(
luaL_getn
)
(
lua_State
*
L
,
int
t
);
...
...
@@ -79,7 +82,7 @@ LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
LUALIB_API
int
(
luaL_ref
)
(
lua_State
*
L
,
int
t
);
LUALIB_API
void
(
luaL_unref
)
(
lua_State
*
L
,
int
t
,
int
ref
);
#if
0
#if
def LUA_CROSS_COMPILER
LUALIB_API
int
(
luaL_loadfile
)
(
lua_State
*
L
,
const
char
*
filename
);
#else
LUALIB_API
int
(
luaL_loadfsfile
)
(
lua_State
*
L
,
const
char
*
filename
);
...
...
app/lua/lbaselib.c
View file @
5d28de85
...
...
@@ -6,16 +6,14 @@
#include "c_ctype.h"
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_string.h"
#define lbaselib_c
#define LUA_LIB
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STDIO
#include C_HEADER_STRING
#include C_HEADER_STDLIB
#include "lauxlib.h"
#include "lualib.h"
#include "lrotable.h"
...
...
@@ -295,7 +293,7 @@ static int luaB_loadstring (lua_State *L) {
static
int
luaB_loadfile
(
lua_State
*
L
)
{
const
char
*
fname
=
luaL_optstring
(
L
,
1
,
NULL
);
#if
0
#if
def LUA_CROSS_COMPILER
return
load_aux
(
L
,
luaL_loadfile
(
L
,
fname
));
#else
return
load_aux
(
L
,
luaL_loadfsfile
(
L
,
fname
));
...
...
@@ -342,7 +340,7 @@ static int luaB_load (lua_State *L) {
static
int
luaB_dofile
(
lua_State
*
L
)
{
const
char
*
fname
=
luaL_optstring
(
L
,
1
,
NULL
);
int
n
=
lua_gettop
(
L
);
#if
0
#if
def LUA_CROSS_COMPILER
if
(
luaL_loadfile
(
L
,
fname
)
!=
0
)
lua_error
(
L
);
#else
if
(
luaL_loadfsfile
(
L
,
fname
)
!=
0
)
lua_error
(
L
);
...
...
app/lua/lcode.c
View file @
5d28de85
...
...
@@ -5,12 +5,12 @@
*/
#include "c_stdlib.h"
#define lcode_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STDLIB
#include "lcode.h"
#include "ldebug.h"
...
...
app/lua/
not_used/
ldblib.c
→
app/lua/ldblib.c
View file @
5d28de85
...
...
@@ -5,18 +5,19 @@
*/
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_string.h"
#define ldblib_c
#define LUA_LIB
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STDIO
#include C_HEADER_STDLIB
#include C_HEADER_STRING
#include "lauxlib.h"
#include "lualib.h"
#include "lrotable.h"
#include "user_modules.h"
...
...
@@ -25,6 +26,7 @@ static int db_getregistry (lua_State *L) {
return
1
;
}
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
static
int
db_getmetatable
(
lua_State
*
L
)
{
luaL_checkany
(
L
,
1
);
...
...
@@ -73,7 +75,7 @@ static void settabsi (lua_State *L, const char *i, int v) {
lua_setfield
(
L
,
-
2
,
i
);
}
#endif
static
lua_State
*
getthread
(
lua_State
*
L
,
int
*
arg
)
{
if
(
lua_isthread
(
L
,
1
))
{
*
arg
=
1
;
...
...
@@ -84,7 +86,7 @@ static lua_State *getthread (lua_State *L, int *arg) {
return
L
;
}
}
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
static
void
treatstackoption
(
lua_State
*
L
,
lua_State
*
L1
,
const
char
*
fname
)
{
if
(
L
==
L1
)
{
...
...
@@ -324,7 +326,7 @@ static int db_debug (lua_State *L) {
lua_settop
(
L
,
0
);
/* remove eventual returns */
}
}
#endif
#define LEVELS1 12
/* size of the first part of the stack */
#define LEVELS2 10
/* size of the second part of the stack */
...
...
@@ -384,12 +386,15 @@ 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
{
LSTRKEY
(
"debug"
),
LFUNCVAL
(
db_debug
)},
{
LSTRKEY
(
"getfenv"
),
LFUNCVAL
(
db_getfenv
)},
{
LSTRKEY
(
"gethook"
),
LFUNCVAL
(
db_gethook
)},
{
LSTRKEY
(
"getinfo"
),
LFUNCVAL
(
db_getinfo
)},
{
LSTRKEY
(
"getlocal"
),
LFUNCVAL
(
db_getlocal
)},
#endif
{
LSTRKEY
(
"getregistry"
),
LFUNCVAL
(
db_getregistry
)},
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
{
LSTRKEY
(
"getmetatable"
),
LFUNCVAL
(
db_getmetatable
)},
{
LSTRKEY
(
"getupvalue"
),
LFUNCVAL
(
db_getupvalue
)},
{
LSTRKEY
(
"setfenv"
),
LFUNCVAL
(
db_setfenv
)},
...
...
@@ -397,6 +402,7 @@ const LUA_REG_TYPE dblib[] = {
{
LSTRKEY
(
"setlocal"
),
LFUNCVAL
(
db_setlocal
)},
{
LSTRKEY
(
"setmetatable"
),
LFUNCVAL
(
db_setmetatable
)},
{
LSTRKEY
(
"setupvalue"
),
LFUNCVAL
(
db_setupvalue
)},
#endif
{
LSTRKEY
(
"traceback"
),
LFUNCVAL
(
db_errorfb
)},
{
LNILKEY
,
LNILVAL
}
};
...
...
app/lua/ldebug.c
View file @
5d28de85
...
...
@@ -5,15 +5,12 @@
*/
#include "c_stdarg.h"
#include "c_stddef.h"
#include "c_string.h"
#define ldebug_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STRING
#include "lapi.h"
#include "lcode.h"
...
...
app/lua/ldo.c
View file @
5d28de85
...
...
@@ -4,15 +4,14 @@
** See Copyright Notice in lua.h
*/
#include <setjmp.h>
#include "c_stdlib.h"
#include "c_string.h"
#define ldo_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STRING
#include "ldebug.h"
#include "ldo.h"
...
...
app/lua/ldump.c
View file @
5d28de85
...
...
@@ -4,13 +4,12 @@
** See Copyright Notice in lua.h
*/
#include "c_stddef.h"
#include "c_string.h"
#define ldump_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STRING
#include "lobject.h"
#include "lstate.h"
...
...
app/lua/lfunc.c
View file @
5d28de85
...
...
@@ -4,11 +4,9 @@
** See Copyright Notice in lua.h
*/
#include "c_stddef.h"
#define lfunc_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
...
...
app/lua/lgc.c
View file @
5d28de85
...
...
@@ -4,12 +4,12 @@
** See Copyright Notice in lua.h
*/
#include "c_string.h"
#define lgc_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STRING
#include "ldebug.h"
#include "ldo.h"
...
...
app/lua/llex.c
View file @
5d28de85
...
...
@@ -5,14 +5,14 @@
*/
#include "c_ctype.h"
#include "c_locale.h"
#include "c_string.h"
#define llex_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_CTYPE
#include C_HEADER_LOCALE
#include C_HEADER_STRING
#include "ldo.h"
#include "llex.h"
...
...
app/lua/llimits.h
View file @
5d28de85
...
...
@@ -9,12 +9,9 @@
//#include "c_limits.h"
//#include "c_stddef.h"
#include "lua.h"
typedef
LUAI_UINT32
lu_int32
;
typedef
LUAI_UMEM
lu_mem
;
...
...
app/lua/lmathlib.c
View file @
5d28de85
...
...
@@ -5,13 +5,13 @@
*/
#include "c_stdlib.h"
#include "c_math.h"
#define lmathlib_c
#define LUA_LIB
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STDLIB
#include C_HEADER_MATH
#include "lauxlib.h"
#include "lualib.h"
...
...
@@ -35,7 +35,7 @@ static int math_abs (lua_State *L) {
}
#ifndef LUA_NUMBER_INTEGRAL
#if 0
static int math_sin (lua_State *L) {
lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
return 1;
...
...
@@ -85,6 +85,7 @@ static int math_atan2 (lua_State *L) {
lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
return 1;
}
#endif
static
int
math_ceil
(
lua_State
*
L
)
{
lua_pushnumber
(
L
,
ceil
(
luaL_checknumber
(
L
,
1
)));
...
...
@@ -95,7 +96,7 @@ static int math_floor (lua_State *L) {
lua_pushnumber
(
L
,
floor
(
luaL_checknumber
(
L
,
1
)));
return
1
;
}
#if 0
static int math_fmod (lua_State *L) {
lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
return 1;
...
...
@@ -108,6 +109,7 @@ static int math_modf (lua_State *L) {
lua_pushnumber(L, fp);
return 2;
}
#endif
#else // #ifndef LUA_NUMBER_INTEGRAL
...
...
@@ -173,7 +175,7 @@ static int math_pow (lua_State *L) {
#ifndef LUA_NUMBER_INTEGRAL
#if 0
static int math_log (lua_State *L) {
lua_pushnumber(L, log(luaL_checknumber(L, 1)));
return 1;
...
...
@@ -210,6 +212,7 @@ static int math_ldexp (lua_State *L) {
lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
return 1;
}
#endif
#endif // #ifdef LUA_NUMBER_INTEGRAL
...
...
@@ -306,6 +309,8 @@ static int math_randomseed (lua_State *L) {
return
0
;
}
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const
LUA_REG_TYPE
math_map
[]
=
{
...
...
app/lua/lmem.c
View file @
5d28de85
...
...
@@ -5,10 +5,9 @@
*/
#include "c_stddef.h"
#define lmem_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
...
...
app/lua/lmem.h
View file @
5d28de85
...
...
@@ -8,7 +8,11 @@
#define lmem_h
//#ifdef LUA_CROSS_COMPILER
//#include <stddef.h>
//#else
//#include "c_stddef.h"
//#endif
#include "llimits.h"
#include "lua.h"
...
...
app/lua/loadlib.c
View file @
5d28de85
...
...
@@ -9,15 +9,18 @@
*/
#include "c_stdlib.h"
#include "c_string.h"
#include "c_fcntl.h"
#include "flash_fs.h"
#define loadlib_c
#define LUA_LIB
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STDLIB
#include C_HEADER_STRING
#include C_HEADER_FCNTL
#ifndef LUA_CROSS_COMPILER
#include "flash_fs.h"
#endif
#include "lauxlib.h"
#include "lualib.h"
...
...
@@ -328,7 +331,7 @@ static int ll_loadlib (lua_State *L) {
** 'require' function
** =======================================================
*/
#if
0
#if
def LUA_CROSS_COMPILER
static
int
readable
(
const
char
*
filename
)
{
FILE
*
f
=
c_fopen
(
filename
,
"r"
);
/* try to open file */
if
(
f
==
NULL
)
return
0
;
/* open failed */
...
...
@@ -389,7 +392,7 @@ static int loader_Lua (lua_State *L) {
const
char
*
name
=
luaL_checkstring
(
L
,
1
);
filename
=
findfile
(
L
,
name
,
"path"
);
if
(
filename
==
NULL
)
return
1
;
/* library not found in this path */
#if
0
#if
def LUA_CROSS_COMPILER
if
(
luaL_loadfile
(
L
,
filename
)
!=
0
)
#else
if
(
luaL_loadfsfile
(
L
,
filename
)
!=
0
)
...
...
app/lua/lobject.c
View file @
5d28de85
...
...
@@ -4,16 +4,15 @@
** See Copyright Notice in lua.h
*/
#include "c_ctype.h"
#include "c_stdarg.h"
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_string.h"
#define lobject_c
#define LUA_CORE
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STDIO
#include C_HEADER_STRING
#include C_HEADER_STDLIB
#include "ldo.h"
#include "lmem.h"
...
...
@@ -21,9 +20,11 @@
#include "lstate.h"
#include "lstring.h"
#include "lvm.h"
#ifndef LUA_CROSS_COMPILER
#include "flash_api.h"
#else
#include <limits.h>
#endif
const
TValue
luaO_nilobject_
=
{
LUA_TVALUE_NIL
};
...
...
@@ -64,9 +65,11 @@ int luaO_log2 (unsigned int x) {
};
int
l
=
-
1
;
while
(
x
>=
256
)
{
l
+=
8
;
x
>>=
8
;
}
// return l + log_2[x];
#ifdef LUA_CROSS_COMPILER
return
l
+
log_2
[
x
];
#else
return
l
+
byte_of_aligned_array
(
log_2
,
x
);
#endif
}
...
...
@@ -95,7 +98,21 @@ int luaO_str2d (const char *s, lua_Number *result) {
*
result
=
lua_str2number
(
s
,
&
endptr
);
if
(
endptr
==
s
)
return
0
;
/* conversion failed */
if
(
*
endptr
==
'x'
||
*
endptr
==
'X'
)
/* maybe an hexadecimal constant? */
#if defined(LUA_CROSS_COMPILER)
{
long
lres
=
strtoul
(
s
,
&
endptr
,
16
);
#if LONG_MAX != 2147483647L
if
(
lres
&
~
0xffffffffL
)
*
result
=
cast_num
(
-
1
);
else
if
(
lres
&
0x80000000L
)
*
result
=
cast_num
(
lres
|
~
0x7fffffffL
);
else
#endif
*
result
=
cast_num
(
lres
);
}
#else
*
result
=
cast_num
(
c_strtoul
(
s
,
&
endptr
,
16
));
#endif
if
(
*
endptr
==
'\0'
)
return
1
;
/* most common case */
while
(
isspace
(
cast
(
unsigned
char
,
*
endptr
)))
endptr
++
;
if
(
*
endptr
!=
'\0'
)
return
0
;
/* invalid trailing characters? */
...
...
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment