-
Notifications
You must be signed in to change notification settings - Fork 73
How to add your own module
yichone edited this page Nov 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 for
NULL. 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.
static const LUA_REG_TYPE my_module_map[] = {
{ LSTRKEY( "start" ), LFUNCVAL( my_module_start ) },
{ LSTRKEY( "stop" ), LFUNCVAL( my_module_stop ) },
{ LNILKEY, LNILVAL }
};
The implementation of your method:
void my_module_start(void) {
printf("My module start\n");
}
void my_module_stop(void) {
printf("My module stop\n");
}
The methods only output test message.
After adding your module, you can invoke them in Lua like this:
my_module.start();
my_module.stop();
Shenzhen Doctors of Intelligence & Technology Co. Ltd: wwww.doit.am, SZDOIT official online Shops: www.vvdoit.com, and www.smartarduino.com
- Preface
- Start to Play ESP8266
- ESP-F
- ESP-F1
- ESP-F2
- ESP-E
- ESP-01
- ESP-01s
- ESP-07
- ESP-12E
- ESP-12F
- ESP-S
- DT-W5G1
- DMP-L1
- DMP-P1
- ESP-M1
- ESP-M2
- ESP-M3
- ESP-M4
- ESP-1
- ESP32
- ESP32U
- ESP32-C2
- NRF24l01
- Preface
- NodeMCU
- miniNodeMCU
- WiFi Shield
- ESPduino
- 2-way&16-way motor&servo shield
- ESP32
- DT-06(TTLtoWiFi)
- ESPDuino-32
- 2/4ch DC motor & 16ch servo shield---motor and servo shield
- Preface
- Video
- Softwares
- Motors & Servos
- Assembling Chassis
- Wireless WiFi Tank Car
- Wireless WiFi Video Tank Car
- RC Robot
- Preface
- Humanoid
- Gripper/Claw
- Robot Arm
- 3dof Robot Arm
- Visual Programming blocks