Skip to content

Commit 2539d04

Browse files
committed
document module.h changes
1 parent e3bd573 commit 2539d04

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

components/base_nodemcu/include/module.h

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#ifndef __MODULE_H__
22
#define __MODULE_H__
33

4-
#include "lrotable.h"
54
#include "sdkconfig.h"
5+
#include "lrotable.h"
66

77
/* Registering a module within NodeMCU is really easy these days!
88
*
@@ -33,8 +33,8 @@
3333
*/
3434

3535
#define MODULE_EXPAND_(x) x
36-
#define MODULE_PASTE_(x, y) x##y
37-
#define MODULE_EXPAND_PASTE_(x, y) MODULE_PASTE_(x, y)
36+
#define MODULE_PASTE_(x,y) x##y
37+
#define MODULE_EXPAND_PASTE_(x,y) MODULE_PASTE_(x,y)
3838

3939
#ifdef LUA_CROSS_COMPILER
4040
#ifdef _MSC_VER
@@ -46,12 +46,12 @@
4646
#define __STRINGIFY(x) #x
4747
#define __TOSTRING(x) __STRINGIFY(x)
4848
#define __ROSECNAME(s) __TOSTRING(__TOTOK(s))
49-
#define LOCK_IN_SECTION(s) __declspec(allocate(__ROSECNAME(s)))
49+
#define LOCK_IN_SECTION(s) __declspec ( allocate( __ROSECNAME(s) ) )
5050
#else
51-
#define LOCK_IN_SECTION(s) __attribute__((used, unused, section(".rodata1." #s)))
51+
#define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".rodata1." #s)))
5252
#endif
5353
#else
54-
#define LOCK_IN_SECTION(s) __attribute__((used, unused, section(".lua_" #s)))
54+
#define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".lua_" #s)))
5555
#endif
5656
/* For the ROM table, we name the variable according to ( | denotes concat):
5757
* cfgname | _module_selected | CONFIG_LUA_MODULE_##cfgname
@@ -63,24 +63,30 @@
6363
* letting the build system detect automatically (via nm) which modules need
6464
* to be linked in.
6565
*/
66-
#define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \
67-
const LOCK_IN_SECTION(libs) \
68-
luaR_entry MODULE_PASTE_(lua_lib_, cfgname) = {luaname, LRO_FUNCVAL(initfunc)}; \
69-
const LOCK_IN_SECTION(rotable) \
70-
luaR_entry MODULE_EXPAND_PASTE_(cfgname, MODULE_EXPAND_PASTE_(_module_selected, MODULE_PASTE_(CONFIG_LUA_MODULE_, cfgname))) = {luaname, LRO_ROVAL(map##_map)}
66+
#define NODEMCU_MODULE(cfgname, luaname, map, initfunc) \
67+
const LOCK_IN_SECTION(libs) \
68+
luaR_entry MODULE_PASTE_(lua_lib_,cfgname) = { luaname, LRO_FUNCVAL(initfunc) }; \
69+
const LOCK_IN_SECTION(rotable) \
70+
luaR_entry MODULE_EXPAND_PASTE_(cfgname,MODULE_EXPAND_PASTE_(_module_selected,MODULE_PASTE_(CONFIG_LUA_MODULE_,cfgname))) \
71+
= {luaname, LRO_ROVAL(map ## _map)}
7172
#endif
7273

74+
75+
// helper stringing macros
7376
#define xstr(s) str(s)
7477
#define str(s) #s
7578

79+
// EXTMODNAME is injected by the generated component.mk
7680
#ifdef EXTMODNAME
7781
#define MODNAME xstr(EXTMODNAME)
7882
#else
7983
#define MODNAME "module"
8084
#endif
8185

86+
// use NODEMCU_MODULE_METATABLE() to generate a unique metatable name for your objects:
8287
#define NODEMCU_MODULE_METATABLE() MODULE_EXPAND_(MODNAME xstr(__COUNTER__))
8388

89+
// NODEMCU_MODULE_STD() defines the entry points for an external module:
8490
#define NODEMCU_MODULE_STD() \
8591
static const LOCK_IN_SECTION(libs) \
8692
luaR_entry lua_lib_module = {MODNAME, LRO_FUNCVAL(module_init)}; \

0 commit comments

Comments
 (0)