whitecatboard / Lua-RTOS-ESP32

Lua RTOS for ESP32
Other
1.18k stars 222 forks source link

how to implement a new lua-module #394

Closed elsbiet closed 2 years ago

elsbiet commented 2 years ago

maybe there's someone out there who can give me a hint.

i want do implement a new lua-module being capable of indexed writes and reads of rtc-memory.

i have implemented two functions: static int nvd_set_byte(lua_State L) { .. } static int nvd_get_byte(lua_State L) { ..},

placed these functions into LUA_REG_TYPE array static const LUA_REG_TYPE nvd_map[] = { { LSTRKEY( "set_byte" ), LFUNCVAL( nvd_set_byte ) }, { LSTRKEY( "get_byte" ), LFUNCVAL( nvd_get_byte ) }, {LNILKEY, LNILVAL} };, implemented int luaopen_nvd(lua_State* L) { printf("%s:%d %s\n", FILE, LINE, FUNCTION); return 0; }

registered

MODULE_REGISTER_ROM(NVD, nvd, nvd_map, luaopen_nvd, 1);

and put my modul's name into component.mk.

my module is compiled but apparently it will not be registered - luaopen_nvd is never called and the result of typing nvd at the lua prompt is the string nil.

is there anybody who can tell me what i have missed?

thanks in advance.

the0ne commented 2 years ago

For reading and writing RTC memory, you could also use the functions that are already there. Those can be found in the ULP module.

They support direct access, as well as assigning RTC memory addresses to variables and then using those variables.