Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
1990f957
"client-libraries/lua/LICENSE" did not exist on "ed9b544e10b84cd43348ddfab7068b610a5df1f7"
Unverified
Commit
1990f957
authored
May 08, 2019
by
Terry Ellison
Committed by
GitHub
May 08, 2019
Browse files
Updated ROTables 1st tranch (#2742)
Updated ROTables
parent
e0f3dbed
Changes
90
Hide whitespace changes
Inline
Side-by-side
app/Makefile
View file @
1990f957
...
...
@@ -138,8 +138,6 @@ DEPENDS_eagle.app.v6 = \
# -DWLAN_CONFIG_CCX
CONFIGURATION_DEFINES
=
-D__ets__
\
-DICACHE_FLASH
\
-DLUA_OPTIMIZE_MEMORY
=
2
\
-DMIN_OPT_LEVEL
=
2
\
-DLWIP_OPEN_SRC
\
-DPBUF_RSV_FOR_WLAN
\
-DEBUF_LWIP
\
...
...
app/include/module.h
View file @
1990f957
...
...
@@ -2,7 +2,7 @@
#define __MODULE_H__
#include "user_modules.h"
#include "lro
defs
.h"
#include "lro
table
.h"
/* Registering a module within NodeMCU is really easy these days!
*
...
...
@@ -18,11 +18,11 @@
*
* Then simply put a line like this at the bottom of your module file:
*
* NODEMCU_MODULE(MYNAME, "myname", myname
_map
, luaopen_myname);
* NODEMCU_MODULE(MYNAME, "myname", myname, luaopen_myname);
*
* or perhaps
*
* NODEMCU_MODULE(MYNAME, "myname", myname
_map
, NULL);
* NODEMCU_MODULE(MYNAME, "myname", myname, NULL);
*
* if you don't need an init function.
*
...
...
@@ -67,13 +67,8 @@
*/
#define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \
const LOCK_IN_SECTION(libs) \
lua
L_Reg
MODULE_PASTE_(lua_lib_,cfgname) = { luaname, initfunc }; \
lua
R_entry
MODULE_PASTE_(lua_lib_,cfgname) = { luaname,
LRO_FUNCVAL(
initfunc
)
}; \
const LOCK_IN_SECTION(rotable) \
luaR_entry MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(LUA_USE_MODULES_,cfgname))) \
= {LSTRKEY(luaname), LROVAL(map)}
#if !defined(LUA_CROSS_COMPILER) && !(MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2)
# error "NodeMCU modules must be built with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
#endif
= {luaname, LRO_ROVAL(map ## _map)}
#endif
app/include/pm/pmSleep.h
View file @
1990f957
...
...
@@ -24,23 +24,17 @@
#define PMSLEEP_ERR(...)
#endif
#define PMSLEEP_SLEEP_MIN_TIME 50000
#define PMSLEEP_SLEEP_MAX_TIME 268435454 //FPM_MAX_SLEEP_TIME-1
#define pmSleep_INIT_CFG(X) pmSleep_param_t X = {.sleep_duration=0, .wake_pin=255, \
.preserve_opmode=TRUE, .suspend_cb_ptr=NULL, .resume_cb_ptr=NULL}
#define PMSLEEP_INT_MAP \
{ LSTRKEY( "INT_BOTH" ), LNUMVAL( GPIO_PIN_INTR_ANYEDGE ) }, \
{ LSTRKEY( "INT_UP" ), LNUMVAL( GPIO_PIN_INTR_POSEDGE ) }, \
{ LSTRKEY( "INT_DOWN" ), LNUMVAL( GPIO_PIN_INTR_NEGEDGE ) }, \
{ LSTRKEY( "INT_HIGH" ), LNUMVAL( GPIO_PIN_INTR_HILEVEL ) }, \
{ LSTRKEY( "INT_LOW" ), LNUMVAL( GPIO_PIN_INTR_LOLEVEL ) }
LROT_NUMENTRY( INT_BOTH, GPIO_PIN_INTR_ANYEDGE ) \
LROT_NUMENTRY( INT_UP, GPIO_PIN_INTR_POSEDGE ) \
LROT_NUMENTRY( INT_DOWN, GPIO_PIN_INTR_NEGEDGE ) \
LROT_NUMENTRY( INT_HIGH, GPIO_PIN_INTR_HILEVEL ) \
LROT_NUMENTRY( INT_LOW, GPIO_PIN_INTR_LOLEVEL )
typedef
struct
pmSleep_param
{
uint32
sleep_duration
;
...
...
app/include/user_config.h
View file @
1990f957
...
...
@@ -244,7 +244,7 @@ extern void luaL_dbgbreak(void);
#endif
#endif
#if !defined(LUA_NUMBER_INTEGRAL) && defined (LUA_DWORD_ALIGNED_TVALUES)
#if !defined(LUA_NUMBER_INTEGRAL) &&
!
defined (LUA_DWORD_ALIGNED_TVALUES)
#define LUA_PACK_TVALUES
#else
#undef LUA_PACK_TVALUES
...
...
app/lua/lauxlib.c
View file @
1990f957
...
...
@@ -419,11 +419,7 @@ LUALIB_API void (luaL_register) (lua_State *L, const char *libname,
LUALIB_API
void
(
luaL_register_light
)
(
lua_State
*
L
,
const
char
*
libname
,
const
luaL_Reg
*
l
)
{
#if LUA_OPTIMIZE_MEMORY > 0
luaI_openlib
(
L
,
libname
,
l
,
0
,
LUA_USELIGHTFUNCTIONS
);
#else
luaI_openlib
(
L
,
libname
,
l
,
0
,
LUA_USECCLOSURES
);
#endif
}
static
int
libsize
(
const
luaL_Reg
*
l
)
{
...
...
app/lua/lbaselib.c
View file @
1990f957
...
...
@@ -16,7 +16,7 @@
#include C_HEADER_STDLIB
#include "lauxlib.h"
#include "lualib.h"
#include "lro
defs
.h"
#include "lro
table
.h"
...
...
@@ -462,64 +462,59 @@ static int luaB_newproxy (lua_State *L) {
return
1
;
}
#include "lro
defs
.h"
#include "lro
table
.h"
extern
const
luaR_entry
lua_rotable_base
[]
;
LROT_EXTERN
(
lua_rotable_base
)
;
/*
* ESP builds use specific linker directives to marshal all ROTable declarations
* into a single ROTable in the PSECT ".lua_rotable".
* Separate ROTables are used for the base functions and library ROTables, with
* the base functions ROTable declared below. The library ROTable is chained
* from this using its __index meta-method.
*
* This is not practical on Posix builds using a standard link so for cross
* compiler builds, separate ROTables are used for the base functions and library
* ROTables, with the latter chained from the former using its __index meta-method.
* In this case all library ROTables are defined in linit.c.
* ESP builds use specific linker directives to marshal all the ROTable entries
* for the library modules into a single ROTable in the PSECT ".lua_rotable".
* This is not practical on Posix builds using a standard GNU link, so the
* equivalent ROTable for the core libraries defined in linit.c for the cross-
* compiler build.
*/
#ifdef LUA_CROSS_COMPILER
#define BASE_ROTABLE base_func_map
#define LOCK_IN_ROTABLE
static
const
LUA_REG_TYPE
base_func_meta
[]
=
{
LROT_TABENTRY
(
__index
,
lua_rotable_base
),
LROT_END
};
#else
#define BASE_ROTABLE lua_rotable_base
#define LOCK_IN_ROTABLE __attribute__((used,unused,section(".lua_rotable")))
#endif
static
const
LUA_REG_TYPE
LOCK_IN_ROTABLE
base_func_map
[]
=
{
LROT_FUNCENTRY
(
assert
,
luaB_assert
),
LROT_FUNCENTRY
(
collectgarbage
,
luaB_collectgarbage
),
LROT_FUNCENTRY
(
dofile
,
luaB_dofile
),
LROT_FUNCENTRY
(
error
,
luaB_error
),
LROT_FUNCENTRY
(
gcinfo
,
luaB_gcinfo
),
LROT_FUNCENTRY
(
getfenv
,
luaB_getfenv
),
LROT_FUNCENTRY
(
getmetatable
,
luaB_getmetatable
),
LROT_FUNCENTRY
(
loadfile
,
luaB_loadfile
),
LROT_FUNCENTRY
(
load
,
luaB_load
),
LROT_FUNCENTRY
(
loadstring
,
luaB_loadstring
),
LROT_FUNCENTRY
(
next
,
luaB_next
),
LROT_FUNCENTRY
(
pcall
,
luaB_pcall
),
LROT_FUNCENTRY
(
print
,
luaB_print
),
LROT_FUNCENTRY
(
rawequal
,
luaB_rawequal
),
LROT_FUNCENTRY
(
rawget
,
luaB_rawget
),
LROT_FUNCENTRY
(
rawset
,
luaB_rawset
),
LROT_FUNCENTRY
(
select
,
luaB_select
),
LROT_FUNCENTRY
(
setfenv
,
luaB_setfenv
),
LROT_FUNCENTRY
(
setmetatable
,
luaB_setmetatable
),
LROT_FUNCENTRY
(
tonumber
,
luaB_tonumber
),
LROT_FUNCENTRY
(
tostring
,
luaB_tostring
),
LROT_FUNCENTRY
(
type
,
luaB_type
),
LROT_FUNCENTRY
(
unpack
,
luaB_unpack
),
LROT_EXTERN
(
lua_rotables
);
LROT_PUBLIC_BEGIN
(
base_func_meta
)
LROT_TABENTRY
(
__index
,
lua_rotables
)
LROT_END
(
base_func
,
base_func_meta
,
LROT_MASK_INDEX
)
LROT_PUBLIC_BEGIN
(
base_func
)
LROT_FUNCENTRY
(
assert
,
luaB_assert
)
LROT_FUNCENTRY
(
collectgarbage
,
luaB_collectgarbage
)
LROT_FUNCENTRY
(
dofile
,
luaB_dofile
)
LROT_FUNCENTRY
(
error
,
luaB_error
)
LROT_FUNCENTRY
(
gcinfo
,
luaB_gcinfo
)
LROT_FUNCENTRY
(
getfenv
,
luaB_getfenv
)
LROT_FUNCENTRY
(
getmetatable
,
luaB_getmetatable
)
LROT_FUNCENTRY
(
loadfile
,
luaB_loadfile
)
LROT_FUNCENTRY
(
load
,
luaB_load
)
LROT_FUNCENTRY
(
loadstring
,
luaB_loadstring
)
LROT_FUNCENTRY
(
next
,
luaB_next
)
LROT_FUNCENTRY
(
pcall
,
luaB_pcall
)
LROT_FUNCENTRY
(
print
,
luaB_print
)
LROT_FUNCENTRY
(
rawequal
,
luaB_rawequal
)
LROT_FUNCENTRY
(
rawget
,
luaB_rawget
)
LROT_FUNCENTRY
(
rawset
,
luaB_rawset
)
LROT_FUNCENTRY
(
select
,
luaB_select
)
LROT_FUNCENTRY
(
setfenv
,
luaB_setfenv
)
LROT_FUNCENTRY
(
setmetatable
,
luaB_setmetatable
)
LROT_FUNCENTRY
(
tonumber
,
luaB_tonumber
)
LROT_FUNCENTRY
(
tostring
,
luaB_tostring
)
LROT_FUNCENTRY
(
type
,
luaB_type
)
LROT_FUNCENTRY
(
unpack
,
luaB_unpack
)
LROT_FUNCENTRY
(
xpcall
,
luaB_xpcall
)
#ifdef LUA_CROSS_COMPILER
,
LROT_TABENTRY
(
__metatable
,
base_func_meta
),
LROT_END
#endif
};
LROT_TABENTRY
(
__metatable
,
base_func_meta
)
LROT_END
(
base_func
,
base_func_meta
,
LROT_MASK_INDEX
)
static
const
luaL_Reg
base_funcs
[]
=
{
{
NULL
,
NULL
}
};
LROT_BEGIN
(
G_meta
)
LROT_TABENTRY
(
__index
,
base_func
)
LROT_END
(
G_meta
,
NULL
,
0
)
/*
...
...
@@ -650,17 +645,14 @@ static int luaB_corunning (lua_State *L) {
return
1
;
}
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
const
LUA_REG_TYPE
co_funcs
[]
=
{
{
LSTRKEY
(
"create"
),
LFUNCVAL
(
luaB_cocreate
)},
{
LSTRKEY
(
"resume"
),
LFUNCVAL
(
luaB_coresume
)},
{
LSTRKEY
(
"running"
),
LFUNCVAL
(
luaB_corunning
)},
{
LSTRKEY
(
"status"
),
LFUNCVAL
(
luaB_costatus
)},
{
LSTRKEY
(
"wrap"
),
LFUNCVAL
(
luaB_cowrap
)},
{
LSTRKEY
(
"yield"
),
LFUNCVAL
(
luaB_yield
)},
{
LNILKEY
,
LNILVAL
}
};
LROT_PUBLIC_BEGIN
(
co_funcs
)
LROT_FUNCENTRY
(
create
,
luaB_cocreate
)
LROT_FUNCENTRY
(
resume
,
luaB_coresume
)
LROT_FUNCENTRY
(
running
,
luaB_corunning
)
LROT_FUNCENTRY
(
status
,
luaB_costatus
)
LROT_FUNCENTRY
(
wrap
,
luaB_cowrap
)
LROT_FUNCENTRY
(
yield
,
luaB_yield
)
LROT_END
(
co_funcs
,
NULL
,
0
)
/* }====================================================== */
...
...
@@ -676,14 +668,12 @@ static void base_open (lua_State *L) {
/* set global _G */
lua_pushvalue
(
L
,
LUA_GLOBALSINDEX
);
lua_setglobal
(
L
,
"_G"
);
/* open lib into global table */
luaL_register_light
(
L
,
"_G"
,
base_funcs
);
#if LUA_OPTIMIZE_MEMORY > 0
lua_pushvalue
(
L
,
-
1
);
lua_setmetatable
(
L
,
-
2
);
lua_pushrotable
(
L
,
(
void
*
)
BASE_ROTABLE
);
lua_setglobal
(
L
,
"__index"
);
#endif
luaL_register_light
(
L
,
"_G"
,
&
((
luaL_Reg
)
{
0
}));
lua_pushrotable
(
L
,
LROT_TABLEREF
(
G_meta
));
lua_setmetatable
(
L
,
LUA_GLOBALSINDEX
);
lua_pushliteral
(
L
,
LUA_VERSION
);
lua_setglobal
(
L
,
"_VERSION"
);
/* set global _VERSION */
/* `ipairs' and `pairs' need auxliliary functions as upvalues */
...
...
app/lua/ldblib.c
View file @
1990f957
...
...
@@ -18,9 +18,9 @@
#include "lualib.h"
#include "lstring.h"
#include "lflash.h"
#include "user_modules.h"
#include "lrotable.h"
#include "user_modules.h"
static
int
db_getregistry
(
lua_State
*
L
)
{
lua_pushvalue
(
L
,
LUA_REGISTRYINDEX
);
...
...
@@ -417,32 +417,28 @@ static int db_errorfb (lua_State *L) {
return
1
;
}
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const
LUA_REG_TYPE
dblib
[]
=
{
LROT_PUBLIC_BEGIN
(
dblib
)
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
{
LSTRKE
Y
(
"
debug
"
),
LFUNCVAL
(
db_debug
)
},
{
LSTRKE
Y
(
"
getfenv
"
),
LFUNCVAL
(
db_getfenv
)
},
{
LSTRKE
Y
(
"
gethook
"
),
LFUNCVAL
(
db_gethook
)
},
{
LSTRKE
Y
(
"
getinfo
"
),
LFUNCVAL
(
db_getinfo
)
},
{
LSTRKE
Y
(
"
getlocal
"
),
LFUNCVAL
(
db_getlocal
)
},
LROT_FUNCENTR
Y
(
debug
,
db_debug
)
LROT_FUNCENTR
Y
(
getfenv
,
db_getfenv
)
LROT_FUNCENTR
Y
(
gethook
,
db_gethook
)
LROT_FUNCENTR
Y
(
getinfo
,
db_getinfo
)
LROT_FUNCENTR
Y
(
getlocal
,
db_getlocal
)
#endif
{
LSTRKE
Y
(
"
getregistry
"
),
LFUNCVAL
(
db_getregistry
)
},
{
LSTRKE
Y
(
"
getstrings
"
),
LFUNCVAL
(
db_getstrings
)
},
LROT_FUNCENTR
Y
(
getregistry
,
db_getregistry
)
LROT_FUNCENTR
Y
(
getstrings
,
db_getstrings
)
#ifndef LUA_USE_BUILTIN_DEBUG_MINIMAL
{
LSTRKE
Y
(
"
getmetatable
"
),
LFUNCVAL
(
db_getmetatable
)
},
{
LSTRKE
Y
(
"
getupvalue
"
),
LFUNCVAL
(
db_getupvalue
)
},
{
LSTRKE
Y
(
"
setfenv
"
),
LFUNCVAL
(
db_setfenv
)
},
{
LSTRKE
Y
(
"
sethook
"
),
LFUNCVAL
(
db_sethook
)
},
{
LSTRKE
Y
(
"
setlocal
"
),
LFUNCVAL
(
db_setlocal
)
},
{
LSTRKE
Y
(
"
setmetatable
"
),
LFUNCVAL
(
db_setmetatable
)
},
{
LSTRKE
Y
(
"
setupvalue
"
),
LFUNCVAL
(
db_setupvalue
)
},
LROT_FUNCENTR
Y
(
getmetatable
,
db_getmetatable
)
LROT_FUNCENTR
Y
(
getupvalue
,
db_getupvalue
)
LROT_FUNCENTR
Y
(
setfenv
,
db_setfenv
)
LROT_FUNCENTR
Y
(
sethook
,
db_sethook
)
LROT_FUNCENTR
Y
(
setlocal
,
db_setlocal
)
LROT_FUNCENTR
Y
(
setmetatable
,
db_setmetatable
)
LROT_FUNCENTR
Y
(
setupvalue
,
db_setupvalue
)
#endif
{
LSTRKEY
(
"traceback"
),
LFUNCVAL
(
db_errorfb
)},
{
LNILKEY
,
LNILVAL
}
};
LROT_FUNCENTRY
(
traceback
,
db_errorfb
)
LROT_END
(
dblib
,
NULL
,
0
)
LUALIB_API
int
luaopen_debug
(
lua_State
*
L
)
{
LREGISTER
(
L
,
LUA_DBLIBNAME
,
dblib
)
;
return
0
;
}
app/lua/linit.c
View file @
1990f957
...
...
@@ -15,45 +15,43 @@
#include "lauxlib.h"
#include "luaconf.h"
#include "module.h"
#include "lstate.h"
#if !defined(LUA_CROSS_COMPILER) && !(MIN_OPT_LEVEL==2 && LUA_OPTIMIZE_MEMORY==2)
# error "NodeMCU modules must be built with LTR enabled (MIN_OPT_LEVEL=2 and LUA_OPTIMIZE_MEMORY=2)"
LROT_EXTERN
(
strlib
);
LROT_EXTERN
(
tab_funcs
);
LROT_EXTERN
(
dblib
);
LROT_EXTERN
(
co_funcs
);
LROT_EXTERN
(
math
);
#if defined(LUA_CROSS_COMPILER)
LROT_EXTERN
(
oslib
);
LROT_EXTERN
(
iolib
);
#endif
extern
const
luaR_entry
strlib
[],
tab_funcs
[],
dblib
[],
co_funcs
[],
math_map
[],
syslib
[];
extern
const
luaR_entry
syslib
[],
io_funcs
[];
// Only used on cross-compile builds
/*
* The NodeMCU Lua initalisation has been adapted to use linker-based module
* registration. This uses a PSECT naming convention to allow the lib and rotab
* entries to be collected by the linker into consoliated tables. The linker
* defines lua_libs_base and lua_rotable_base.
* registration. This uses a PSECT naming convention to allow the ROTable and
* initialisation function entries to be collected by the linker into two
* consoliated ROTables. This significantly simplifies adding new modules and
* configuring builds with a small subset of the total modules.
*
* This linker-based approach is not practical for cross compiler builds which
* must link on a range of platforms, and where we don't have control of PSECT
* placement. However unlike the target builds, the luac.cross builds only
* used a small and fixed list of libraries and so in this case the table can
* be defined in this source file, so in this case all library ROTables are
* defined here, avoiding the need for linker magic is avoided on host builds.
*
* This is not practical on Posix builds which use a standard loader declaration
* so for cross compiler builds, separate ROTables are used for the base functions
* and library ROTables, with the latter chained from the former using its __index
* meta-method. In this case all library ROTables are defined here, avoiding the
* need for linker magic is avoided on host builds.
* Note that a separate ROTable is defined in lbaselib.c for the base functions
* and there is a metatable index cascade from _G to this base function table to
* the master rotables table. In the target build, the linker marshals the
* table, hence the LROT_BREAK() macros which don't 0 terminate the lists.
*/
#if defined(LUA_CROSS_COMPILER)
#define LUA_ROTABLES lua_rotable_base
#define LUA_LIBS lua_libs_base
#else
/* declare Xtensa toolchain linker defined constants */
extern
const
luaL_Reg
lua_libs_base
[];
extern
const
luaR_entry
lua_rotable_base
[];
#define LUA_ROTABLES lua_rotable_core
#define LUA_LIBS lua_libs_core
#endif
#ifdef _MSC_VER
//MSVC requires us to declare these sections before we refer to them
#pragma section(__ROSECNAME(A), read)
#pragma section(__ROSECNAME(zzzzzzzz), read)
#pragma section(__ROSECNAME(libs), read)
#pragma section(__ROSECNAME(rotable), read)
//These help us to find the beginning and ending of the RO data. NOTE: linker
//magic is used; the section names are lexically sorted, so 'a' and 'z' are
//important to keep the other sections lexically between these two dummy
...
...
@@ -61,43 +59,57 @@ extern const luaR_entry lua_rotable_base[];
const
LOCK_IN_SECTION
(
A
)
char
_ro_start
[
1
]
=
{
0
};
const
LOCK_IN_SECTION
(
zzzzzzzz
)
char
_ro_end
[
1
]
=
{
0
};
#endif
static
const
LOCK_IN_SECTION
(
libs
)
luaL_reg
LUA_LIBS
[]
=
{
{
""
,
luaopen_base
},
{
LUA_LOADLIBNAME
,
luaopen_package
},
{
LUA_STRLIBNAME
,
luaopen_string
},
{
LUA_TABLIBNAME
,
luaopen_table
},
{
LUA_DBLIBNAME
,
luaopen_debug
}
#if defined(LUA_CROSS_COMPILER)
,{
LUA_IOLIBNAME
,
luaopen_io
},
{
NULL
,
NULL
}
LROT_PUBLIC_TABLE
(
lua_rotables
)
LROT_PUBLIC_BEGIN
(
LOCK_IN_SECTION
(
rotable
)
lua_rotables
)
LROT_TABENTRY
(
string
,
strlib
)
LROT_TABENTRY
(
table
,
tab_funcs
)
LROT_TABENTRY
(
debug
,
dblib
)
LROT_TABENTRY
(
coroutine
,
co_funcs
)
LROT_TABENTRY
(
math
,
math
)
LROT_TABENTRY
(
ROM
,
lua_rotables
)
#ifdef LUA_CROSS_COMPILER
LROT_TABENTRY
(
os
,
oslib
)
LROT_TABENTRY
(
io
,
iolib
)
LROT_END
(
lua_rotables
,
NULL
,
0
)
#else
LROT_BREAK
(
lua_rotables
)
#endif
};
#define ENTRY(n,t) {LSTRKEY(n), LRO_ROVAL(t)}
LROT_PUBLIC_BEGIN
(
LOCK_IN_SECTION
(
libs
)
lua_libs
)
LROT_FUNCENTRY
(
_
,
luaopen_base
)
LROT_FUNCENTRY
(
package
,
luaopen_package
)
LROT_FUNCENTRY
(
string
,
luaopen_string
)
LROT_FUNCENTRY
(
table
,
luaopen_table
)
LROT_FUNCENTRY
(
debug
,
luaopen_debug
)
#ifndef LUA_CROSS_COMPILER
LROT_BREAK
(
lua_rotables
)
#else
LROT_FUNCENTRY
(
io
,
luaopen_io
)
LROT_END
(
lua_libs
,
NULL
,
0
)
#endif
const
LOCK_IN_SECTION
(
rotable
)
ROTable
LUA_ROTABLES
[]
=
{
ENTRY
(
"ROM"
,
LUA_ROTABLES
),
ENTRY
(
LUA_STRLIBNAME
,
strlib
),
ENTRY
(
LUA_TABLIBNAME
,
tab_funcs
),
ENTRY
(
LUA_DBLIBNAME
,
dblib
),
ENTRY
(
LUA_COLIBNAME
,
co_funcs
),
ENTRY
(
LUA_MATHLIBNAME
,
math_map
)
#if defined(LUA_CROSS_COMPILER)
,
ENTRY
(
LUA_OSLIBNAME
,
syslib
),
LROT_END
#ifndef LUA_CROSS_COMPILER
extern
void
luaL_dbgbreak
(
void
);
#endif
};
void
luaL_openlibs
(
lua_State
*
L
)
{
const
luaL_Reg
*
lib
=
lua_libs_base
;
lua_pushrotable
(
L
,
LROT_TABLEREF
(
lua_libs
));
lua_pushnil
(
L
);
/* first key */
/* loop round and open libraries */
for
(;
lib
->
name
;
lib
++
)
{
if
(
lib
->
func
)
{
lua_pushcfunction
(
L
,
lib
->
func
);
lua_pushstring
(
L
,
lib
->
name
);
lua_call
(
L
,
1
,
0
);
#ifndef LUA_CROSS_COMPILER
// luaL_dbgbreak(); // This is a test point for debugging library start ups
#endif
while
(
lua_next
(
L
,
-
2
)
!=
0
)
{
if
(
lua_islightfunction
(
L
,
-
1
)
&&
fvalue
(
L
->
top
-
1
))
{
// only process function entries
lua_pushvalue
(
L
,
-
2
);
lua_call
(
L
,
1
,
0
);
// call luaopen_XXX(libname)
}
else
{
lua_pop
(
L
,
1
);
}
}
lua_pop
(
L
,
1
);
//cleanup stack
}
app/lua/lmathlib.c
View file @
1990f957
...
...
@@ -15,6 +15,7 @@
#include "lauxlib.h"
#include "lualib.h"
#include "lrotable.h"
#undef PI
#define PI (3.14159265358979323846)
...
...
@@ -308,92 +309,57 @@ static int math_randomseed (lua_State *L) {
return
0
;
}
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const
LUA_REG_TYPE
math_map
[]
=
{
LROT_PUBLIC_BEGIN
(
math
)
#ifdef LUA_NUMBER_INTEGRAL
{
LSTRKEY
(
"abs"
),
LFUNCVAL
(
math_abs
)},
{
LSTRKEY
(
"ceil"
),
LFUNCVAL
(
math_identity
)},
{
LSTRKEY
(
"floor"
),
LFUNCVAL
(
math_identity
)},
{
LSTRKEY
(
"max"
),
LFUNCVAL
(
math_max
)},
{
LSTRKEY
(
"min"
),
LFUNCVAL
(
math_min
)},
{
LSTRKEY
(
"pow"
),
LFUNCVAL
(
math_pow
)},
{
LSTRKEY
(
"random"
),
LFUNCVAL
(
math_random
)},
{
LSTRKEY
(
"randomseed"
),
LFUNCVAL
(
math_randomseed
)},
{
LSTRKEY
(
"sqrt"
),
LFUNCVAL
(
math_sqrt
)},
#if LUA_OPTIMIZE_MEMORY > 0
{
LSTRKEY
(
"huge"
),
LNUMVAL
(
INT_MAX
)},
#endif
LROT_FUNCENTRY
(
abs
,
math_abs
)
LROT_FUNCENTRY
(
ceil
,
math_identity
)
LROT_FUNCENTRY
(
floor
,
math_identity
)
LROT_FUNCENTRY
(
max
,
math_max
)
LROT_FUNCENTRY
(
min
,
math_min
)
LROT_FUNCENTRY
(
pow
,
math_pow
)
LROT_FUNCENTRY
(
random
,
math_random
)
LROT_FUNCENTRY
(
randomseed
,
math_randomseed
)
LROT_FUNCENTRY
(
sqrt
,
math_sqrt
)
LROT_NUMENTRY
(
huge
,
INT_MAX
)
#else
{
LSTRKEY
(
"abs"
),
LFUNCVAL
(
math_abs
)},
// {LSTRKEY("acos"), LFUNCVAL(math_acos)},
// {LSTRKEY("asin"), LFUNCVAL(math_asin)},
// {LSTRKEY("atan2"), LFUNCVAL(math_atan2)},
// {LSTRKEY("atan"), LFUNCVAL(math_atan)},
{
LSTRKEY
(
"ceil"
),
LFUNCVAL
(
math_ceil
)},
// {LSTRKEY("cosh"), LFUNCVAL(math_cosh)},
// {LSTRKEY("cos"), LFUNCVAL(math_cos)},
// {LSTRKEY("deg"), LFUNCVAL(math_deg)},
// {LSTRKEY("exp"), LFUNCVAL(math_exp)},
{
LSTRKEY
(
"floor"
),
LFUNCVAL
(
math_floor
)},
// {LSTRKEY("fmod"), LFUNCVAL(math_fmod)},
#if LUA_OPTIMIZE_MEMORY > 0 && defined(LUA_COMPAT_MOD)
// {LSTRKEY("mod"), LFUNCVAL(math_fmod)},
#endif
// {LSTRKEY("frexp"), LFUNCVAL(math_frexp)},
// {LSTRKEY("ldexp"), LFUNCVAL(math_ldexp)},
// {LSTRKEY("log10"), LFUNCVAL(math_log10)},
// {LSTRKEY("log"), LFUNCVAL(math_log)},
{
LSTRKEY
(
"max"
),
LFUNCVAL
(
math_max
)},
{
LSTRKEY
(
"min"
),
LFUNCVAL
(
math_min
)},
// {LSTRKEY("modf"), LFUNCVAL(math_modf)},
{
LSTRKEY
(
"pow"
),
LFUNCVAL
(
math_pow
)},
// {LSTRKEY("rad"), LFUNCVAL(math_rad)},
{
LSTRKEY
(
"random"
),
LFUNCVAL
(
math_random
)},
{
LSTRKEY
(
"randomseed"
),
LFUNCVAL
(
math_randomseed
)},
// {LSTRKEY("sinh"), LFUNCVAL(math_sinh)},
// {LSTRKEY("sin"), LFUNCVAL(math_sin)},
{
LSTRKEY
(
"sqrt"
),
LFUNCVAL
(
math_sqrt
)},
// {LSTRKEY("tanh"), LFUNCVAL(math_tanh)},
// {LSTRKEY("tan"), LFUNCVAL(math_tan)},
#if LUA_OPTIMIZE_MEMORY > 0
{
LSTRKEY
(
"pi"
),
LNUMVAL
(
PI
)},
{
LSTRKEY
(
"huge"
),
LNUMVAL
(
HUGE_VAL
)},
#endif // #if LUA_OPTIMIZE_MEMORY > 0
LROT_FUNCENTRY
(
abs
,
math_abs
)
// LROT_FUNCENTRY( acos, math_acos )
// LROT_FUNCENTRY( asin, math_asin )
// LROT_FUNCENTRY( atan2, math_atan2 )
// LROT_FUNCENTRY( atan, math_atan )
LROT_FUNCENTRY
(
ceil
,
math_ceil
)
// LROT_FUNCENTRY( cosh, math_cosh )
// LROT_FUNCENTRY( cos, math_cos )
// LROT_FUNCENTRY( deg, math_deg )
// LROT_FUNCENTRY( exp, math_exp )
LROT_FUNCENTRY
(
floor
,
math_floor
)
// LROT_FUNCENTRY( fmod, math_fmod )
// LROT_FUNCENTRY( mod, math_fmod )
// LROT_FUNCENTRY( frexp, math_frexp )
// LROT_FUNCENTRY( ldexp, math_ldexp )
// LROT_FUNCENTRY( log10, math_log10 )
// LROT_FUNCENTRY( log, math_log )
LROT_FUNCENTRY
(
max
,
math_max
)
LROT_FUNCENTRY
(
min
,
math_min
)
// LROT_FUNCENTRY( modf, math_modf )
LROT_FUNCENTRY
(
pow
,
math_pow
)
// LROT_FUNCENTRY( rad, math_rad )
LROT_FUNCENTRY
(
random
,
math_random
)
LROT_FUNCENTRY
(
randomseed
,
math_randomseed
)
// LROT_FUNCENTRY( sinh, math_sinh )
// LROT_FUNCENTRY( sin, math_sin )
LROT_FUNCENTRY
(
sqrt
,
math_sqrt
)
// LROT_FUNCENTRY( tanh, math_tanh )
// LROT_FUNCENTRY( tan, math_tan )
LROT_NUMENTRY
(
pi
,
PI
)
LROT_NUMENTRY
(
huge
,
HUGE_VAL
)
#endif // #ifdef LUA_NUMBER_INTEGRAL
{
LNILKEY
,
LNILVAL
}
};
LROT_END
(
math
,
NULL
,
0
)
/*
** Open math library
*/
#if defined LUA_NUMBER_INTEGRAL
# include "c_limits.h"
/* for INT_MAX */
#endif
LUALIB_API
int
luaopen_math
(
lua_State
*
L
)
{
#if LUA_OPTIMIZE_MEMORY > 0
return
0
;
#else
luaL_register
(
L
,
LUA_MATHLIBNAME
,
math_map
);
# if defined LUA_NUMBER_INTEGRAL
lua_pushnumber
(
L
,
INT_MAX
);
lua_setfield
(
L
,
-
2
,
"huge"
);
# else
lua_pushnumber
(
L
,
PI
);
lua_setfield
(
L
,
-
2
,
"pi"
);
lua_pushnumber
(
L
,
HUGE_VAL
);
lua_setfield
(
L
,
-
2
,
"huge"
);
# if defined(LUA_COMPAT_MOD)
lua_getfield
(
L
,
-
1
,
"fmod"
);
lua_setfield
(
L
,
-
2
,
"mod"
);
# endif
# endif
return
1
;
#endif
}
app/lua/loadlib.c
View file @
1990f957
...
...
@@ -24,6 +24,7 @@
#include "lauxlib.h"
#include "lualib.h"
#include "lrotable.h"
/* prefix for open functions in C libraries */
#define LUA_POF "luaopen_"
...
...
@@ -361,7 +362,9 @@ static const char * findfile (lua_State *L, const char *name,
const
char
*
pname
)
{
const
char
*
path
;
name
=
luaL_gsub
(
L
,
name
,
"."
,
LUA_DIRSEP
);
lua_getfield
(
L
,
LUA_ENVIRONINDEX
,
pname
);
lua_getfield
(
L
,
LUA_GLOBALSINDEX
,
"package"
);
lua_getfield
(
L
,
-
1
,
pname
);
lua_remove
(
L
,
-
2
);
path
=
lua_tostring
(
L
,
-
1
);
if
(
path
==
NULL
)
luaL_error
(
L
,
LUA_QL
(
"package.%s"
)
" must be a string"
,
pname
);
...
...
@@ -447,7 +450,9 @@ static int loader_Croot (lua_State *L) {
static
int
loader_preload
(
lua_State
*
L
)
{
const
char
*
name
=
luaL_checkstring
(
L
,
1
);
lua_getfield
(
L
,
LUA_ENVIRONINDEX
,
"preload"
);
lua_getfield
(
L
,
LUA_GLOBALSINDEX
,
"package"
);
lua_getfield
(
L
,
-
1
,
"preload"
);
lua_remove
(
L
,
-
2
);
if
(
!
lua_istable
(
L
,
-
1
))
luaL_error
(
L
,
LUA_QL
(
"package.preload"
)
" must be a table"
);
lua_getfield
(
L
,
-
1
,
name
);
...
...
@@ -480,7 +485,9 @@ static int ll_require (lua_State *L) {
lua_pop
(
L
,
1
);
}
/* else must load it; iterate over available loaders */
lua_getfield
(
L
,
LUA_ENVIRONINDEX
,
"loaders"
);
lua_getfield
(
L
,
LUA_GLOBALSINDEX
,
"package"
);
lua_getfield
(
L
,
-
1
,
"loaders"
);
lua_remove
(
L
,
-
2
);
if
(
!
lua_istable
(
L
,
-
1
))
luaL_error
(
L
,
LUA_QL
(
"package.loaders"
)
" must be a table"
);
lua_pushliteral
(
L
,
""
);
/* error message accumulator */
...
...
@@ -650,34 +657,20 @@ static const luaL_Reg ll_funcs[] = {
static
const
lua_CFunction
loaders
[]
=
{
loader_preload
,
loader_Lua
,
loader_C
,
loader_Croot
,
NULL
};
#if LUA_OPTIMIZE_MEMORY > 0
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const
LUA_REG_TYPE
lmt
[]
=
{
{
LRO_STRKEY
(
"__gc"
),
LRO_FUNCVAL
(
gctm
)},
{
LRO_NILKEY
,
LRO_NILVAL
}
};
#endif
LROT_PUBLIC_BEGIN
(
lmt
)
LROT_FUNCENTRY
(
__gc
,
gctm
)
LROT_END
(
lmt
,
lmt
,
LROT_MASK_GC
)
LUALIB_API
int
luaopen_package
(
lua_State
*
L
)
{
int
i
;
/* create new type _LOADLIB */
#if LUA_OPTIMIZE_MEMORY == 0
luaL_newmetatable
(
L
,
"_LOADLIB"
);
lua_pushlightfunction
(
L
,
gctm
);
lua_setfield
(
L
,
-
2
,
"__gc"
);
#else
luaL_rometatable
(
L
,
"_LOADLIB"
,
(
void
*
)
lmt
);
#endif
luaL_rometatable
(
L
,
"_LOADLIB"
,
LROT_TABLEREF
(
lmt
));
/* create `package' table */
luaL_register_light
(
L
,
LUA_LOADLIBNAME
,
pk_funcs
);
#if defined(LUA_COMPAT_LOADLIB)
lua_getfield
(
L
,
-
1
,
"loadlib"
);
lua_setfield
(
L
,
LUA_GLOBALSINDEX
,
"loadlib"
);
#endif
lua_pushvalue
(
L
,
-
1
);
lua_replace
(
L
,
LUA_ENVIRONINDEX
);
/* create `loaders' table */
lua_createtable
(
L
,
sizeof
(
loaders
)
/
sizeof
(
loaders
[
0
])
-
1
,
0
);
/* fill it with pre-defined loaders */
...
...
app/lua/lrodefs.h
View file @
1990f957
...
...
@@ -25,8 +25,7 @@
#define LNUMVAL LRO_NUMVAL
#define LROVAL LRO_ROVAL
#define LNILVAL LRO_NILVAL
#define LREGISTER(L, name, table)\
return 0
#define LREGISTER(L, name, table) return 0
#else
#define LUA_REG_TYPE luaL_reg
#define LSTRKEY(x) x
...
...
@@ -38,10 +37,17 @@
return 1
#endif
#define LROT_TABENTRY(n,t) {LSTRKEY(#n), LRO_ROVAL(t)}
#define LROT_FUNCENTRY(n,f) {LSTRKEY(#n), LRO_FUNCVAL(f)}
#define LROT_NUMENTRY(n,x) {LSTRKEY(#n), LRO_NUMVAL(x)}
#define LROT_END {LNILKEY, LNILVAL}
#define LROT_TABLE(t) static const LUA_REG_TYPE t ## _map[];
#define LROT_TABLEREF(t) ((void *) t ## _map)
#define LROT_BEGIN(t) static const LUA_REG_TYPE t ## _map [] = {
#define LROT_PUBLIC_BEGIN(t) const LUA_REG_TYPE t ## _map[] = {
#define LROT_EXTERN(t) extern const LUA_REG_TYPE t ## _map[]
#define LROT_TABENTRY(n,t) {LRO_STRKEY(#n), LRO_ROVAL(t ## _map)},
#define LROT_FUNCENTRY(n,f) {LRO_STRKEY(#n), LRO_FUNCVAL(f)},
#define LROT_NUMENTRY(n,x) {LRO_STRKEY(#n), LRO_NUMVAL(x)},
#define LROT_LUDENTRY(n,x) {LRO_STRKEY(#n), LRO_LUDATA((void *) x)},
#define LROT_END(t,mt, f) {LRO_NILKEY, LRO_NILVAL} };
#define LREGISTER(L, name, table) return 0
#endif
/* lrodefs_h */
app/lua/lrotable.c
View file @
1990f957
...
...
@@ -14,7 +14,7 @@
#else
#define ALIGNED_STRING (__attribute__((aligned(4))) char *)
#endif
#define LA_LINES
16
#define LA_LINES
32
#define LA_SLOTS 4
//#define COLLECT_STATS
...
...
@@ -36,7 +36,7 @@
* Note that this hash does a couple of prime multiples and a modulus 2^X
* with is all evaluated in H/W, and adequately randomizes the lookup.
*/
#define HASH(a,b) (519*(
(
size_t)(a)>>4) +
17*((size_t)(b)>>4
))
#define HASH(a,b)
(((
(519*(size_t)(a)
))
>>4) +
((b) ? (b)->tsv.hash: 0
))
static
struct
{
unsigned
hash
;
...
...
@@ -83,19 +83,18 @@ static void update_cache(unsigned hash, ROTable *rotable, unsigned ndx) {
const
TValue
*
luaR_findentry
(
ROTable
*
rotable
,
TString
*
key
,
unsigned
*
ppos
)
{
const
luaR_entry
*
pentry
=
rotable
;
const
char
*
strkey
=
key
?
getstr
(
key
)
:
ALIGNED_STRING
"__metatable"
;
size_t
hash
=
HASH
(
rotable
,
key
);
unsigned
hash
=
HASH
(
rotable
,
key
);
unsigned
i
=
0
;
int
j
=
lookup_cache
(
hash
,
rotable
);
unsigned
l
=
key
?
key
->
tsv
.
len
:
sizeof
(
"__metatable"
)
-
1
;
if
(
pentry
)
{
if
(
j
>=
0
){
if
((
pentry
[
j
].
key
.
type
==
LUA_TSTRING
)
&&
!
c_strcmp
(
pentry
[
j
].
key
.
id
.
strkey
,
strkey
))
{
if
(
ppos
)
*
ppos
=
j
;
return
&
pentry
[
j
].
value
;
}
if
(
j
>=
0
&&
!
c_strcmp
(
pentry
[
j
].
key
,
strkey
))
{
if
(
ppos
)
*
ppos
=
j
;
//dbg_printf("%3d hit %p %s\n", (hash>>2) & (LA_LINES-1), rotable, strkey);
return
&
pentry
[
j
].
value
;
}
/*
* The invariants for 1st word comparison are deferred to here since they
...
...
@@ -105,40 +104,22 @@ const TValue* luaR_findentry(ROTable *rotable, TString *key, unsigned *ppos) {
unsigned
name4
,
mask4
=
l
>
2
?
(
~
0u
)
:
(
~
0u
)
>>
((
3
-
l
)
*
8
);
c_memcpy
(
&
name4
,
strkey
,
sizeof
(
name4
));
for
(;
pentry
->
key
.
type
!=
LUA_TNI
L
;
i
++
,
pentry
++
)
{
if
((
pentry
->
key
.
type
==
LUA_TSTRING
)
&&
((
*
(
unsigned
*
)
pentry
->
key
.
id
.
strkey
^
name4
)
&
mask4
)
==
0
&&
!
c_strcmp
(
pentry
->
key
.
id
.
strkey
,
strke
y
))
{
for
(;
pentry
->
key
!=
NUL
L
;
i
++
,
pentry
++
)
{
if
((
(
*
(
unsigned
*
)
pentry
->
key
^
name4
)
&
mask4
)
==
0
&&
!
c_strcmp
(
pentry
->
key
,
strkey
))
{
//dbg_printf("%p %s hit after %d probes \n", rotable, strkey, (int)(rotable-pentr
y))
;
if
(
ppos
)
*
ppos
=
i
;
if
(
j
==-
1
)
{
update_cache
(
hash
,
rotable
,
pentry
-
rotable
);
}
else
if
(
j
!=
(
pentry
-
rotable
))
{
j
=
0
;
}
return
&
pentry
->
value
;
update_cache
(
hash
,
rotable
,
pentry
-
rotable
);
//dbg_printf("%3d %3d %p %s\n", (hash>>2) & (LA_LINES-1), (int)(pentry-rotable), rotable, strkey);
return
&
pentry
->
value
;
}
}
}
//dbg_printf("%p %s miss after %d probes \n", rotable, strkey, (int)(rotable-pentry));
return
luaO_nilobject
;
}
const
TValue
*
luaR_findentryN
(
ROTable
*
rotable
,
luaR_numkey
numkey
,
unsigned
*
ppos
)
{
unsigned
i
=
0
;
const
luaR_entry
*
pentry
=
rotable
;
if
(
pentry
)
{
for
(
;
pentry
->
key
.
type
!=
LUA_TNIL
;
i
++
,
pentry
++
)
{
if
(
pentry
->
key
.
type
==
LUA_TNUMBER
&&
(
luaR_numkey
)
pentry
->
key
.
id
.
numkey
==
numkey
)
{
if
(
ppos
)
*
ppos
=
i
;
return
&
pentry
->
value
;
}
}
}
return
NULL
;
}
/* Find the metatable of a given table */
void
*
luaR_getmeta
(
ROTable
*
rotable
)
{
const
TValue
*
res
=
luaR_findentry
(
rotable
,
NULL
,
NULL
);
...
...
@@ -147,15 +128,13 @@ void* luaR_getmeta(ROTable *rotable) {
static
void
luaR_next_helper
(
lua_State
*
L
,
ROTable
*
pentries
,
int
pos
,
TValue
*
key
,
TValue
*
val
)
{
setnilvalue
(
key
);
setnilvalue
(
val
);
if
(
pentries
[
pos
].
key
.
type
!=
LUA_TNIL
)
{
if
(
pentries
[
pos
].
key
)
{
/* Found an entry */
if
(
pentries
[
pos
].
key
.
type
==
LUA_TSTRING
)
set
svalue
(
L
,
key
,
luaS_new
(
L
,
pentries
[
pos
].
key
.
id
.
strkey
))
else
setnvalue
(
key
,
(
lua_Number
)
pentries
[
pos
].
key
.
id
.
numkey
)
set
obj2s
(
L
,
val
,
&
pentries
[
pos
].
val
ue
);
setsvalue
(
L
,
key
,
luaS_new
(
L
,
pentries
[
pos
].
key
));
set
obj2s
(
L
,
val
,
&
pentries
[
pos
].
value
);
}
else
{
setn
il
value
(
key
)
;
set
nilvalue
(
val
);
}
}
...
...
@@ -167,12 +146,10 @@ void luaR_next(lua_State *L, ROTable *rotable, TValue *key, TValue *val) {
/* Special case: if key is nil, return the first element of the rotable */
if
(
ttisnil
(
key
))
luaR_next_helper
(
L
,
rotable
,
0
,
key
,
val
);
else
if
(
ttisstring
(
key
)
||
ttisnumber
(
key
)
)
{
else
if
(
ttisstring
(
key
))
{
/* Find the previous key again */
if
(
ttisstring
(
key
))
{
luaR_findentry
(
rotable
,
rawtsvalue
(
key
),
&
keypos
);
}
else
{
luaR_findentryN
(
rotable
,
(
luaR_numkey
)
nvalue
(
key
),
&
keypos
);
}
/* Advance to next key */
keypos
++
;
...
...
app/lua/lrotable.h
View file @
1990f957
...
...
@@ -7,6 +7,7 @@
#include "luaconf.h"
#include "lobject.h"
#include "llimits.h"
#include "lrotable.h"
/* Macros one can use to define rotable entries */
#define LRO_FUNCVAL(v) {{.p = v}, LUA_TLIGHTFUNCTION}
...
...
@@ -14,13 +15,28 @@
#define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER}
#define LRO_ROVAL(v) {{.p = (void*)v}, LUA_TROTABLE}
#define LRO_NILVAL {{.p = NULL}, LUA_TNIL}
#ifdef LUA_CROSS_COMPILER
#define LRO_STRKEY(k)
{LUA_TSTRING, {.strkey = k}}
#define LRO_STRKEY(k)
k
#else
#define LRO_STRKEY(k)
{LUA_TSTRING, {.strkey =
(STORE_ATTR char *) k
}}
#define LRO_STRKEY(k)
(
(STORE_ATTR char *) k
)
#endif
#define LRO_NUMKEY(k) {LUA_TNUMBER, {.numkey = k}}
#define LRO_NILKEY {LUA_TNIL, {.strkey=NULL}}
#define LROT_TABLE(t) static const LUA_REG_TYPE t ## _map[];
#define LROT_PUBLIC_TABLE(t) const LUA_REG_TYPE t ## _map[];
#define LROT_TABLEREF(t) ((void *) t ## _map)
#define LROT_BEGIN(t) static const LUA_REG_TYPE t ## _map [] = {
#define LROT_PUBLIC_BEGIN(t) const LUA_REG_TYPE t ## _map[] = {
#define LROT_EXTERN(t) extern const LUA_REG_TYPE t ## _map[]
#define LROT_TABENTRY(n,t) {LRO_STRKEY(#n), LRO_ROVAL(t ## _map)},
#define LROT_FUNCENTRY(n,f) {LRO_STRKEY(#n), LRO_FUNCVAL(f)},
#define LROT_NUMENTRY(n,x) {LRO_STRKEY(#n), LRO_NUMVAL(x)},
#define LROT_LUDENTRY(n,x) {LRO_STRKEY(#n), LRO_LUDATA((void *) x)},
#define LROT_END(t,mt, f) {NULL, LRO_NILVAL} };
#define LROT_BREAK(t) };
#define LUA_REG_TYPE luaR_entry
#define LREGISTER(L, name, table) return 0
/* Maximum length of a rotable name and of a string key*/
#define LUA_MAX_ROTABLE_NAME 32
...
...
@@ -28,18 +44,9 @@
/* Type of a numeric key in a rotable */
typedef
int
luaR_numkey
;
/* The next structure defines the type of a key */
typedef
struct
{
int
type
;
union
{
const
char
*
strkey
;
luaR_numkey
numkey
;
}
id
;
}
luaR_key
;
/* An entry in the read only table */
typedef
struct
luaR_entry
{
const
luaR_key
key
;
const
char
*
key
;
const
TValue
value
;
}
luaR_entry
;
...
...
app/lua/lstrlib.c
View file @
1990f957
...
...
@@ -15,12 +15,12 @@
#include "lauxlib.h"
#include "lualib.h"
#include "lrotable.h"
/* macro to `unsign' a character */
#define uchar(c) ((unsigned char)(c))
static
int
str_len
(
lua_State
*
L
)
{
size_t
l
;
luaL_checklstring
(
L
,
1
,
&
l
);
...
...
@@ -576,7 +576,7 @@ static int gmatch (lua_State *L) {
return
1
;
}
#if
LUA_OPTIMIZE_MEMORY == 0 || !defined(
LUA_COMPAT_GFIND
)
#if
ndef
LUA_COMPAT_GFIND
static
int
gfind_nodef
(
lua_State
*
L
)
{
return
luaL_error
(
L
,
LUA_QL
(
"string.gfind"
)
" was renamed to "
LUA_QL
(
"string.gmatch"
));
...
...
@@ -824,67 +824,37 @@ static int str_format (lua_State *L) {
return
1
;
}
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const
LUA_REG_TYPE
strlib
[]
=
{
{
LSTRKEY
(
"byte"
),
LFUNCVAL
(
str_byte
)},
{
LSTRKEY
(
"char"
),
LFUNCVAL
(
str_char
)},
{
LSTRKEY
(
"dump"
),
LFUNCVAL
(
str_dump
)},
{
LSTRKEY
(
"find"
),
LFUNCVAL
(
str_find
)},
{
LSTRKEY
(
"format"
),
LFUNCVAL
(
str_format
)},
#if LUA_OPTIMIZE_MEMORY > 0 && defined(LUA_COMPAT_GFIND)
{
LSTRKEY
(
"gfind"
),
LFUNCVAL
(
gmatch
)},
LROT_PUBLIC_BEGIN
(
strlib
)
LROT_FUNCENTRY
(
byte
,
str_byte
)
LROT_FUNCENTRY
(
char
,
str_char
)
LROT_FUNCENTRY
(
dump
,
str_dump
)
LROT_FUNCENTRY
(
find
,
str_find
)
LROT_FUNCENTRY
(
format
,
str_format
)
#ifdef LUA_COMPAT_GFIND
LROT_FUNCENTRY
(
gfind
,
gmatch
)
#else
{
LSTRKEY
(
"gfind"
),
LFUNCVAL
(
gfind_nodef
)},
#endif
{
LSTRKEY
(
"gmatch"
),
LFUNCVAL
(
gmatch
)},
{
LSTRKEY
(
"gsub"
),
LFUNCVAL
(
str_gsub
)},
{
LSTRKEY
(
"len"
),
LFUNCVAL
(
str_len
)},
{
LSTRKEY
(
"lower"
),
LFUNCVAL
(
str_lower
)},
{
LSTRKEY
(
"match"
),
LFUNCVAL
(
str_match
)},
{
LSTRKEY
(
"rep"
),
LFUNCVAL
(
str_rep
)},
{
LSTRKEY
(
"reverse"
),
LFUNCVAL
(
str_reverse
)},
{
LSTRKEY
(
"sub"
),
LFUNCVAL
(
str_sub
)},
{
LSTRKEY
(
"upper"
),
LFUNCVAL
(
str_upper
)},
#if LUA_OPTIMIZE_MEMORY > 0
{
LSTRKEY
(
"__index"
),
LROVAL
(
strlib
)},
#endif
{
LNILKEY
,
LNILVAL
}
};
#if LUA_OPTIMIZE_MEMORY != 2
static
void
createmetatable
(
lua_State
*
L
)
{
lua_createtable
(
L
,
0
,
1
);
/* create metatable for strings */
lua_pushliteral
(
L
,
""
);
/* dummy string */
lua_pushvalue
(
L
,
-
2
);
lua_setmetatable
(
L
,
-
2
);
/* set string metatable */
lua_pop
(
L
,
1
);
/* pop dummy string */
lua_pushvalue
(
L
,
-
2
);
/* string library... */
lua_setfield
(
L
,
-
2
,
"__index"
);
/* ...is the __index metamethod */
lua_pop
(
L
,
1
);
/* pop metatable */
}
LROT_FUNCENTRY
(
gfind
,
gfind_nodef
)
#endif
LROT_FUNCENTRY
(
gmatch
,
gmatch
)
LROT_FUNCENTRY
(
gsub
,
str_gsub
)
LROT_FUNCENTRY
(
len
,
str_len
)
LROT_FUNCENTRY
(
lower
,
str_lower
)
LROT_FUNCENTRY
(
match
,
str_match
)
LROT_FUNCENTRY
(
rep
,
str_rep
)
LROT_FUNCENTRY
(
reverse
,
str_reverse
)
LROT_FUNCENTRY
(
sub
,
str_sub
)
LROT_FUNCENTRY
(
upper
,
str_upper
)
LROT_TABENTRY
(
__index
,
strlib
)
LROT_END
(
strlib
,
NULL
,
0
)
// OR DO WE NEED LRTO_MASK_INDEX **TODO**
/*
** Open string library
*/
LUALIB_API
int
luaopen_string
(
lua_State
*
L
)
{
#if LUA_OPTIMIZE_MEMORY == 0
luaL_register
(
L
,
LUA_STRLIBNAME
,
strlib
);
#if defined(LUA_COMPAT_GFIND)
lua_getfield
(
L
,
-
1
,
"gmatch"
);
lua_setfield
(
L
,
-
2
,
"gfind"
);
#endif
createmetatable
(
L
);
return
1
;
#else
lua_pushliteral
(
L
,
""
);
lua_pushrotable
(
L
,
(
void
*
)
strlib
);
lua_pushrotable
(
L
,
LROT_TABLEREF
(
strlib
)
)
;
lua_setmetatable
(
L
,
-
2
);
lua_pop
(
L
,
1
);
return
0
;
#endif
}
app/lua/ltable.c
View file @
1990f957
...
...
@@ -580,7 +580,7 @@ const TValue *luaH_getnum (Table *t, int key) {
/* same thing for rotables */
const
TValue
*
luaH_getnum_ro
(
void
*
t
,
int
key
)
{
const
TValue
*
res
=
luaR_findentryN
(
t
,
key
,
NULL
);
const
TValue
*
res
=
NULL
;
// integer values not supported:
luaR_findentryN(t, key, NULL);
return
res
?
res
:
luaO_nilobject
;
}
...
...
@@ -739,11 +739,7 @@ int luaH_getn (Table *t) {
/* same thing for rotables */
int
luaH_getn_ro
(
void
*
t
)
{
int
i
=
1
,
len
=
0
;
while
(
luaR_findentryN
(
t
,
i
++
,
NULL
))
len
++
;
return
len
;
return
0
;
// Integer Keys are not currently supported for ROTables
}
int
luaH_isdummy
(
Node
*
n
)
{
return
n
==
dummynode
;
}
...
...
app/lua/ltablib.c
View file @
1990f957
...
...
@@ -13,6 +13,7 @@
#include "lauxlib.h"
#include "lualib.h"
#include "lrotable.h"
#define aux_getn(L,n) (luaL_checktype(L, n, LUA_TTABLE), luaL_getn(L, n))
...
...
@@ -265,22 +266,18 @@ static int sort (lua_State *L) {
/* }====================================================== */
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const
LUA_REG_TYPE
tab_funcs
[]
=
{
{
LSTRKEY
(
"concat"
),
LFUNCVAL
(
tconcat
)},
{
LSTRKEY
(
"foreach"
),
LFUNCVAL
(
foreach
)},
{
LSTRKEY
(
"foreachi"
),
LFUNCVAL
(
foreachi
)},
{
LSTRKEY
(
"getn"
),
LFUNCVAL
(
getn
)},
{
LSTRKEY
(
"maxn"
),
LFUNCVAL
(
maxn
)},
{
LSTRKEY
(
"insert"
),
LFUNCVAL
(
tinsert
)},
{
LSTRKEY
(
"remove"
),
LFUNCVAL
(
tremove
)},
{
LSTRKEY
(
"setn"
),
LFUNCVAL
(
setn
)},
{
LSTRKEY
(
"sort"
),
LFUNCVAL
(
sort
)},
{
LNILKEY
,
LNILVAL
}
};
LROT_PUBLIC_BEGIN
(
tab_funcs
)
LROT_FUNCENTRY
(
concat
,
tconcat
)
LROT_FUNCENTRY
(
foreach
,
foreach
)
LROT_FUNCENTRY
(
foreachi
,
foreachi
)
LROT_FUNCENTRY
(
getn
,
getn
)
LROT_FUNCENTRY
(
maxn
,
maxn
)
LROT_FUNCENTRY
(
insert
,
tinsert
)
LROT_FUNCENTRY
(
remove
,
tremove
)
LROT_FUNCENTRY
(
setn
,
setn
)
LROT_FUNCENTRY
(
sort
,
sort
)
LROT_END
(
tab_funcs
,
NULL
,
0
)
LUALIB_API
int
luaopen_table
(
lua_State
*
L
)
{
LREGISTER
(
L
,
LUA_TABLIBNAME
,
tab_funcs
)
;
return
1
;
}
app/lua/luac_cross/Makefile
View file @
1990f957
...
...
@@ -13,7 +13,7 @@ LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile
CCFLAGS
+=
-Wall
DEFINES
+=
-DLUA_CROSS_COMPILER
-DLUA_OPTIMIZE_MEMORY
=
2
DEFINES
+=
-DLUA_CROSS_COMPILER
TARGET
=
host
...
...
app/lua/luac_cross/liolib.c
View file @
1990f957
...
...
@@ -12,12 +12,12 @@
#define liolib_c
#define LUA_LIB
#define LUA_OPTIMIZE_MEMORY 2
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "lrotable.h"
#define IO_INPUT 1
#define IO_OUTPUT 2
...
...
@@ -439,36 +439,31 @@ static int f_flush (lua_State *L) {
return
pushresult
(
L
,
fflush
(
tofile
(
L
))
==
0
,
NULL
);
}
#define MIN_OPT_LEVEL 2
#include "lrodefs.h"
const
LUA_REG_TYPE
iolib_funcs
[]
=
{
{
LSTRKEY
(
"close"
),
LFUNCVAL
(
io_close
)},
{
LSTRKEY
(
"flush"
),
LFUNCVAL
(
io_flush
)},
{
LSTRKEY
(
"input"
),
LFUNCVAL
(
io_input
)},
{
LSTRKEY
(
"lines"
),
LFUNCVAL
(
io_lines
)},
{
LSTRKEY
(
"open"
),
LFUNCVAL
(
io_open
)},
{
LSTRKEY
(
"output"
),
LFUNCVAL
(
io_output
)},
{
LSTRKEY
(
"read"
),
LFUNCVAL
(
io_read
)},
{
LSTRKEY
(
"type"
),
LFUNCVAL
(
io_type
)},
{
LSTRKEY
(
"write"
),
LFUNCVAL
(
io_write
)},
{
LSTRKEY
(
"__index"
),
LROVAL
(
iolib_funcs
)},
{
LNILKEY
,
LNILVAL
}
};
#include "lrodefs.h"
const
LUA_REG_TYPE
flib
[]
=
{
{
LSTRKEY
(
"close"
),
LFUNCVAL
(
io_close
)},
{
LSTRKEY
(
"flush"
),
LFUNCVAL
(
f_flush
)},
{
LSTRKEY
(
"lines"
),
LFUNCVAL
(
f_lines
)},
{
LSTRKEY
(
"read"
),
LFUNCVAL
(
f_read
)},
{
LSTRKEY
(
"seek"
),
LFUNCVAL
(
f_seek
)},
{
LSTRKEY
(
"setvbuf"
),
LFUNCVAL
(
f_setvbuf
)},
{
LSTRKEY
(
"write"
),
LFUNCVAL
(
f_write
)},
{
LSTRKEY
(
"__gc"
),
LFUNCVAL
(
io_gc
)},
{
LSTRKEY
(
"__tostring"
),
LFUNCVAL
(
io_tostring
)},
{
LSTRKEY
(
"__index"
),
LROVAL
(
flib
)},
{
LNILKEY
,
LNILVAL
}
};
LROT_PUBLIC_BEGIN
(
iolib
)
LROT_FUNCENTRY
(
close
,
io_close
)
LROT_FUNCENTRY
(
flush
,
io_flush
)
LROT_FUNCENTRY
(
input
,
io_input
)
LROT_FUNCENTRY
(
lines
,
io_lines
)
LROT_FUNCENTRY
(
open
,
io_open
)
LROT_FUNCENTRY
(
output
,
io_output
)
LROT_FUNCENTRY
(
read
,
io_read
)
LROT_FUNCENTRY
(
type
,
io_type
)
LROT_FUNCENTRY
(
write
,
io_write
)
LROT_TABENTRY
(
__index
,
iolib
)
LROT_END
(
iolib
,
NULL
,
0
)
LROT_BEGIN
(
flib
)
LROT_FUNCENTRY
(
close
,
io_close
)
LROT_FUNCENTRY
(
flush
,
f_flush
)
LROT_FUNCENTRY
(
lines
,
f_lines
)
LROT_FUNCENTRY
(
read
,
f_read
)
LROT_FUNCENTRY
(
seek
,
f_seek
)
LROT_FUNCENTRY
(
setvbuf
,
f_setvbuf
)
LROT_FUNCENTRY
(
write
,
f_write
)
LROT_FUNCENTRY
(
__gc
,
io_gc
)
LROT_FUNCENTRY
(
__tostring
,
io_tostring
)
LROT_TABENTRY
(
__index
,
flib
)
LROT_END
(
flib
,
NULL
,
LROT_MASK_GC_INDEX
)
static
const
luaL_Reg
io_base
[]
=
{{
NULL
,
NULL
}};
...
...
@@ -481,12 +476,12 @@ static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
}
LUALIB_API
int
luaopen_io
(
lua_State
*
L
)
{
luaL_rometatable
(
L
,
LUA_FILEHANDLE
,
(
void
*
)
flib
);
/* create metatable for file handles */
luaL_rometatable
(
L
,
LUA_FILEHANDLE
,
LROT_TABLEREF
(
flib
)
)
;
/* create metatable for file handles */
luaL_register_light
(
L
,
LUA_IOLIBNAME
,
io_base
);
lua_pushvalue
(
L
,
-
1
);
lua_setmetatable
(
L
,
-
2
);
lua_pushliteral
(
L
,
"__index"
);
lua_pushrotable
(
L
,
(
void
*
)
iolib_funcs
);
lua_pushrotable
(
L
,
LROT_TABLEREF
(
iolib
)
);
lua_rawset
(
L
,
-
3
);
/* create (and set) default files */
...
...
app/lua/luac_cross/loslib.c
View file @
1990f957
...
...
@@ -20,6 +20,7 @@
#include "lauxlib.h"
#include "lualib.h"
#include "lrotable.h"
static
int
os_pushresult
(
lua_State
*
L
,
int
i
,
const
char
*
filename
)
{
int
en
=
errno
;
/* calls to Lua API may change this value */
...
...
@@ -219,30 +220,25 @@ static int os_exit (lua_State *L) {
c_exit
(
luaL_optint
(
L
,
1
,
EXIT_SUCCESS
));
}
#undef MIN_OPT_LEVEL
#define MIN_OPT_LEVEL 1
#include "lrodefs.h"
const
LUA_REG_TYPE
syslib
[]
=
{
{
LSTRKEY
(
"clock"
),
LFUNCVAL
(
os_clock
)},
{
LSTRKEY
(
"date"
),
LFUNCVAL
(
os_date
)},
LROT_PUBLIC_BEGIN
(
oslib
)
LROT_FUNCENTRY
(
clock
,
os_clock
)
LROT_FUNCENTRY
(
date
,
os_date
)
#if !defined LUA_NUMBER_INTEGRAL
{
LSTRKE
Y
(
"
difftime
"
),
LFUNCVAL
(
os_difftime
)
},
LROT_FUNCENTR
Y
(
difftime
,
os_difftime
)
#endif
{
LSTRKEY
(
"execute"
),
LFUNCVAL
(
os_execute
)},
{
LSTRKEY
(
"exit"
),
LFUNCVAL
(
os_exit
)},
{
LSTRKEY
(
"getenv"
),
LFUNCVAL
(
os_getenv
)},
{
LSTRKEY
(
"remove"
),
LFUNCVAL
(
os_remove
)},
{
LSTRKEY
(
"rename"
),
LFUNCVAL
(
os_rename
)},
{
LSTRKEY
(
"setlocale"
),
LFUNCVAL
(
os_setlocale
)},
{
LSTRKEY
(
"time"
),
LFUNCVAL
(
os_time
)},
{
LSTRKEY
(
"tmpname"
),
LFUNCVAL
(
os_tmpname
)},
{
LNILKEY
,
LNILVAL
}
};
LROT_FUNCENTRY
(
execute
,
os_execute
)
LROT_FUNCENTRY
(
exit
,
os_exit
)
LROT_FUNCENTRY
(
getenv
,
os_getenv
)
LROT_FUNCENTRY
(
remove
,
os_remove
)
LROT_FUNCENTRY
(
rename
,
os_rename
)
LROT_FUNCENTRY
(
setlocale
,
os_setlocale
)
LROT_FUNCENTRY
(
time
,
os_time
)
LROT_FUNCENTRY
(
tmpname
,
os_tmpname
)
LROT_END
(
oslib
,
NULL
,
0
)
/* }====================================================== */
LUALIB_API
int
luaopen_os
(
lua_State
*
L
)
{
LREGISTER
(
L
,
LUA_OSLIBNAME
,
syslib
)
;
return
1
;
}
app/lua/luaconf.h
View file @
1990f957
...
...
@@ -910,8 +910,8 @@ union luai_Cast { double l_d; long l_l; };
** without modifying the main part of the file.
*/
#if
LUA_OPTIMIZE_MEMORY == 2 &&
defined(LUA_USE_POPEN)
#error "Pipes not supported
in aggresive optimization mode (LUA_OPTIMIZE_MEMORY=2)
"
#if defined(LUA_USE_POPEN)
#error "Pipes not supported
NodeMCU firmware
"
#endif
#endif
Prev
1
2
3
4
5
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