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
74fd5184
Commit
74fd5184
authored
Jul 14, 2018
by
Ryan Hartlage
Browse files
Use RO metatable for MQTT module; add link to docs in mkdocs.yml
parent
ba57b0fa
Changes
2
Show whitespace changes
Inline
Side-by-side
components/modules/mqtt.c
View file @
74fd5184
...
...
@@ -668,31 +668,7 @@ static int mqtt_new( lua_State* L )
lua_pushlightuserdata
(
L
,
mqtt_cfg
);
lua_setfield
(
L
,
-
2
,
"_settings"
);
// set t["_mqtt"] = client
lua_pushcfunction
(
L
,
mqtt_connect
);
lua_setfield
(
L
,
-
2
,
"connect"
);
// set t["connect"] = lmqtt_connect
lua_pushcfunction
(
L
,
mqtt_close
);
lua_setfield
(
L
,
-
2
,
"close"
);
// set t["close"] = lmqtt_close
lua_pushcfunction
(
L
,
mqtt_lwt
);
lua_setfield
(
L
,
-
2
,
"lwt"
);
// set t["lwt"] = lmqtt_lwt
lua_pushcfunction
(
L
,
mqtt_publish
);
lua_setfield
(
L
,
-
2
,
"publish"
);
// set t["publish"] = lmqtt_publish
lua_pushcfunction
(
L
,
mqtt_subscribe
);
lua_setfield
(
L
,
-
2
,
"subscribe"
);
// set t["subscribe"] = lmqtt_subscribe
lua_pushcfunction
(
L
,
mqtt_unsubscribe
);
lua_setfield
(
L
,
-
2
,
"unsubscribe"
);
// set t["unsubscribe"] = lmqtt_unsubscribe
lua_pushcfunction
(
L
,
mqtt_on
);
lua_setfield
(
L
,
-
2
,
"on"
);
// set t["on"] = lmqtt_on
lua_pushcfunction
(
L
,
mqtt_delete
);
lua_setfield
(
L
,
-
2
,
"__gc"
);
// set t["__gc"] = lmqtt_delete
lua_pushvalue
(
L
,
1
);
//make a copy of the table
luaL_getmetatable
(
L
,
"mqtt.mt"
);
lua_setmetatable
(
L
,
-
2
);
hConn
=
task_get_id
(
_connected_cb
);
...
...
@@ -706,6 +682,19 @@ static int mqtt_new( lua_State* L )
return
1
;
//leave table on top of the stack
}
static
const
LUA_REG_TYPE
mqtt_metatable_map
[]
=
{
{
LSTRKEY
(
"connect"
),
LFUNCVAL
(
mqtt_connect
)},
{
LSTRKEY
(
"close"
),
LFUNCVAL
(
mqtt_close
)},
{
LSTRKEY
(
"lwt"
),
LFUNCVAL
(
mqtt_lwt
)},
{
LSTRKEY
(
"publish"
),
LFUNCVAL
(
mqtt_publish
)},
{
LSTRKEY
(
"subscribe"
),
LFUNCVAL
(
mqtt_subscribe
)},
{
LSTRKEY
(
"unsubscribe"
),
LFUNCVAL
(
mqtt_unsubscribe
)},
{
LSTRKEY
(
"on"
),
LFUNCVAL
(
mqtt_on
)},
{
LSTRKEY
(
"__gc"
),
LFUNCVAL
(
mqtt_delete
)},
{
LSTRKEY
(
"__index"
),
LROVAL
(
mqtt_metatable_map
)},
{
LNILKEY
,
LNILVAL
}
};
// Module function map
static
const
LUA_REG_TYPE
mqtt_map
[]
=
{
...
...
@@ -713,5 +702,9 @@ static const LUA_REG_TYPE mqtt_map[] = {
{
LNILKEY
,
LNILVAL
}
};
NODEMCU_MODULE
(
MQTT
,
"mqtt"
,
mqtt_map
,
NULL
);
int
luaopen_mqtt
(
lua_State
*
L
)
{
luaL_rometatable
(
L
,
"mqtt.mt"
,
(
void
*
)
mqtt_metatable_map
);
// create metatable for mqtt
return
0
;
}
NODEMCU_MODULE
(
MQTT
,
"mqtt"
,
mqtt_map
,
luaopen_mqtt
);
mkdocs.yml
View file @
74fd5184
...
...
@@ -41,6 +41,7 @@ pages:
-
'
gpio'
:
'
en/modules/gpio.md'
-
'
i2c'
:
'
en/modules/i2c.md'
-
'
ledc'
:
'
en/modules/ledc.md'
-
'
mqtt'
:
'
en/modules/mqtt.md'
-
'
net'
:
'
en/modules/net.md'
-
'
node'
:
'
en/modules/node.md'
-
'
ow
(1-Wire)'
:
'
en/modules/ow.md'
...
...
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