/* * NodeMCU extensions to Lua 5.1 for readonly Flash memory support */ #ifndef lnodemcu_h #define lnodemcu_h #include "lua.h" #include "lobject.h" #include "llimits.h" #include "ltm.h" #ifdef LUA_USE_HOST #define LRO_STRKEY(k) k #define LOCK_IN_SECTION(s) #else #define LRO_STRKEY(k) ((__attribute__((aligned(4))) const char *) k) #define LOCK_IN_SECTION(s) __attribute__((used,unused,section(".lua_" #s))) #endif /* Macros used to declare rotable entries */ #define LRO_FUNCVAL(v) {{.p = v}, LUA_TLIGHTFUNCTION} #define LRO_LUDATA(v) {{.p = cast(void*,v)}, LUA_TLIGHTUSERDATA} #define LRO_NILVAL {{.p = NULL}, LUA_TNIL} #define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER} #define LRO_INTVAL(v) LRO_NUMVAL(v) #define LRO_FLOATVAL(v) LRO_NUMVAL(v) #define LRO_ROVAL(v) {{.gc = cast(GCObject *, &(v ## _ROTable))}, LUA_TROTABLE} #define LROT_MARKED 0 //<<<<<<<<<< *** TBD *** >>>>>>>>>>> #define LROT_FUNCENTRY(n,f) {LRO_STRKEY(#n), LRO_FUNCVAL(f)}, #define LROT_LUDENTRY(n,x) {LRO_STRKEY(#n), LRO_LUDATA(x)}, #define LROT_NUMENTRY(n,x) {LRO_STRKEY(#n), LRO_NUMVAL(x)}, #define LROT_INTENTRY(n,x) LROT_NUMENTRY(n,x) #define LROT_FLOATENTRY(n,x) LROT_NUMENTRY(n,x) #define LROT_TABENTRY(n,t) {LRO_STRKEY(#n), LRO_ROVAL(t)}, #define LROT_TABLE(rt) const ROTable rt ## _ROTable #define LROT_ENTRYREF(rt) (rt ##_entries) #define LROT_TABLEREF(rt) (&rt ##_ROTable) #define LROT_BEGIN(rt,mt,f) LROT_TABLE(rt); \ static ROTable_entry rt ## _entries[] = { #define LROT_ENTRIES_IN_SECTION(rt,s) \ static ROTable_entry LOCK_IN_SECTION(s) rt ## _entries[] = { #define LROT_END(rt,mt,f) {NULL, LRO_NILVAL} }; \ const ROTable rt ## _ROTable = { \ .next = (GCObject *)1, .tt = LUA_TROTABLE, .marked = LROT_MARKED, \ .flags = cast(lu_byte, ~(f)), \ .lsizenode = (sizeof(rt ## _entries)/sizeof(ROTable_entry)) - 1, \ .metatable = cast(Table *, mt), \ .entry = cast(ROTable_entry *, rt ## _entries) }; #define LROT_BREAK(rt) }; #define LROT_MASK(m) cast(lu_byte, 1<