Terry Ellison bbeb09b695 Squashed updates do get Lua51 and Lua53 working (#3075)
-  Lots of minor but nasty bugfixes to get all tests to run clean
-  core lua and test suite fixes to allow luac -F to run cleanly against test suite
-  next tranch to get LFS working
-  luac.cross -a options plus fixes from feedback
-  UART fixes and lua.c merge
-  commit of wip prior to rebaselining against current dev
-  more tweaks
2020-06-09 22:26:52 +02:00

51 lines
993 B
C

// Module for RTC user memory access
#include "module.h"
#include "lauxlib.h"
#include "rtc/rtcaccess.h"
static int rtcmem_read32 (lua_State *L)
{
int idx = luaL_checknumber (L, 1);
int n = 1;
if (lua_isnumber (L, 2))
n = lua_tonumber (L, 2);
if (!lua_checkstack (L, n))
return 0;
int ret = 0;
while (n > 0 && idx >= 0 && idx < RTC_USER_MEM_NUM_DWORDS)
{
lua_pushinteger (L, rtc_mem_read (idx++));
--n;
++ret;
}
return ret;
}
static int rtcmem_write32 (lua_State *L)
{
int idx = luaL_checknumber (L, 1);
int n = lua_gettop (L) - 1;
luaL_argcheck (
L, idx + n <= RTC_USER_MEM_NUM_DWORDS, 1, "RTC mem would overrun");
int src = 2;
while (n-- > 0)
{
rtc_mem_write (idx++, lua_tonumber (L, src++));
}
return 0;
}
// Module function map
LROT_BEGIN(rtcmem, NULL, 0)
LROT_FUNCENTRY( read32, rtcmem_read32 )
LROT_FUNCENTRY( write32, rtcmem_write32 )
LROT_END(rtcmem, NULL, 0)
NODEMCU_MODULE(RTCMEM, "rtcmem", rtcmem, NULL);