https://github.com/nodemcu/nodemcu-firm ... w-17892825
I tried to set up a error handler using the task api as requested by Philip Gladstone.
Initail hints on the tastk api came from
http://nodemcu.readthedocs.io/en/master ... loper-faq/
and task.h
Two problems:
- I expected the param field being handled transparentely, but my content gets modified
- The very reason to use the task api was to get sure to have a lua context again, but instead I get a lua panic resultiong in module reboot
I tagged and pushed the code to github for reference:
https://github.com/wolfgangr/nodemcu-fi ... net_info.c
As my debug print shows, registering the callback, placing the task and receiving the task callback basically works.
This is the essence of my task callback:
static void net_if_error (task_param_t param, uint8_t prio ) {
NET_INFO_DEBUG(" entering net_if_error \n");
// get lua state (I'm supposed to be able in the task, right?)
lua_State *L = lua_getstate();
NET_INFO_DEBUG(" ... in error got lua state: 0x%x\n", L);
char *errmsg = (char*) param ;
// char errmsg[] = "lets try it with a dummy message";
NET_INFO_DEBUG(" ... in error got message: %s - pointers were 0x%x from 0x%x \n", errmsg, errmsg , param );
lua_pushstring(L , errmsg);
NET_INFO_DEBUG(" ... pushed my msg to the stack...\n" );
lua_error(L);
NET_INFO_DEBUG(" ... and called a lua error (will I see this?)\n" );
}A test run on the module yields
net_info.dummy()
### DEBUG: net_info ### : entering task error dummy
### DEBUG: net_info ### : ... in dummy got lua state: 0x3ffefb98
### DEBUG: net_info ### : and my message is I am the stupid hello task dummy
### DEBUG: net_info ### : have casted my param from 0x3ffffd30 to 0x3ffffd30
### DEBUG: net_info ### : ... have postet my msg task now...
> ### DEBUG: net_info ### : entering net_if_error
### DEBUG: net_info ### : ... in error got lua state: 0x3ffefb98
### DEBUG: net_info ### : ... in error got message: V - pointers were 0x3ffffd30 from 0x3ffffd30
### DEBUG: net_info ### : ... pushed my msg to the stack...
PANIC: unprotected error in call to Lua API (V)
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
As we see, the pointer 0x3ffffd30 was not modified from the task machine, but the content changed from "I am the stupid hello task dummy" to "V" (this is reproducible).
However, even when I bypass the param handling, using a literal dummy string like "lets try it with a dummy message", I still get the panic. So there must something wrong with the lua state, although it is still the same pointer as in the function registering the task.
When I call lua_err without the task api, it behavs as expected and documented in https://www.lua.org/manual/5.1/manual.html#lua_error : a controlled lua error with error message, stack trace and return to the command line - no reboot:
=net_info.panic()
=net_info.panic()
### DEBUG: net_info ### : ... this is my panicking message: Does lua_error really produce a panic?
### DEBUG: net_info ### : ... pushed my msg to the stack...
Does lua_error really produce a panic?
stack traceback:
[C]: in function 'panic'
stdin:1: in main chunk
From the traces, I suspect that the task api modifes the data referred by param, thus screwing the lua state.
But what then should go to task_post param?
Where can I find doucmentation?
I grepped the source tree and the chain of include files, but found no help there.