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"
|
2019-05-08 13:08:20 +02:00
|
|
|
#include "lrotable.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}
|
2019-05-08 13:08:20 +02:00
|
|
|
|
2018-10-13 16:14:33 +02:00
|
|
|
#ifdef LUA_CROSS_COMPILER
|
2019-05-08 13:08:20 +02:00
|
|
|
#define LRO_STRKEY(k) k
|
2018-10-13 16:14:33 +02:00
|
|
|
#else
|
2019-05-08 13:08:20 +02:00
|
|
|
#define LRO_STRKEY(k) ((STORE_ATTR char *) k)
|
2018-10-13 16:14:33 +02:00
|
|
|
#endif
|
2019-05-08 13:08:20 +02:00
|
|
|
|
|
|
|
#define LROT_TABLE(t) static const LUA_REG_TYPE t ## _map[];
|
|
|
|
#define LROT_PUBLIC_TABLE(t) const LUA_REG_TYPE t ## _map[];
|
|
|
|
#define LROT_TABLEREF(t) ((void *) t ## _map)
|
|
|
|
#define LROT_BEGIN(t) static const LUA_REG_TYPE t ## _map [] = {
|
|
|
|
#define LROT_PUBLIC_BEGIN(t) const LUA_REG_TYPE t ## _map[] = {
|
|
|
|
#define LROT_EXTERN(t) extern const LUA_REG_TYPE t ## _map[]
|
|
|
|
#define LROT_TABENTRY(n,t) {LRO_STRKEY(#n), LRO_ROVAL(t ## _map)},
|
|
|
|
#define LROT_FUNCENTRY(n,f) {LRO_STRKEY(#n), LRO_FUNCVAL(f)},
|
|
|
|
#define LROT_NUMENTRY(n,x) {LRO_STRKEY(#n), LRO_NUMVAL(x)},
|
|
|
|
#define LROT_LUDENTRY(n,x) {LRO_STRKEY(#n), LRO_LUDATA((void *) x)},
|
|
|
|
#define LROT_END(t,mt, f) {NULL, LRO_NILVAL} };
|
|
|
|
#define LROT_BREAK(t) };
|
|
|
|
|
|
|
|
#define LUA_REG_TYPE luaR_entry
|
|
|
|
#define LREGISTER(L, name, table) return 0
|
2014-12-22 12:35:05 +01:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
/* An entry in the read only table */
|
2018-10-13 16:14:33 +02:00
|
|
|
typedef struct luaR_entry {
|
2019-05-08 13:08:20 +02:00
|
|
|
const char *key;
|
2014-12-22 12:35:05 +01:00
|
|
|
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
|
2019-02-17 19:26:29 +01:00
|
|
|
* nil record. The convention is to use ROtable * to refer to the entire vector
|
2018-10-13 16:14:33 +02:00
|
|
|
* 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
|
|
|
|
|
|
|
/*
|
2019-02-17 19:26:29 +01: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
|
2018-10-13 16:14:33 +02:00
|
|
|
* VM changes on the more developer-friendly hot gdb environment.
|
|
|
|
*/
|
|
|
|
#if defined(LUA_CROSS_COMPILER)
|
|
|
|
|
2019-02-23 15:09:29 +01:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
//msvc build uses these dummy vars to locate the beginning and ending addresses of the RO data
|
2019-02-23 20:49:30 +01:00
|
|
|
extern const char _ro_start[], _ro_end[];
|
2019-02-23 15:09:29 +01:00
|
|
|
#define IN_RODATA_AREA(p) (((const char*)(p)) >= _ro_start && ((const char *)(p)) <= _ro_end)
|
|
|
|
#else /* one of the POSIX variants */
|
2018-10-13 16:14:33 +02:00
|
|
|
#if defined(__CYGWIN__)
|
|
|
|
#define _RODATA_END __end__
|
2019-02-23 15:09:29 +01:00
|
|
|
#elif defined(__MINGW32__)
|
|
|
|
#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
|
2019-02-17 19:26:29 +01:00
|
|
|
#endif
|
2018-10-13 16:14:33 +02:00
|
|
|
extern const char _RODATA_END[];
|
|
|
|
#define IN_RODATA_AREA(p) (((const char *)(p)) < _RODATA_END)
|
2019-02-23 15:09:29 +01:00
|
|
|
#endif /* defined(_MSC_VER) */
|
2018-10-13 16:14:33 +02:00
|
|
|
|
|
|
|
#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)
|
|
|
|
|
2019-02-23 15:09:29 +01:00
|
|
|
#endif /* defined(LUA_CROSS_COMPILER) */
|
2014-12-22 12:35:05 +01:00
|
|
|
|
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
|