Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to add your own module

yichone edited this pageNov 30, 2016 ·6 revisions

To add your own module is easy. Just follow the steps below:

  • Add the module source code to the path: LuaNode_Esp32/components/modules
  • If you add a module, say my_module, and your code named my_module.c, then you should register your module. Use the macro named LUANODE_MODULE to register your module.
// The registration macro// The first parameter MY_MODULE is a string to be used for registration. Use your module name.// The second parameter is the module name to be required in lua, you invoke the methods in your module by using this name.// The third parameter is a key-value map for your module methods and their names.// The last parameter is a init function, which will be called when module initialize. Usually, you can set it forNULL.LUANODE_MODULE(MY_MODULE,"my_module",my_module_map,NULL);
  • How to add methods to your module? Add your methods as well as their name to the key-value map mentioned above.
// The module function map// In this example, we have two custom methods for my_module. The two methods are my_module_start and my_module_stop,// and their corresponding name is start and stop respectively.staticconstLUA_REG_TYPEmy_module_map[]= {    {LSTRKEY("start" ),LFUNCVAL(my_module_start ) },    {LSTRKEY("stop" ),LFUNCVAL(my_module_stop ) },    {LNILKEY,LNILVAL }};

The implementation of your method:

voidmy_module_start(void) {printf("My module start\n");}voidmy_module_stop(void) {printf("My module stop\n");}Themethodsonlyoutputtestmessage.Afteraddingyourmodule,youcaninvoketheminLualikethis:my_module.start();my_module.stop();

Shenzhen Doctors of Intelligence & Technology Co. Ltd:wwww.doit.am, SZDOIT official online Shops:www.vvdoit.com, andwww.smartarduino.com

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp