2014-12-22 12:35:05 +01:00
|
|
|
/* Read-only tables for Lua */
|
|
|
|
|
|
|
|
#ifndef lrotable_h
|
|
|
|
#define lrotable_h
|
|
|
|
|
|
|
|
#include "lua.h"
|
|
|
|
#include "luaconf.h"
|
2018-03-08 01:20:59 +01:00
|
|
|
#include "lobject.h"
|
|
|
|
#include "llimits.h"
|
2014-12-22 12:35:05 +01:00
|
|
|
|
|
|
|
/* Macros one can use to define rotable entries */
|
|
|
|
#define LRO_FUNCVAL(v) {{.p = v}, LUA_TLIGHTFUNCTION}
|
2015-03-01 23:11:24 +01:00
|
|
|
#define LRO_LUDATA(v) {{.p = v}, LUA_TLIGHTUSERDATA}
|
2014-12-22 12:35:05 +01:00
|
|
|
#define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER}
|
|
|
|
#define LRO_ROVAL(v) {{.p = (void*)v}, LUA_TROTABLE}
|
|
|
|
#define LRO_NILVAL {{.p = NULL}, LUA_TNIL}
|
2018-10-13 16:14:33 +02:00
|
|
|
#ifdef LUA_CROSS_COMPILER
|
2014-12-22 12:35:05 +01:00
|
|
|
#define LRO_STRKEY(k) {LUA_TSTRING, {.strkey = k}}
|
2018-10-13 16:14:33 +02:00
|
|
|
#else
|
|
|
|
#define LRO_STRKEY(k) {LUA_TSTRING, {.strkey = (STORE_ATTR char *) k}}
|
|
|
|
#endif
|
2014-12-22 12:35:05 +01:00
|
|
|
#define LRO_NUMKEY(k) {LUA_TNUMBER, {.numkey = k}}
|
|
|
|
#define LRO_NILKEY {LUA_TNIL, {.strkey=NULL}}
|
|
|
|
|
|
|
|
/* Maximum length of a rotable name and of a string key*/
|
|
|
|
#define LUA_MAX_ROTABLE_NAME 32
|
|
|
|
|
|
|
|
/* Type of a numeric key in a rotable */
|
|
|
|
typedef int luaR_numkey;
|
|
|
|
|
|
|
|
/* The next structure defines the type of a key */
|
2018-10-13 16:14:33 +02:00
|
|
|
typedef struct {
|
2014-12-22 12:35:05 +01:00
|
|
|
int type;
|
2018-10-13 16:14:33 +02:00
|
|
|
union {
|
2014-12-22 12:35:05 +01:00
|
|
|
const char* strkey;
|
|
|
|
luaR_numkey numkey;
|
|
|
|
} id;
|
|
|
|
} luaR_key;
|
|
|
|
|
|
|
|
/* An entry in the read only table */
|
2018-10-13 16:14:33 +02:00
|
|
|
typedef struct luaR_entry {
|
2014-12-22 12:35:05 +01:00
|
|
|
const luaR_key key;
|
|
|
|
const TValue value;
|
|
|
|
} luaR_entry;
|
|
|
|
|
2018-10-13 16:14:33 +02:00
|
|
|
/*
|
|
|
|
* The current ROTable implmentation is a vector of luaR_entry terminated by a
|
|
|
|
* nil record. The convention is to use ROtable * to refer to the entire vector
|
|
|
|
* as a logical ROTable.
|
|
|
|
*/
|
|
|
|
typedef const struct luaR_entry ROTable;
|
|
|
|
|
|
|
|
const TValue* luaR_findentry(ROTable *tab, TString *key, unsigned *ppos);
|
|
|
|
const TValue* luaR_findentryN(ROTable *tab, luaR_numkey numkey, unsigned *ppos);
|
|
|
|
void luaR_next(lua_State *L, ROTable *tab, TValue *key, TValue *val);
|
|
|
|
void* luaR_getmeta(ROTable *tab);
|
2014-12-22 12:35:05 +01:00
|
|
|
int luaR_isrotable(void *p);
|
2018-10-13 16:14:33 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set inRO check depending on platform. Note that this implementation needs
|
|
|
|
* to work on both the host (luac.cross) and ESP targets. The luac.cross
|
|
|
|
* VM is used for the -e option, and is primarily used to be able to debug
|
|
|
|
* VM changes on the more developer-friendly hot gdb environment.
|
|
|
|
*/
|
|
|
|
#if defined(LUA_CROSS_COMPILER)
|
|
|
|
|
|
|
|
#if defined(__CYGWIN__)
|
|
|
|
#define _RODATA_END __end__
|
2014-12-22 12:35:05 +01:00
|
|
|
#else
|
2018-10-13 16:14:33 +02:00
|
|
|
#define _RODATA_END _edata
|
|
|
|
#endif
|
|
|
|
extern const char _RODATA_END[];
|
|
|
|
#define IN_RODATA_AREA(p) (((const char *)(p)) < _RODATA_END)
|
|
|
|
|
|
|
|
#else /* xtensa tool chain for ESP target */
|
|
|
|
|
|
|
|
extern const char _irom0_text_start[];
|
|
|
|
extern const char _irom0_text_end[];
|
|
|
|
#define IN_RODATA_AREA(p) (((const char *)(p)) >= _irom0_text_start && ((const char *)(p)) <= _irom0_text_end)
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
#endif
|
|
|
|
|
2018-10-13 16:14:33 +02:00
|
|
|
/* Return 1 if the given pointer is a rotable */
|
|
|
|
#define luaR_isrotable(p) IN_RODATA_AREA(p)
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
#endif
|