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
9977b13b
Commit
9977b13b
authored
Mar 03, 2016
by
TerryE
Browse files
Update to address review comments in PR #1105
parent
4f8f192c
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/modules/node.c
View file @
9977b13b
...
@@ -449,19 +449,19 @@ static int node_compile( lua_State* L )
...
@@ -449,19 +449,19 @@ static int node_compile( lua_State* L )
return
0
;
return
0
;
}
}
// Task callback handler for node.task
now
()
// Task callback handler for node.task
.post
()
static
task_handle_t
do_node_task_handle
;
static
task_handle_t
do_node_task_handle
;
static
void
do_node_task
(
task_param_t
task_fn_ref
,
uint8_t
prio
)
static
void
do_node_task
(
task_param_t
task_fn_ref
,
uint8_t
prio
)
{
{
UNUSED
(
prio
);
UNUSED
(
prio
);
lua_State
*
L
=
lua_getstate
();
lua_State
*
L
=
lua_getstate
();
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
(
int
)
task_fn_ref
);
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
(
int
)
task_fn_ref
);
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
(
int
)
task_fn_ref
);
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
(
int
)
task_fn_ref
);
lua_pushinteger
(
L
,
prio
);
lua_pushinteger
(
L
,
prio
);
lua_call
(
L
,
1
,
0
);
lua_call
(
L
,
1
,
0
);
}
}
// Lua: node.task
now(
task_cb)
)
-- schedule a task for execution next
// Lua: node.task
.post([priority],
task_cb) -- schedule a task for execution next
static
int
node_task_post
(
lua_State
*
L
)
static
int
node_task_post
(
lua_State
*
L
)
{
{
int
n
=
1
,
Ltype
=
lua_type
(
L
,
1
);
int
n
=
1
,
Ltype
=
lua_type
(
L
,
1
);
...
@@ -472,14 +472,18 @@ static int node_task_post( lua_State* L )
...
@@ -472,14 +472,18 @@ static int node_task_post( lua_State* L )
Ltype
=
lua_type
(
L
,
++
n
);
Ltype
=
lua_type
(
L
,
++
n
);
}
}
luaL_argcheck
(
L
,
Ltype
==
LUA_TFUNCTION
||
Ltype
==
LUA_TLIGHTFUNCTION
,
n
,
"invalid function"
);
luaL_argcheck
(
L
,
Ltype
==
LUA_TFUNCTION
||
Ltype
==
LUA_TLIGHTFUNCTION
,
n
,
"invalid function"
);
lua_pushvalue
(
L
,
n
);
lua_pushvalue
(
L
,
n
);
int
task_fn_ref
=
luaL_ref
(
L
,
LUA_REGISTRYINDEX
);
int
task_fn_ref
=
luaL_ref
(
L
,
LUA_REGISTRYINDEX
);
if
(
!
do_node_task_handle
)
// bind the task handle to do_node_task on 1st call
if
(
!
do_node_task_handle
)
// bind the task handle to do_node_task on 1st call
do_node_task_handle
=
task_get_id
(
do_node_task
);
do_node_task_handle
=
task_get_id
(
do_node_task
);
task_post
(
priority
,
do_node_task_handle
,
(
task_param_t
)
task_fn_ref
);
if
(
!
task_post
(
priority
,
do_node_task_handle
,
(
task_param_t
)
task_fn_ref
))
{
luaL_unref
(
L
,
LUA_REGISTRYINDEX
,
task_fn_ref
);
luaL_error
(
L
,
"Task queue overflow. Task not posted"
);
}
return
0
;
}
}
// Lua: setcpufreq(mhz)
// Lua: setcpufreq(mhz)
...
...
docs/en/modules/node.md
View file @
9977b13b
...
@@ -412,6 +412,8 @@ Enable a Lua callback or task to post another task request. Note that as per the
...
@@ -412,6 +412,8 @@ Enable a Lua callback or task to post another task request. Note that as per the
example multiple tasks can be posted in any task, but the highest priority is
example multiple tasks can be posted in any task, but the highest priority is
always delivered first.
always delivered first.
If the task queue is full then a queue full error is raised.
####Syntax
####Syntax
`node.task.post([task_priority], function)`
`node.task.post([task_priority], function)`
...
...
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