feat(lua): Port of NodeMCU Lua53 read-only tables (#2994)

* chore(lua): revert useless c light function change

This change was part of the eLua LTR patches (based on 5.1), whereby this feature was already integrated in Lua 5.2.

* feat(lua): port of NodeMCU Lua53 read-only tables

# Conflicts:
#	radio/src/lua/CMakeLists.txt
#	radio/src/lua/api_general.cpp

* fix(nv14): missing SDRAM definition

* fix: l_mathop

* fix: use float functions in drawPower()

* fix: ltable resize

* fix: correct name is "bit32"

* fix: first Lua context must be closed last

As the lookup cache is attached to that one

* Revert to Lua using double

* Ensure byte-code compatibility

* Fix possible compatibility issue with `lua_typename`/`luaL_typename`

* Fix Bitmap symbol table

* Re-add table lib for COLORLCD
This commit is contained in:
Raphael Coeffic
2023-02-09 20:29:56 +10:00
committed by GitHub
parent 72193eda82
commit be3f8d74a8
43 changed files with 1387 additions and 2211 deletions
+31 -45
View File
@@ -23,7 +23,6 @@
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "lrotable.h"
#include "ltm.h"
#include "lundump.h"
#include "lvm.h"
@@ -261,7 +260,7 @@ LUA_API const char *lua_typename (lua_State *L, int t) {
LUA_API int lua_iscfunction (lua_State *L, int idx) {
StkId o = index2addr(L, idx);
return (ttislcf(o) || ttislightfunction(o) || (ttisCclosure(o)));
return (ttislcf(o) || (ttisCclosure(o)));
}
@@ -407,10 +406,11 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
LUA_API size_t lua_rawlen (lua_State *L, int idx) {
StkId o = index2addr(L, idx);
switch (ttypenv(o)) {
case LUA_TSTRING: return tsvalue(o)->len;
switch (ttype(o)) {
case LUA_TSHRSTR:
case LUA_TLNGSTR: return tsvalue(o)->len;
case LUA_TUSERDATA: return uvalue(o)->len;
case LUA_TTABLE: return luaH_getn(hvalue(o));
case LUA_TTBLRAM: return luaH_getn(hvalue(o));
default: return 0;
}
}
@@ -418,7 +418,7 @@ LUA_API size_t lua_rawlen (lua_State *L, int idx) {
LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
StkId o = index2addr(L, idx);
if (ttislcf(o)) return lcfvalue(o);
if (ttislcf(o)) return fvalue(o);
else if (ttisCclosure(o))
return clCvalue(o)->f;
else return NULL; /* not a C function */
@@ -444,17 +444,15 @@ LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
LUA_API const void *lua_topointer (lua_State *L, int idx) {
StkId o = index2addr(L, idx);
switch (ttype(o)) {
case LUA_TTABLE: return hvalue(o);
case LUA_TTBLRAM:
case LUA_TTBLROF: return hvalue(o);
case LUA_TLCL: return clLvalue(o);
case LUA_TCCL: return clCvalue(o);
case LUA_TLCF: return cast(void *, cast(size_t, lcfvalue(o)));
case LUA_TLCF: return cast(void *, cast(size_t, fvalue(o)));
case LUA_TTHREAD: return thvalue(o);
case LUA_TUSERDATA:
case LUA_TLIGHTUSERDATA:
return lua_touserdata(L, idx);
case LUA_TROTABLE:
case LUA_TLIGHTFUNCTION:
return pvalue(o);
default: return NULL;
}
}
@@ -558,7 +556,7 @@ LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
lua_lock(L);
if (n == 0) {
setlcfvalue(L->top, fn);
setfvalue(L->top, fn);
}
else {
Closure *cl;
@@ -576,6 +574,7 @@ LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
lua_unlock(L);
}
LUA_API void lua_pushboolean (lua_State *L, int b) {
lua_lock(L);
setbvalue(L->top, (b != 0)); /* ensure that true is 1 */
@@ -591,19 +590,6 @@ LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {
lua_unlock(L);
}
LUA_API void lua_pushrotable (lua_State *L, void *p) {
lua_lock(L);
setrvalue(L->top, p);
api_incr_top(L);
lua_unlock(L);
}
LUA_API void lua_pushlightfunction(lua_State *L, void *p) {
lua_lock(L);
setlfvalue(L->top, p);
api_incr_top(L);
lua_unlock(L);
}
LUA_API int lua_pushthread (lua_State *L) {
lua_lock(L);
@@ -613,30 +599,27 @@ LUA_API int lua_pushthread (lua_State *L) {
return (G(L)->mainthread == L);
}
LUA_API void lua_pushrotable (lua_State *L, const ROTable *t) {
lua_lock(L);
sethvalue(L, L->top, cast(Table *, t));
api_incr_top(L);
lua_unlock(L);
}
/*
** get functions (Lua -> stack)
*/
LUA_API void lua_getglobal (lua_State *L, const char *var) {
TValue value;
luaR_result found;
TRACE_LUA_INTERNALS("lua_getglobal() '%s'", var);
Table *reg = hvalue(&G(L)->l_registry);
const TValue *gt; /* global table */
lua_lock(L);
found = luaR_findglobal(L, var, &value);
if (found && ttislightfunction(&value)) {
setsvalue2s(L, L->top++, luaS_new(L, var));
setlfvalue(L->top - 1, lfvalue(&value))
}
else {
gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
setsvalue2s(L, L->top++, luaS_new(L, var));
luaV_gettable(L, gt, L->top - 1, L->top - 1);
}
gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
setsvalue2s(L, L->top++, luaS_new(L, var));
luaV_gettable(L, gt, L->top - 1, L->top - 1);
lua_unlock(L);
}
@@ -797,7 +780,7 @@ LUA_API void lua_rawset (lua_State *L, int idx) {
lua_lock(L);
api_checknelems(L, 2);
t = index2addr(L, idx);
api_check(L, ttistable(t), "table expected");
api_check(L, ttisrwtable(t), "RW table expected");
setobj2t(L, luaH_set(L, hvalue(t), L->top-2), L->top-1);
invalidateTMcache(hvalue(t));
luaC_barrierback(L, gcvalue(t), L->top-1);
@@ -811,7 +794,7 @@ LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
lua_lock(L);
api_checknelems(L, 1);
t = index2addr(L, idx);
api_check(L, ttistable(t), "table expected");
api_check(L, ttisrwtable(t), "RW table expected");
luaH_setint(L, hvalue(t), n, L->top - 1);
luaC_barrierback(L, gcvalue(t), L->top-1);
L->top--;
@@ -825,7 +808,7 @@ LUA_API void lua_rawsetp (lua_State *L, int idx, const void *p) {
lua_lock(L);
api_checknelems(L, 1);
t = index2addr(L, idx);
api_check(L, ttistable(t), "table expected");
api_check(L, ttisrwtable(t), "RW table expected");
setpvalue(&k, cast(void *, p));
setobj2t(L, luaH_set(L, hvalue(t), &k), L->top - 1);
luaC_barrierback(L, gcvalue(t), L->top - 1);
@@ -846,8 +829,8 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
api_check(L, ttistable(L->top - 1), "table expected");
mt = hvalue(L->top - 1);
}
switch (ttypenv(obj)) {
case LUA_TTABLE: {
switch (ttype(obj)) {
case LUA_TTBLRAM: {
hvalue(obj)->metatable = mt;
if (mt) {
luaC_objbarrierback(L, gcvalue(obj), mt);
@@ -855,6 +838,9 @@ LUA_API int lua_setmetatable (lua_State *L, int objindex) {
}
break;
}
case LUA_TTBLROF: {
luai_apicheck(L, "RW table expected");
}
case LUA_TUSERDATA: {
uvalue(obj)->metatable = mt;
if (mt) {
+36 -8
View File
@@ -298,6 +298,18 @@ LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {
}
LUALIB_API int luaL_rometatable (lua_State *L, const char* tname, const ROTable *p) {
lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */
if (!lua_isnil(L, -1)) /* name already in use? */
return 0; /* leave previous value on top, but return 0 */
lua_pop(L, 1);
lua_pushrotable(L, p);
lua_pushvalue(L, -1);
lua_setfield(L, LUA_REGISTRYINDEX, tname); /* registry.name = metatable */
return 1;
}
LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {
void *p = lua_touserdata(L, ud);
if (p != NULL) { /* value is a userdata? */
@@ -923,16 +935,32 @@ LUALIB_API int luaL_getsubtable (lua_State *L, int idx, const char *fname) {
*/
LUALIB_API void luaL_requiref (lua_State *L, const char *modname,
lua_CFunction openf, int glb) {
lua_pushcfunction(L, openf);
lua_pushstring(L, modname); /* argument to open function */
lua_call(L, 1, 1); /* open module */
int inROM = 0;
luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED");
lua_pushvalue(L, -2); /* make copy of module (call result) */
lua_setfield(L, -2, modname); /* _LOADED[modname] = module */
lua_pop(L, 1); /* remove _LOADED table */
lua_getfield(L, -1, modname); /* LOADED[modname] */
if (!lua_toboolean(L, -1)) { /* package not in LOADED table? */
lua_getglobal(L, "ROM"); /* try the ROM entry */
if(!lua_isnil(L,-1)) {
lua_getfield(L, -1, modname); /* ROM[name] */
inROM = lua_toboolean(L, -1);
lua_pop(L, 3);
} else
lua_pop(L, 2);
if (inROM) /* package is in ROM */
glb = 0; /* suppress setting _G entry */
lua_pushcfunction(L, openf);
lua_pushstring(L, modname); /* argument to open function */
lua_call(L, 1, 1); /* call 'openf' to open module */
if (lua_toboolean(L, -1) && !inROM) { /* if not in ROM & result is returned */
lua_pushvalue(L, -1); /* make copy of module (call result) */
lua_setfield(L, -3, modname); /* LOADED[modname] = module */
}
}
lua_remove(L, -2); /* remove LOADED table */
if (glb) {
lua_pushvalue(L, -1); /* copy of 'mod' */
lua_setglobal(L, modname); /* _G[modname] = module */
lua_pushvalue(L, -1); /* copy of module */
lua_setglobal(L, modname); /* _G[modname] = module */
}
}
+6
View File
@@ -13,6 +13,9 @@
#include "lua.h"
#ifdef LUA_LIB
#include "lro_defs.h"
#endif
/* extra error code for `luaL_load' */
@@ -62,6 +65,9 @@ LUALIB_API void (luaL_checkany) (lua_State *L, int narg);
LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname);
LUALIB_API void (luaL_setmetatable) (lua_State *L, const char *tname);
LUALIB_API int (luaL_rometatable) (lua_State *L, const char* tname, const ROTable *p);
LUALIB_API void *(luaL_testudata) (lua_State *L, int ud, const char *tname);
LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname);
+46 -38
View File
@@ -4,19 +4,22 @@
** See Copyright Notice in lua.h
*/
#define lbaselib_c
#define LUA_LIB
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define lbaselib_c
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "lrotable.h"
// ROTable
#include "lobject.h"
static int luaB_print (lua_State *L) {
int n = lua_gettop(L); /* number of arguments */
@@ -411,39 +414,44 @@ static int luaB_tostring (lua_State *L) {
return 1;
}
const luaL_Reg baselib[] = {
{"assert", luaB_assert},
{"collectgarbage", luaB_collectgarbage},
{"dofile", luaB_dofile},
{"error", luaB_error},
{"getmetatable", luaB_getmetatable},
{"ipairs", luaB_ipairs},
{"loadfile", luaB_loadfile},
{"load", luaB_load},
#if defined(LUA_COMPAT_LOADSTRING)
{"loadstring", luaB_load},
#endif
{"next", luaB_next},
{"pairs", luaB_pairs},
{"pcall", luaB_pcall},
{"print", luaB_print},
{"rawequal", luaB_rawequal},
{"rawlen", luaB_rawlen},
{"rawget", luaB_rawget},
{"rawset", luaB_rawset},
{"select", luaB_select},
{"setmetatable", luaB_setmetatable},
{"tonumber", luaB_tonumber},
{"tostring", luaB_tostring},
{"type", luaB_type},
{"xpcall", luaB_xpcall},
{NULL, NULL}
};
extern LROT_TABLE(etxlib);
#if 0
// TODO
const luaR_value_entry baselib_vals[] = {
{"_VERSION", LUA_VERSION},
{NULL, 0}
};
LROT_BEGIN(base_func, NULL, 0)
LROT_FUNCENTRY(assert, luaB_assert)
LROT_FUNCENTRY(collectgarbage, luaB_collectgarbage)
LROT_FUNCENTRY(dofile, luaB_dofile)
LROT_FUNCENTRY(error, luaB_error)
LROT_FUNCENTRY(getmetatable, luaB_getmetatable)
LROT_FUNCENTRY(ipairs, luaB_ipairs)
LROT_FUNCENTRY(loadfile, luaB_loadfile)
LROT_FUNCENTRY(load, luaB_load)
#if defined(LUA_COMPAT_LOADSTRING)
LROT_FUNCENTRY(loadstring, luaB_load)
#endif
LROT_FUNCENTRY(next, luaB_next)
LROT_FUNCENTRY(pairs, luaB_pairs)
LROT_FUNCENTRY(pcall, luaB_pcall)
LROT_FUNCENTRY(print, luaB_print)
LROT_FUNCENTRY(rawequal, luaB_rawequal)
LROT_FUNCENTRY(rawlen, luaB_rawlen)
LROT_FUNCENTRY(rawget, luaB_rawget)
LROT_FUNCENTRY(rawset, luaB_rawset)
LROT_FUNCENTRY(select, luaB_select)
LROT_FUNCENTRY(setmetatable, luaB_setmetatable)
LROT_FUNCENTRY(tonumber, luaB_tonumber)
LROT_FUNCENTRY(tostring, luaB_tostring)
LROT_FUNCENTRY(type, luaB_type)
LROT_FUNCENTRY(xpcall, luaB_xpcall)
LROT_END(base_func, NULL, 0)
extern LROT_TABLE(rotables);
LUAMOD_API int luaopen_base (lua_State *L) {
lua_pushglobaltable(L); /* set global _G */
lua_pushliteral(L, LUA_VERSION); /* set global _VERSION */
lua_setfield(L, -2, "_VERSION");
lua_createtable (L, 0, 1); /* mt for _G */
lua_pushrotable(L, LROT_TABLEREF(rotables));
lua_setfield(L, -2, "__index"); /* mt.__index=ROM table */
lua_setmetatable(L, -2);
return 1; /* returns _G */
}
+18 -20
View File
@@ -5,14 +5,13 @@
*/
#define lbitlib_c
#define LUA_LIB
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "lrotable.h"
/* number of bits to consider in a number */
#if !defined(LUA_NBITS)
#define LUA_NBITS 32
@@ -186,26 +185,25 @@ static int b_replace (lua_State *L) {
}
const luaL_Reg bitlib[] = {
{"arshift", b_arshift},
{"band", b_and},
{"bnot", b_not},
{"bor", b_or},
{"bxor", b_xor},
{"btest", b_test},
{"extract", b_extract},
{"lrotate", b_lrot},
{"lshift", b_lshift},
{"replace", b_replace},
{"rrotate", b_rrot},
{"rshift", b_rshift},
{NULL, NULL}
};
LROT_BEGIN(bitlib, NULL, 0)
LROT_FUNCENTRY( arshift, b_arshift )
LROT_FUNCENTRY( band, b_and )
LROT_FUNCENTRY( bnot, b_not )
LROT_FUNCENTRY( bor, b_or )
LROT_FUNCENTRY( bxor, b_xor )
LROT_FUNCENTRY( btest, b_test )
LROT_FUNCENTRY( extract, b_extract )
LROT_FUNCENTRY( lrotate, b_lrot )
LROT_FUNCENTRY( lshift, b_lshift )
LROT_FUNCENTRY( replace, b_replace )
LROT_FUNCENTRY( rrotate, b_rrot )
LROT_FUNCENTRY( rshift, b_rshift )
LROT_END(bitlib, NULL, 0)
const luaR_value_entry bitlib_vals[] = {
{NULL, 0}
};
/*
** Open bit library
*/
LUAMOD_API int luaopen_bit32 (lua_State *L) {
return 0;
}
+1 -4
View File
@@ -305,10 +305,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
ptrdiff_t funcr = savestack(L, func);
switch (ttype(func)) {
case LUA_TLCF: /* light C function */
f = lcfvalue(func);
goto Cfunc;
case LUA_TLIGHTFUNCTION:
f = check_exp(ttislightfunction(func), val_(func).f);
f = fvalue(func);
goto Cfunc;
case LUA_TCCL: { /* C closure */
f = clCvalue(func)->f;
+95 -51
View File
@@ -14,72 +14,116 @@
#define linit_c
#define LUA_LIB
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include "lrotable.h"
#include "lstring.h"
#include "ltable.h"
#include "lstate.h"
#include "lgc.h"
#include "lua/api_filesystem.h"
#include "lua/api_colorlcd.h"
extern LROT_TABLE(iolib);
extern LROT_TABLE(strlib);
extern LROT_TABLE(mathlib);
extern LROT_TABLE(bitlib);
extern LROT_TABLE(etxlib);
extern LROT_TABLE(etxcst);
extern LROT_TABLE(etxstr);
extern LROT_TABLE(etxdir);
extern LROT_TABLE(lcdlib);
extern LROT_TABLE(modellib);
extern LROT_TABLE(bitmaplib);
/*
** these libs are loaded by lua.c and are readily available to any Lua
** program
*/
static const luaL_Reg loadedlibs[] = {
// {"_G", luaopen_base},
#if defined(COLORLCD)
{LUA_LOADLIBNAME, luaopen_package},
extern LROT_TABLE(tablib);
#endif
// {LUA_COLIBNAME, luaopen_coroutine},
// {LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
// {LUA_OSLIBNAME, luaopen_os},
// {LUA_STRLIBNAME, luaopen_string},
// {LUA_BITLIBNAME, luaopen_bit32},
// {LUA_MATHLIBNAME, luaopen_math},
// {LUA_DBLIBNAME, luaopen_debug},
{NULL, NULL}
/* _G __index -> rotables __index -> _index_hook_fct */
extern LROT_TABLE(rotables_meta);
extern LROT_TABLE(base_func);
static const ROTable* _global_symbols[] = {
LROT_TABLEREF(base_func),
LROT_TABLEREF(etxlib),
LROT_TABLEREF(etxdir),
LROT_TABLEREF(etxcst),
LROT_TABLEREF(etxstr),
NULL,
};
/* The read-only tables are defined here */
const luaR_table lua_rotable[] =
static int _index_hook_fct(lua_State * L)
{
{"__opentx", opentxLib, opentxConstants, edgetxStrings},
{"lcd", lcdLib, NULL, NULL},
{"model", modelLib, NULL, NULL},
{"__baselib", baselib, NULL, NULL},
{LUA_IOLIBNAME, iolib, NULL, NULL},
{LUA_STRLIBNAME, strlib, NULL, NULL},
{LUA_MATHLIBNAME, mathlib, mathlib_vals, NULL},
{LUA_BITLIBNAME, bitlib, NULL, NULL},
#if defined(COLORLCD)
{LUA_TABLIBNAME, tab_funcs, NULL, NULL},
#endif
{NULL, NULL, NULL, NULL}
};
const ROTable** t = _global_symbols;
const TValue* res = luaO_nilobject;
TString* key;
/*
** these libs are preloaded and must be required before used
*/
static const luaL_Reg preloadedlibs[] = {
{NULL, NULL}
};
lua_lock(L);
key = rawtsvalue(L->top - 1);
for(; *t; t++) {
res = luaH_getstr((Table*)*t, key);
if (!ttisnil(res)) break;
}
if (ttislightuserdata(res)) {
/* strings are encoded as light user data */
setsvalue2s(L, L->top - 1, luaS_new(L, pvalue(res)));
} else {
setobj2s(L, L->top - 1, res);
}
lua_unlock(L);
return 1;
}
/* rotables is inserted in luaopen_base */
LROT_BEGIN(rotables_meta, NULL, LROT_MASK_INDEX)
LROT_FUNCENTRY( __index, _index_hook_fct )
LROT_END(rotables_meta, NULL, LROT_MASK_INDEX)
LROT_BEGIN(rotables, LROT_TABLEREF(rotables_meta), 0)
LROT_TABENTRY( _G, base_func)
LROT_TABENTRY( io, iolib )
LROT_TABENTRY( string, strlib )
LROT_TABENTRY( math, mathlib )
LROT_TABENTRY( bit32, bitlib )
LROT_TABENTRY( lcd, lcdlib )
LROT_TABENTRY( model, modellib )
LROT_TABENTRY( bitmap, bitmaplib )
LROT_TABENTRY( Bitmap, bitmaplib ) /* TODO: obsolete after 2.9 */
#if defined(COLORLCD)
LROT_TABENTRY( table, tablib )
#endif
LROT_TABENTRY( ROM, rotables )
LROT_END(rotables, LROT_TABLEREF(rotables_meta), 0)
LROT_BEGIN(lua_libs, NULL, 0)
LROT_FUNCENTRY( _G, luaopen_base )
LROT_FUNCENTRY( io, luaopen_io )
LROT_FUNCENTRY( dir, luaopen_etxdir )
LROT_FUNCENTRY( bitmap_mt, luaopen_bitmap )
#if defined(LUA_ENABLE_LOADLIB)
LROT_FUNCENTRY( package, luaopen_package )
#endif
#if defined(LUA_ENABLE_STRLIB_MT)
LROT_FUNCENTRY( string, luaopen_string )
#endif
LROT_END(lua_libs, NULL, 0)
LUALIB_API void luaL_openlibs (lua_State *L) {
const luaL_Reg *lib;
/* call open functions from 'loadedlibs' and set results to global table */
for (lib = loadedlibs; lib->func; lib++) {
luaL_requiref(L, lib->name, lib->func, 1);
lua_pop(L, 1); /* remove lib */
const ROTable_entry *p = LROT_TABLEREF(lua_libs)->entry;
/* Now do lua opens */
for ( ; p->key; p++) {
if (ttislcf(&p->value) && fvalue(&p->value))
luaL_requiref(L, p->key, fvalue(&p->value), 1);
}
/* add open functions from 'preloadedlibs' into 'package.preload' table */
luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
for (lib = preloadedlibs; lib->func; lib++) {
lua_pushcfunction(L, lib->func);
lua_setfield(L, -2, lib->name);
}
lua_pop(L, 1); /* remove _PRELOAD table */
}
+15 -76
View File
@@ -4,7 +4,6 @@
** See Copyright Notice in lua.h
*/
/*
** POSIX idiosyncrasy!
** This definition must come before the inclusion of 'stdio.h'; it
@@ -14,15 +13,14 @@
#define _FILE_OFFSET_BITS 64
#endif
#define liolib_c
#define LUA_LIB
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define liolib_c
#include "lua.h"
#include "lauxlib.h"
@@ -649,84 +647,25 @@ static int io_seek (lua_State *L) {
/*
** functions for 'io' library
*/
const luaL_Reg iolib[] = {
{"close", io_close},
// {"flush", io_flush},
// {"input", io_input},
// {"lines", io_lines},
{"seek", io_seek},
{"open", io_open},
// {"output", io_output},
// {"popen", io_popen},
{"read", io_read},
// {"tmpfile", io_tmpfile},
// {"type", io_type},
{"write", io_write},
{NULL, NULL}
};
LROT_BEGIN(iolib, NULL, 0)
LROT_FUNCENTRY( close, io_close )
LROT_FUNCENTRY( seek, io_seek )
LROT_FUNCENTRY( open, io_open )
LROT_FUNCENTRY( read, io_read )
LROT_FUNCENTRY( write, io_write )
LROT_END(iolib, NULL, 0)
/*
** methods for file handles
**
** we define only garbage collector to close any leftover open files
*/
static const luaL_Reg flib[] = {
// {"close", io_close},
// {"flush", f_flush},
// {"lines", f_lines},
// {"read", io_read},
// {"seek", f_seek},
// {"setvbuf", f_setvbuf},
// {"write", f_write},
{"__gc", f_gc}, // we define only garbage collector to close any leftover open files
// {"__tostring", f_tostring},
{NULL, NULL}
};
LROT_BEGIN(file_handle, NULL, LROT_MASK_GC)
LROT_FUNCENTRY( __gc, f_gc )
LROT_END(file_handle, NULL, LROT_MASK_GC)
static void createmeta (lua_State *L) {
luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
lua_pushvalue(L, -1); /* push metatable */
lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */
lua_pop(L, 1); /* pop new metatable */
}
#if !defined(USE_FATFS)
/*
** function to (not) close the standard files stdin, stdout, and stderr
*/
static int io_noclose (lua_State *L) {
LStream *p = tolstream(L);
p->closef = &io_noclose; /* keep file opened */
lua_pushnil(L);
lua_pushliteral(L, "cannot close standard file");
return 2;
}
static void createstdfile (lua_State *L, FILE *f, const char *k,
const char *fname) {
LStream *p = newprefile(L);
p->f = f;
p->closef = &io_noclose;
if (k != NULL) {
lua_pushvalue(L, -1);
lua_setfield(L, LUA_REGISTRYINDEX, k); /* add file to registry */
}
lua_setfield(L, -2, fname); /* add file to module */
}
#endif
LUAMOD_API int luaopen_io (lua_State *L) {
// luaL_newlib(L, iolib); /* new module */
createmeta(L);
/* create (and set) default files */
// createstdfile(L, stdin, IO_INPUT, "stdin");
// createstdfile(L, stdout, IO_OUTPUT, "stdout");
// createstdfile(L, stderr, NULL, "stderr");
// return 1;
luaL_rometatable( L, LUA_FILEHANDLE, LROT_TABLEREF(file_handle));
return 0;
}
#if defined(USE_FATFS)
#undef FILE
#endif
+11
View File
@@ -145,6 +145,17 @@ typedef lu_int32 Instruction;
#endif
/*
** Size of cache for strings in the API. 'N' is the number of
** sets (better be a prime) and "M" is the size of each set (M == 1
** makes a direct cache.)
*/
#if !defined(KEYCACHE_N)
#define KEYCACHE_N 32
#define KEYCACHE_M 4
#endif
/* minimum size for string buffer */
#if !defined(LUA_MINBUFFER)
#define LUA_MINBUFFER 32
+37 -42
View File
@@ -4,19 +4,17 @@
** See Copyright Notice in lua.h
*/
#define lmathlib_c
#define LUA_LIB
#include <stdlib.h>
#include <math.h>
#define lmathlib_c
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "lrotable.h"
#undef PI
#define PI ((lua_Number)(3.1415926535897932384626433832795))
#define RADIANS_PER_DEGREE ((lua_Number)(PI/180.0))
@@ -229,45 +227,42 @@ static int math_randomseed (lua_State *L) {
return 0;
}
const luaL_Reg mathlib[] = {
{"abs", math_abs},
{"acos", math_acos},
{"asin", math_asin},
{"atan2", math_atan2},
{"atan", math_atan},
{"ceil", math_ceil},
{"cosh", math_cosh},
{"cos", math_cos},
{"deg", math_deg},
{"exp", math_exp},
{"floor", math_floor},
{"fmod", math_fmod},
{"frexp", math_frexp},
{"ldexp", math_ldexp},
#if defined(LUA_COMPAT_LOG10)
{"log10", math_log10},
#endif
{"log", math_log},
{"max", math_max},
{"min", math_min},
{"modf", math_modf},
{"pow", math_pow},
{"rad", math_rad},
{"random", math_random},
{"randomseed", math_randomseed},
{"sinh", math_sinh},
{"sin", math_sin},
{"sqrt", math_sqrt},
{"tanh", math_tanh},
{"tan", math_tan},
{NULL, NULL}
};
const luaR_value_entry mathlib_vals[] = {
{"pi", PI},
{"huge", HUGE_VAL},
{NULL, 0}
};
LROT_BEGIN(mathlib, NULL, 0)
LROT_FUNCENTRY( abs, math_abs)
LROT_FUNCENTRY( acos, math_acos)
LROT_FUNCENTRY( asin, math_asin)
LROT_FUNCENTRY( atan2, math_atan2)
LROT_FUNCENTRY( atan, math_atan)
LROT_FUNCENTRY( ceil, math_ceil)
LROT_FUNCENTRY( cosh, math_cosh)
LROT_FUNCENTRY( cos, math_cos)
LROT_FUNCENTRY( deg, math_deg)
LROT_FUNCENTRY( exp, math_exp)
LROT_FUNCENTRY( floor, math_floor)
LROT_FUNCENTRY( fmod, math_fmod)
LROT_FUNCENTRY( frexp, math_frexp)
LROT_FUNCENTRY( ldexp, math_ldexp)
#if defined(LUA_COMPAT_LOG10)
LROT_FUNCENTRY( log10, math_log10)
#endif
LROT_FUNCENTRY( log, math_log)
LROT_FUNCENTRY( max, math_max)
LROT_FUNCENTRY( min, math_min)
LROT_FUNCENTRY( modf, math_modf)
LROT_FUNCENTRY( pow, math_pow)
LROT_FUNCENTRY( rad, math_rad)
LROT_FUNCENTRY( random, math_random)
LROT_FUNCENTRY( randomseed, math_randomseed)
LROT_FUNCENTRY( sinh, math_sinh)
LROT_FUNCENTRY( sin, math_sin)
LROT_FUNCENTRY( sqrt, math_sqrt)
LROT_FUNCENTRY( tanh, math_tanh)
LROT_FUNCENTRY( tan, math_tan)
LROT_NUMENTRY( pi, PI)
LROT_NUMENTRY( huge,(lua_Number)HUGE_VAL)
LROT_END(mathlib, NULL, 0)
/*
** Open math library
+43 -19
View File
@@ -55,6 +55,9 @@
#define LUA_TSHRSTR (LUA_TSTRING | (0 << 4)) /* short strings */
#define LUA_TLNGSTR (LUA_TSTRING | (1 << 4)) /* long strings */
/* Variant tags for tables */
#define LUA_TTBLRAM (LUA_TTABLE | (0 << 4)) /* RAM based Table */
#define LUA_TTBLROF (LUA_TTABLE | (1 << 4)) /* RO Flash based ROTable */
/* Bit mark for collectable types */
#define BIT_ISCOLLECTABLE (1 << 6)
@@ -133,12 +136,12 @@ typedef union Value Value;
#define ttisnil(o) checktag((o), LUA_TNIL)
#define ttisboolean(o) checktag((o), LUA_TBOOLEAN)
#define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA)
#define ttisrotable(o) checktag((o), LUA_TROTABLE)
#define ttislightfunction(o) checktag((o), LUA_TLIGHTFUNCTION)
#define ttisstring(o) checktype((o), LUA_TSTRING)
#define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR))
#define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR))
#define ttistable(o) checktag((o), ctb(LUA_TTABLE))
#define ttistable(o) checktype((o), LUA_TTABLE)
#define ttisrwtable(o) checktag((o), ctb(LUA_TTBLRAM))
#define ttisrotable(o) checktag((o), ctb(LUA_TTBLROF))
#define ttisfunction(o) checktype(o, LUA_TFUNCTION)
#define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION)
#define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))
@@ -155,7 +158,6 @@ typedef union Value Value;
#define gcvalue(o) check_exp(iscollectable(o), val_(o).gc)
#define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p)
#define rvalue(o) check_exp(ttisrotable(o), val_(o).p)
#define lfvalue(o) check_exp(ttislightfunction(o), val_(o).p)
#define rawtsvalue(o) check_exp(ttisstring(o), &val_(o).gc->ts)
#define tsvalue(o) (&rawtsvalue(o)->tsv)
#define rawuvalue(o) check_exp(ttisuserdata(o), &val_(o).gc->u)
@@ -163,8 +165,10 @@ typedef union Value Value;
#define clvalue(o) check_exp(ttisclosure(o), &val_(o).gc->cl)
#define clLvalue(o) check_exp(ttisLclosure(o), &val_(o).gc->cl.l)
#define clCvalue(o) check_exp(ttisCclosure(o), &val_(o).gc->cl.c)
#define lcfvalue(o) check_exp(ttislcf(o), val_(o).f)
#define fvalue(o) check_exp(ttislcf(o), val_(o).f)
#define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h)
#define rwhvalue(o) check_exp(ttisrwtable(o), gco2rwt(&val_(o).gc))
#define rohvalue(o) check_exp(ttisrotable(o), gco2rot(val_(o).gc))
#define bvalue(o) check_exp(ttisboolean(o), val_(o).b)
#define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th)
/* a dead value may get the 'gc' field, but cannot access its contents */
@@ -192,18 +196,12 @@ typedef union Value Value;
#define setnilvalue(obj) settt_(obj, LUA_TNIL)
#define setlcfvalue(obj,x) \
#define setfvalue(obj,x) \
{ TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); }
#define setpvalue(obj,x) \
{ TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); }
#define setrvalue(obj,x) \
{ TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TROTABLE); }
#define setlfvalue(obj,x) \
{ TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTFUNCTION); }
#define setbvalue(obj,x) \
{ TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); }
@@ -238,8 +236,8 @@ typedef union Value Value;
checkliveness(G(L),io); }
#define sethvalue(L,obj,x) \
{ TValue *io=(obj); \
val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTABLE)); \
{ TValue *io=(obj); Table *x_ = (x); \
val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(x_->tt)); \
checkliveness(G(L),io); }
#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY)
@@ -547,6 +545,20 @@ typedef union Closure {
#define getproto(o) (clLvalue(o)->p)
/*
** Common Table fields for both table versions (like CommonHeader in
** macro form, to be included in table structure definitions).
**
** Note that the sethvalue() macro works much like the setsvalue()
** macro and handles the abstracted type. the hvalue(o) macro can be
** used to access CommonTable fields, but the rwhvalue(o) and
** rohvalue(o) value variants must be used if accessing variant-specfic
** fields
*/
#define CommonTable CommonHeader; \
lu_byte flags; lu_byte lsizenode; struct Table *metatable;
/*
** Tables
*/
@@ -567,17 +579,29 @@ typedef struct Node {
typedef struct Table {
CommonHeader;
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
lu_byte lsizenode; /* log2 of size of `node' array */
struct Table *metatable;
/* flags & 1<<p means tagmethod(p) is not present */
/* lsizenode = log2 of size of `node' array */
CommonTable;
int sizearray; /* size of `array' array */
TValue *array; /* array part */
Node *node;
Node *lastfree; /* any free position is before this position */
GCObject *gclist;
int sizearray; /* size of `array' array */
} Table;
typedef struct ROTable_entry {
const char *key;
const TValue value;
} ROTable_entry;
typedef struct ROTable {
/* next always has the value (GCObject *)((size_t) 1); */
/* flags & 1<<p means tagmethod(p) is not present */
/* lsizenode is the number of ROTable entries */
/* Like TStrings, the ROTable_entry vector follows the ROTable */
CommonTable;
const ROTable_entry *entry;
} ROTable;
/*
+52
View File
@@ -0,0 +1,52 @@
#ifndef lro_defs_h
#define lro_defs_h
#include "lua.h"
#include "lobject.h"
#include "llimits.h"
#include "ltm.h"
/* Macros used to declare rotable entries */
#define LRO_STRKEY(k) k
#define LRO_FUNCVAL(v) {{.f = v}, LUA_TLCF}
#define LRO_LUDATA(v) {{.p = (void *) v}, LUA_TLIGHTUSERDATA}
#define LRO_NILVAL {{.p = NULL}, LUA_TNIL}
#define LRO_NUMVAL(v) {{.n = v}, LUA_TNUMBER}
#define LRO_ROVAL(v) {{.gc = cast(GCObject *, &(v ## _ROTable))}, LUA_TTBLROF}
#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_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) extern LROT_TABLE(rt); \
static const ROTable_entry rt ## _entries[] = {
#define LROT_END(rt,mt,f) {NULL, LRO_NILVAL} }; \
const ROTable rt ## _ROTable = { \
(GCObject *)1, LUA_TTBLROF, LROT_MARKED, \
cast(lu_byte, ~(f)), (sizeof(rt ## _entries)/sizeof(ROTable_entry)) - 1, \
cast(Table *, mt), cast(const ROTable_entry *, rt ## _entries) };
#define LROT_BREAK(rt) };
#define LROT_MASK(m) cast(lu_byte, 1<<TM_ ## m)
/*
* These are statically coded can be any combination of the fast index tags
* listed in ltm.h: EQ, GC, INDEX, LEN, MODE, NEWINDEX or combined by anding
* GC+INDEX is the only common combination used, hence the combinaton macro
*/
#define LROT_MASK_EQ LROT_MASK(EQ)
#define LROT_MASK_GC LROT_MASK(GC)
#define LROT_MASK_INDEX LROT_MASK(INDEX)
#define LROT_MASK_LEN LROT_MASK(LEN)
#define LROT_MASK_MODE LROT_MASK(MODE)
#define LROT_MASK_NEWINDEX LROT_MASK(NEWINDEX)
#define LROT_MASK_GC_INDEX (LROT_MASK_GC | LROT_MASK_INDEX)
#endif
-106
View File
@@ -1,106 +0,0 @@
/* Read-only tables for Lua */
#include <string.h>
#include "lua.h"
#include "lauxlib.h"
#include "lstring.h"
#include "lrotable.h"
/* Utility function: find a key in a given table of functions */
static luaR_result luaR_findfunctionkey(const luaL_Reg* pf, const char * key, TValue * found) {
if(!pf)
return 0;
while(1) {
if (!pf->name)
break;
if (!strcmp(pf->name, key)) {
setlfvalue(found, pf->func);
return 1;
}
pf++;
}
return 0;
}
/* Utility function: find a key in a given table of constants */
static luaR_result luaR_findconstantkey(const luaR_value_entry* pv, const char * key, TValue * found) {
if(!pv)
return 0;
while(1) {
if (!pv->name)
break;
if (!strcmp(pv->name, key)) {
setnvalue(found, pv->value);
return 1;
}
pv++;
}
return 0;
}
/* Utility function: find a key in a given table of strings */
static luaR_result luaR_findstringkey(lua_State *L, const luaR_string_entry* ps, const char * key, TValue * found) {
if(!ps)
return 0;
while(1) {
if (!ps->name)
break;
if (!strcmp(ps->name, key)) {
TString *ts = luaS_new(L, ps->string);
setsvalue(L, found, ts);
return 1;
}
ps++;
}
return 0;
}
/* Find a global "read only table" in the constant lua_rotable array */
luaR_result luaR_findglobal(lua_State *L, const char * name, TValue * val) {
unsigned i;
if (strlen(name) > LUA_MAX_ROTABLE_NAME) {
TRACE_LUA_INTERNALS("luaR_findglobal('%s') = NAME TOO LONG", name);
return 0;
}
for (i=0; lua_rotable[i].name; i++) {
void * table = (void *)(&lua_rotable[i]);
if (!strcmp(lua_rotable[i].name, name)) {
setrvalue(val, table);
TRACE_LUA_INTERNALS("luaR_findglobal('%s') = TABLE %p (%s)", name, table, lua_rotable[i].name);
return 1;
}
if (!strncmp(lua_rotable[i].name, "__", 2)) {
if (luaR_findentry(L, table, name, val)) {
TRACE_LUA_INTERNALS("luaR_findglobal('%s') = FOUND in table '%s'", name, lua_rotable[i].name);
return 1;
}
}
}
TRACE_LUA_INTERNALS("luaR_findglobal() '%s' = NOT FOUND", name);
return 0;
}
luaR_result luaR_findentry(lua_State *L, void *data, const char * key, TValue * val) {
luaR_table * table = (luaR_table *)data;
/* First look at the functions */
if (luaR_findfunctionkey(table->pfuncs, key, val)) {
TRACE_LUA_INTERNALS("luaR_findentry(%p[%s], '%s') = FUNCTION %p", table, table->name, key, lfvalue(val));
return 1;
}
else if (luaR_findconstantkey(table->pvalues, key, val)) {
/* Then at the values */
TRACE_LUA_INTERNALS("luaR_findentry(%p[%s], '%s') = NUMBER %g", table, table->name, key, nvalue(val));
return 1;
}
else if (luaR_findstringkey(L, table->pstrings, key, val)) {
/* Then at the strings */
TRACE_LUA_INTERNALS("luaR_findentry(%p[%s], '%s') = STRING %s", table, table->name, key, svalue(val));
return 1;
}
TRACE_LUA_INTERNALS("luaR_findentry(%p[%s], '%s') = NOT FOUND", table, table->name, key);
return 0;
}
-46
View File
@@ -1,46 +0,0 @@
// Read-only tables for Lua
#ifndef lrotable_h
#define lrotable_h
#include "lua.h"
#include "llimits.h"
#include "lauxlib.h"
#include "lobject.h"
typedef uint8_t luaR_result;
// A number entry in the read only table
typedef struct
{
const char *name;
lua_Number value;
} luaR_value_entry;
// A string entry in the read only table
typedef struct
{
const char *name;
const char *string;
} luaR_string_entry;
extern const luaR_value_entry baselib_vals[];
extern const luaR_value_entry mathlib_vals[];
extern const luaR_value_entry opentxConstants[];
extern const luaR_string_entry edgetxStrings[];
// A mapping between table name and its entries
typedef struct
{
const char *name;
const luaL_Reg *pfuncs;
const luaR_value_entry *pvalues;
const luaR_string_entry *pstrings;
} luaR_table;
extern const luaR_table lua_rotable[];
luaR_result luaR_findglobal(lua_State *L, const char * name, TValue * val);
luaR_result luaR_findentry(lua_State *L, void * data, const char * key, TValue * val);
#endif
+21
View File
@@ -218,6 +218,8 @@ static void preinit_state (lua_State *L, global_State *g) {
}
static lua_State *L0 = NULL;
static void close_state (lua_State *L) {
global_State *g = G(L);
luaF_close(L, L->stack); /* close all upvalues for this thread */
@@ -225,6 +227,10 @@ static void close_state (lua_State *L) {
luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size);
luaZ_freebuffer(L, &g->buff);
freestack(L);
if (L == L0) {
(*g->frealloc)(g->ud, g->cache, KEYCACHE_N * sizeof(KeyCacheLine), 0);
L0 = NULL; /* so reopening state initialises properly */
}
lua_assert(gettotalbytes(g) == sizeof(LG));
(*g->frealloc)(g->ud, fromstate(L), sizeof(LG), 0); /* free main block */
}
@@ -258,6 +264,9 @@ void luaE_freethread (lua_State *L, lua_State *L1) {
luaM_free(L, l);
}
LUAI_FUNC KeyCache *luaE_getcache (int lineno) {
return &G(L0)->cache[lineno][0];
}
LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
int i;
@@ -300,6 +309,18 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
g->gcpause = LUAI_GCPAUSE;
g->gcmajorinc = LUAI_GCMAJOR;
g->gcstepmul = LUAI_GCMUL;
#ifdef LUA_ENABLE_TEST
if (L0) { /* This is a second state */
g->cache=G(L0)->cache;
} else {
#endif
L0 = L;
g->cache = cast(KeyCacheLine *,
(*f)(ud, NULL, 0, KEYCACHE_N * sizeof(KeyCacheLine)));
memset(g->cache, 0, KEYCACHE_N * sizeof(KeyCacheLine));
#ifdef LUA_ENABLE_TEST
}
#endif
for (i=0; i < LUA_NUMTAGS; i++) g->mt[i] = NULL;
if (luaD_rawrunprotected(L, f_luaopen, NULL) != LUA_OK) {
/* memory allocation error: free partial state */
+13 -2
View File
@@ -105,10 +105,16 @@ typedef struct CallInfo {
#define isLua(ci) ((ci)->callstatus & CIST_LUA)
/*
** KeyCache used for resolution of ROTable entries and Cstrings
*/
typedef lu_int32 KeyCache;
typedef KeyCache KeyCacheLine[KEYCACHE_M];
/*
** `global state', shared by all threads of this state
*/
typedef struct global_State {
lua_Alloc frealloc; /* function to reallocate memory */
void *ud; /* auxiliary data to `frealloc' */
@@ -145,6 +151,7 @@ typedef struct global_State {
TString *memerrmsg; /* memory-error message */
TString *tmname[TM_N]; /* array with tag-method names */
struct Table *mt[LUA_NUMTAGS]; /* metatables for basic types */
KeyCacheLine *cache; /* cache for strings in API */
} global_State;
@@ -188,6 +195,7 @@ union GCObject {
union Udata u;
union Closure cl;
struct Table h;
struct ROTable roh;
struct Proto p;
struct UpVal uv;
struct lua_State th; /* thread */
@@ -206,7 +214,10 @@ union GCObject {
#define gco2ccl(o) check_exp((o)->gch.tt == LUA_TCCL, &((o)->cl.c))
#define gco2cl(o) \
check_exp(novariant((o)->gch.tt) == LUA_TFUNCTION, &((o)->cl))
#define gco2t(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
#define gco2t(o) \
check_exp(novariant((o)->gch.tt) == LUA_TTABLE, &((o)->h))
#define gco2rwt(o) check_exp((o)->gch.tt == LUA_TTBLRAM, &((o)->h))
#define gco2rot(o) check_exp((o)->gch.tt == LUA_TTBLROF, &((o)->roh))
#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
@@ -222,7 +233,7 @@ LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
LUAI_FUNC void luaE_freeCI (lua_State *L);
LUAI_FUNC KeyCache *luaE_getcache (int cl);
#endif
+24 -36
View File
@@ -4,6 +4,8 @@
** See Copyright Notice in lua.h
*/
#define lstrlib_c
#define LUA_LIB
#include <ctype.h>
#include <stddef.h>
@@ -11,8 +13,6 @@
#include <string.h>
#include <stdio.h>
#define lstrlib_c
#include "lua.h"
#include "lauxlib.h"
@@ -975,44 +975,32 @@ static int str_format (lua_State *L) {
/* }====================================================== */
const luaL_Reg strlib[] = {
{"byte", str_byte},
{"char", str_char},
{"dump", str_dump},
{"find", str_find},
{"format", str_format},
{"gmatch", gmatch},
{"gsub", str_gsub},
{"len", str_len},
{"lower", str_lower},
{"match", str_match},
{"rep", str_rep},
{"reverse", str_reverse},
{"sub", str_sub},
{"upper", str_upper},
{NULL, NULL}
};
#if 0
static void createmetatable (lua_State *L) {
lua_createtable(L, 0, 1); /* table to be metatable for strings */
lua_pushliteral(L, ""); /* dummy string */
lua_pushvalue(L, -2); /* copy table */
lua_setmetatable(L, -2); /* set table as metatable for strings */
lua_pop(L, 1); /* pop dummy string */
lua_pushvalue(L, -2); /* get string library */
lua_setfield(L, -2, "__index"); /* metatable.__index = string */
lua_pop(L, 1); /* pop metatable */
}
LROT_BEGIN(strlib, NULL, LROT_MASK_INDEX)
LROT_TABENTRY( __index, strlib )
LROT_FUNCENTRY( byte, str_byte )
LROT_FUNCENTRY( char, str_char )
LROT_FUNCENTRY( dump, str_dump )
LROT_FUNCENTRY( find, str_find )
LROT_FUNCENTRY( format, str_format )
LROT_FUNCENTRY( gmatch, gmatch )
LROT_FUNCENTRY( gsub, str_gsub )
LROT_FUNCENTRY( len, str_len )
LROT_FUNCENTRY( lower, str_lower )
LROT_FUNCENTRY( match, str_match )
LROT_FUNCENTRY( rep, str_rep )
LROT_FUNCENTRY( reverse, str_reverse )
LROT_FUNCENTRY( sub, str_sub )
LROT_FUNCENTRY( upper, str_upper )
LROT_END(strlib, NULL, LROT_MASK_INDEX)
/*
** Open string library
*/
LUAMOD_API int luaopen_string (lua_State *L) {
luaL_newlib(L, strlib);
createmetatable(L);
return 1;
lua_pushliteral(L, ""); /* dummy string */
lua_pushrotable(L, LROT_TABLEREF(strlib));
lua_setmetatable(L, -2); /* set table as metatable for strings */
lua_pop(L, 1); /* pop dummy string */
return 0;
}
#endif
+158 -13
View File
@@ -113,7 +113,7 @@ static Node *mainposition (const Table *t, const TValue *key) {
case LUA_TLIGHTUSERDATA:
return hashpointer(t, pvalue(key));
case LUA_TLCF:
return hashpointer(t, lcfvalue(key));
return hashpointer(t, fvalue(key));
default:
return hashpointer(t, gcvalue(key));
}
@@ -165,9 +165,15 @@ static int findindex (lua_State *L, Table *t, StkId key) {
}
}
static void rotable_next(lua_State *L, ROTable *t, TValue *key, TValue *val);
int luaH_next (lua_State *L, Table *t, StkId key) {
int i = findindex(L, t, key); /* find original element */
int i;
if (isrotable(t)) {
rotable_next(L, (ROTable *) t, key, key+1);
return ttisnil(key) ? 0 : 1;
}
i = findindex(L, t, key); /* find original element */
for (i++; i < t->sizearray; i++) { /* try first array part */
if (!ttisnil(&t->array[i])) { /* a non-nil value? */
setnvalue(key, cast_num(i+1));
@@ -209,10 +215,7 @@ static int computesizes (int nums[], int *narray) {
}
if (a == *narray) break; /* all elements already counted */
}
if (n - *narray > 1024)
*narray += 1024;
else
*narray = n;
*narray = n;
lua_assert(*narray/2 <= na && na <= *narray);
return na;
}
@@ -306,7 +309,6 @@ void luaH_resize (lua_State *L, Table *t, int nasize, int nhsize) {
int i;
int oldasize = t->sizearray;
int oldhsize = t->lsizenode;
TRACE_LUA_INTERNALS_WITH_LINEINFO(L, "luaH_resize table %p %d(%d) %d(%d)", t, nasize, oldasize, nhsize, twoto(oldhsize));
Node *nold = t->node; /* save old hash ... */
if (nasize > oldasize) /* array part must grow? */
setarrayvector(L, t, nasize);
@@ -406,6 +408,7 @@ static Node *getfreepos (Table *t) {
*/
TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
Node *mp;
if(!isrwtable(t)) luaG_runerror(L, "table is Readonly");
if (ttisnil(key)) luaG_runerror(L, "table index is nil");
else if (ttisnumber(key) && luai_numisnan(L, nvalue(key)))
luaG_runerror(L, "table index is NaN");
@@ -446,6 +449,8 @@ TValue *luaH_newkey (lua_State *L, Table *t, const TValue *key) {
** search function for integers
*/
const TValue *luaH_getint (Table *t, int key) {
if (isrotable(t))
return luaO_nilobject;
/* (1 <= key && key <= t->sizearray) */
if (cast(unsigned int, key-1) < cast(unsigned int, t->sizearray))
return &t->array[key-1];
@@ -465,8 +470,14 @@ const TValue *luaH_getint (Table *t, int key) {
/*
** search function for short strings
*/
static const TValue* rotable_findentry(ROTable *rotable, TString *key, unsigned *ppos);
const TValue *luaH_getstr (Table *t, TString *key) {
Node *n = hashstr(t, key);
Node *n;
if (isrotable(t))
return rotable_findentry((ROTable*) t, key, NULL);
n = hashstr(t, key);
lua_assert(key->tsv.tt == LUA_TSHRSTR);
do { /* check whether `key' is somewhere in the chain */
if (ttisshrstring(gkey(n)) && eqshrstr(rawtsvalue(gkey(n)), key))
@@ -493,7 +504,9 @@ const TValue *luaH_get (Table *t, const TValue *key) {
/* else go through */
}
default: {
Node *n = mainposition(t, key);
Node *n;
if (isrotable(t)) return luaO_nilobject;
n = mainposition(t, key);
do { /* check whether `key' is somewhere in the chain */
if (luaV_rawequalobj(gkey(n), key))
return gval(n); /* that's it */
@@ -510,7 +523,10 @@ const TValue *luaH_get (Table *t, const TValue *key) {
** barrier and invalidate the TM cache.
*/
TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
const TValue *p = luaH_get(t, key);
const TValue *p;
if (isrotable(t))
luaG_runerror(L, "table is readonly");
p = luaH_get(t, key);
if (p != luaO_nilobject)
return cast(TValue *, p);
else return luaH_newkey(L, t, key);
@@ -518,7 +534,10 @@ TValue *luaH_set (lua_State *L, Table *t, const TValue *key) {
void luaH_setint (lua_State *L, Table *t, int key, TValue *value) {
const TValue *p = luaH_getint(t, key);
const TValue *p;
if (isrotable(t))
luaG_runerror(L, "table is readonly");
p = luaH_getint(t, key);
TValue *cell;
if (p != luaO_nilobject)
cell = cast(TValue *, p);
@@ -577,6 +596,134 @@ int luaH_getn (Table *t) {
else return unbound_search(t, j);
}
int luaH_isdummy (const Node *n) { return isdummy(n); }
/*
** All keyed ROTable access passes through rotable_findentry(). ROTables
** are simply a list of <key><TValue value> pairs.
**
** The global KeyCache is used to avoid a relatively expensive Flash memory
** vector scan. A simple hash on the key's TString addr and the ROTable
** addr selects the cache line. The line's slots are then scanned for a
** hit.
**
** Unlike the standard hash which uses a prime line count therefore requires
** the use of modulus operation which is expensive on an IoT processor
** without H/W divide. This hash is power of 2 based which might not be quite
** so uniform but can be calculated without using H/W-based instructions.
**
** If a match is found and the table addresses match, then this entry is
** probed first. In practice the hit-rate here is over 99% so the code
** rarely fails back to doing the linear scan in ROM.
** Note that this hash does a couple of prime multiples and a modulus 2^X
** with is all evaluated in H/W, and adequately randomizes the lookup.
*/
#define HASH(a,b) ((((29*(size_t)(a)) ^ (37*((b)->tsv.hash)))>>4)&(KEYCACHE_N-1))
#define NDX_SHFT 24
#define ADDR_MASK (((size_t) 1<<24)-1)
/*
* Find a string key entry in a rotable and return it.
*/
static const TValue* rotable_findentry(ROTable *t, TString *key, unsigned *ppos) {
const ROTable_entry *e = cast(const ROTable_entry *, t->entry);
const int tl = t->lsizenode;
const char *strkey = getstr(key);
const int hash = HASH(t, key);
KeyCache *cl = luaE_getcache(hash);
int i, j = 1, l;
if (!e || key->tsv.tt != LUA_TSHRSTR)
return luaO_nilobject;
l = key->tsv.len;
/* scan the ROTable key cache and return if hit found */
for (i = 0; i < KEYCACHE_M; i++) {
lu_int32 cl_ndx = cl[i] >> NDX_SHFT;
if ((((size_t)t - cl[i]) & ADDR_MASK) == 0 && cl_ndx < tl &&
strcmp(e[cl_ndx].key, strkey) == 0) {
if (ppos)
*ppos = cl_ndx;
return &e[cl_ndx].value;
}
}
/*
* In practice most table scans are from a table miss due to the key cache
* short-circuiting almost all table hits. ROTable keys can be unsorted
* because of legacy compatibility, so the search must use a sequential
* equality match.
*
* The masked name4 comparison is a safe 4-byte comparison for all supported
* NodeMCU hosts and targets; It generate fast efficient access that avoids
* unaligned exceptions and costly strcmp() except for a last hit validation.
* However, this is ENDIAN SENSITIVE which is validate during initialisation.
*
* The majority of search misses are for metavalues (keys starting with __),
* so all metavalues if any must be at the front of each entry list.
*/
lu_int32 name4 = *(lu_int32 *)strkey;
lu_int32 mask4 = l > 2 ? (~0u) : (~0u)>>((3-l)*8);
lua_assert(*(int*)"abcd" == 0x64636261);
#define eq4(s) (((*(lu_int32 *)s ^ name4) & mask4) == 0)
#define ismeta(s) ((*(lu_int32 *)s & 0xffff) == *(lu_int32 *)"__\0")
if (ismeta(&name4)) {
for(i = 0; i < tl && ismeta(e[i].key); i++) {
if (eq4(e[i].key) && !strcmp(e[i].key, strkey)) {
j = 0; break;
}
}
} else {
for(i = 0; i < tl; i++) {
if (eq4(e[i].key) && !strcmp(e[i].key, strkey)) {
j = 0; break;
}
}
}
if (j)
return luaO_nilobject;
if (ppos)
*ppos = i;
/* In the case of a hit, update the lookaside cache */
for (j = KEYCACHE_M-1; j>0; j--)
cl[j] = cl[j-1];
cl[0] = ((size_t)t & ADDR_MASK) + ((lu_int32)i << NDX_SHFT);
return &e[i].value;
}
static void rotable_next_helper(lua_State *L, ROTable *t, int pos,
TValue *key, TValue *val) {
const ROTable_entry *e = cast(const ROTable_entry *, t->entry);
if (pos < t->lsizenode) {
/* Found an entry */
setsvalue(L, key, luaS_new(L, e[pos].key));
setobj2s(L, val, &e[pos].value);
} else {
setnilvalue(key);
setnilvalue(val);
}
}
/* next (used for iteration) */
static void rotable_next(lua_State *L, ROTable *t, TValue *key, TValue *val) {
unsigned keypos = t->lsizenode;
/* Special case: if key is nil, return the first element of the rotable */
if (ttisnil(key))
rotable_next_helper(L, t, 0, key, val);
else if (ttisstring(key)) {
/* Find the previous key again */
if (ttisstring(key)) {
rotable_findentry(t, rawtsvalue(key), &keypos);
}
/* Advance to next key */
rotable_next_helper(L, t, ++keypos, key, val);
}
}
#if defined(LUA_DEBUG)
@@ -585,6 +732,4 @@ Node *luaH_mainposition (const Table *t, const TValue *key) {
return mainposition(t, key);
}
int luaH_isdummy (Node *n) { return isdummy(n); }
#endif
+5
View File
@@ -18,6 +18,11 @@
#define invalidateTMcache(t) ((t)->flags = 0)
/* test Table to determine if it is a RW or RO table */
#define isrotable(t) ((t)->tt==LUA_TTBLROF)
#define isrwtable(t) ((t)->tt==LUA_TTBLRAM)
LUAI_FUNC const TValue *luaH_getint (Table *t, int key);
LUAI_FUNC void luaH_setint (lua_State *L, Table *t, int key, TValue *value);
LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key);
+12 -19
View File
@@ -4,11 +4,11 @@
** See Copyright Notice in lua.h
*/
#define ltablib_c
#define LUA_LIB
#include <stddef.h>
#define ltablib_c
#include "lua.h"
#include "lauxlib.h"
@@ -256,27 +256,20 @@ static int sort (lua_State *L) {
/* }====================================================== */
const luaL_Reg tab_funcs[] = {
{"concat", tconcat},
LROT_BEGIN(tablib, NULL, 0)
LROT_FUNCENTRY( concat, tconcat)
#if defined(LUA_COMPAT_MAXN)
{"maxn", maxn},
LROT_FUNCENTRY( maxn, maxn)
#endif
{"insert", tinsert},
{"pack", pack},
{"unpack", unpack},
{"remove", tremove},
{"sort", sort},
{NULL, NULL}
};
LROT_FUNCENTRY( insert, tinsert)
LROT_FUNCENTRY( pack, pack)
LROT_FUNCENTRY( unpack, unpack)
LROT_FUNCENTRY( remove, tremove)
LROT_FUNCENTRY( sort, sort)
LROT_END(tablib, NULL, 0)
LUAMOD_API int luaopen_table (lua_State *L) {
luaL_newlib(L, tab_funcs);
#if defined(LUA_COMPAT_UNPACK)
/* _G.unpack = table.unpack */
lua_getfield(L, -1, "unpack");
lua_setglobal(L, "unpack");
#endif
return 1;
return 0;
}
+3 -1
View File
@@ -23,7 +23,9 @@ static const char udatatypename[] = "userdata";
LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {
"no value",
"nil", "boolean", "rotable", "lightfunction", udatatypename, "number",
"nil", "boolean",
"_obsolete_", "_obsolete_", /* removed LUA_TROTABLE and LUA_TLIGHTFUNCTION */
udatatypename, "number",
"string", "table", "function", udatatypename, "thread",
"proto", "upval" /* these last two cases are used for tests only */
};
+9 -4
View File
@@ -77,8 +77,6 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize);
#define LUA_TNIL 0
#define LUA_TBOOLEAN 1
#define LUA_TROTABLE 2
#define LUA_TLIGHTFUNCTION 3
#define LUA_TLIGHTUSERDATA 4
#define LUA_TNUMBER 5
#define LUA_TSTRING 6
@@ -216,8 +214,6 @@ LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...);
LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n);
LUA_API void (lua_pushboolean) (lua_State *L, int b);
LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p);
LUA_API void (lua_pushlightfunction) (lua_State *L, void *p);
LUA_API void (lua_pushrotable) (lua_State *L, void *p);
LUA_API int (lua_pushthread) (lua_State *L);
@@ -431,6 +427,15 @@ struct lua_Debug {
/* }====================================================================== */
/* ROTable extensions to the standard API */
typedef struct ROTable ROTable;
typedef struct ROTable_entry ROTable_entry;
LUA_API void (lua_pushrotable) (lua_State *L, const ROTable *p);
LUA_API void (lua_createrotable) (lua_State *L, ROTable *t, const ROTable_entry *e, ROTable *mt);
/* }====================================================================== */
/******************************************************************************
* Copyright (C) 1994-2013 Lua.org, PUC-Rio.
+2 -3
View File
@@ -15,7 +15,8 @@
#define USE_FATFS
#endif
#define LUA_ANSI // force ANSI mode: lua_number2integer() behaves the same way on all platforms (#3826)
// force ANSI mode: lua_number2integer() behaves the same way on all platforms (#3826)
#define LUA_ANSI
/*
** ==================================================================
@@ -560,6 +561,4 @@
** without modifying the main part of the file.
*/
#define LUA_MAX_ROTABLE_NAME 32
#endif
+5 -5
View File
@@ -69,7 +69,7 @@ static lua_Number LoadNumber(LoadState* S)
return x;
}
static TString* Load_String(LoadState* S)
static TString* LoadString(LoadState* S)
{
size_t size;
LoadVar(S,size);
@@ -116,7 +116,7 @@ static void LoadConstants(LoadState* S, Proto* f)
setnvalue(o,LoadNumber(S));
break;
case LUA_TSTRING:
setsvalue2n(S->L,o,Load_String(S));
setsvalue2n(S->L,o,LoadString(S));
break;
default: lua_assert(0);
}
@@ -149,7 +149,7 @@ static void LoadUpvalues(LoadState* S, Proto* f)
static void LoadDebug(LoadState* S, Proto* f)
{
int i,n;
f->source=Load_String(S);
f->source=LoadString(S);
n=LoadInt(S);
f->lineinfo=luaM_newvector(S->L,n,int);
f->sizelineinfo=n;
@@ -160,12 +160,12 @@ static void LoadDebug(LoadState* S, Proto* f)
for (i=0; i<n; i++) f->locvars[i].varname=NULL;
for (i=0; i<n; i++)
{
f->locvars[i].varname=Load_String(S);
f->locvars[i].varname=LoadString(S);
f->locvars[i].startpc=LoadInt(S);
f->locvars[i].endpc=LoadInt(S);
}
n=LoadInt(S);
for (i=0; i<n; i++) f->upvalues[i].name=Load_String(S);
for (i=0; i<n; i++) f->upvalues[i].name=LoadString(S);
}
static void LoadFunction(LoadState* S, Proto* f)
+20 -53
View File
@@ -25,7 +25,7 @@
#include "ltable.h"
#include "ltm.h"
#include "lvm.h"
#include "lrotable.h"
/* limit for table tag-method chains (to avoid loops) */
@@ -106,27 +106,9 @@ static void callTM (lua_State *L, const TValue *f, const TValue *p1,
}
}
static void lua_getcstr(char *dest, const TString *src, size_t maxsize) {
if (src->tsv.len+1 > maxsize)
dest[0] = '\0';
else {
memcpy(dest, getstr(src), src->tsv.len);
dest[src->tsv.len] = '\0';
}
}
void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
int loop;
if (ttisrotable(t)) {
setnilvalue(val);
if (ttisstring(key)) {
char keyname[LUA_MAX_ROTABLE_NAME + 1];
lua_getcstr(keyname, rawtsvalue(key), LUA_MAX_ROTABLE_NAME);
TRACE_LUA_INTERNALS("luaV_gettable(%s)", keyname);
luaR_findentry(L, rvalue(t), keyname, val);
}
return;
}
for (loop = 0; loop < MAXTAGLOOP; loop++) {
const TValue *tm;
if (ttistable(t)) { /* `t' is a table? */
@@ -139,10 +121,9 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
}
/* else will try the tag method */
}
else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) {
else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
luaG_typeerror(L, t, "index");
}
if (ttisfunction(tm) || ttislightfunction(tm)) {
if (ttisfunction(tm)) {
callTM(L, tm, t, key, val, 1);
return;
}
@@ -225,24 +206,22 @@ static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,
}
/*
** Compare two strings 'ls' x 'rs', returning an integer smaller-equal-
** -larger than zero if 'ls' is smaller-equal-larger than 'rs'.
** Stripped down version for NodeMCU without locales support
*/
static int l_strcmp (const TString *ls, const TString *rs) {
const char *l = getstr(ls);
size_t ll = ls->tsv.len;
const char *r = getstr(rs);
size_t lr = rs->tsv.len;
for (;;) {
int temp = strcoll(l, r);
if (temp != 0) return temp;
else { /* strings are equal up to a `\0' */
size_t len = strlen(l); /* index of first `\0' in both strings */
if (len == lr) /* r is finished? */
return (len == ll) ? 0 : 1;
else if (len == ll) /* l is finished? */
return -1; /* l is smaller than r (because r is not finished) */
/* both strings longer than `len'; go on comparing (after the `\0') */
len++;
l += len; ll -= len; r += len; lr -= len;
}
if (l == r) {
return 0;
} else {
size_t ll = ls->tsv.len;
size_t lr = rs->tsv.len;
size_t lm = ll<lr ? ll : lr;
int s = memcmp(l, r, lm);
return s ? s : (lr == lm ? (ll == lm ? 0 : 1) : -1);
}
}
@@ -283,11 +262,8 @@ int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2) {
case LUA_TNIL: return 1;
case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));
case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
case LUA_TLIGHTUSERDATA:
case LUA_TROTABLE:
case LUA_TLIGHTFUNCTION:
return pvalue(t1) == pvalue(t2);
case LUA_TLCF: return lcfvalue(t1) == lcfvalue(t2);
case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
case LUA_TLCF: return fvalue(t1) == fvalue(t2);
case LUA_TSHRSTR: return eqshrstr(rawtsvalue(t1), rawtsvalue(t2));
case LUA_TLNGSTR: return luaS_eqlngstr(rawtsvalue(t1), rawtsvalue(t2));
case LUA_TUSERDATA: {
@@ -296,7 +272,8 @@ int luaV_equalobj_ (lua_State *L, const TValue *t1, const TValue *t2) {
tm = get_equalTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable, TM_EQ);
break; /* will try TM */
}
case LUA_TTABLE: {
case LUA_TTBLRAM:
case LUA_TTBLROF: {
if (hvalue(t1) == hvalue(t2)) return 1;
else if (L == NULL) return 0;
tm = get_equalTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);
@@ -620,21 +597,11 @@ void luaV_execute (lua_State *L) {
case OP_GETTABUP:
{
int b = GETARG_B(i);
if (ttisstring(RKC(i))) {
char keyname[LUA_MAX_ROTABLE_NAME + 1];
lua_getcstr(keyname, rawtsvalue(RKC(i)), LUA_MAX_ROTABLE_NAME);
TRACE_LUA_INTERNALS("luaV_execute(OP_GETTABUP, %s)", keyname);
if (luaR_findglobal(L, keyname, ra)) {
break;
}
}
TRACE_LUA_INTERNALS("luaV_execute(OP_GETTABUP, %d) OLD WAY", b);
Protect(luaV_gettable(L, cl->upvals[b]->v, RKC(i), ra));
}
break;
case OP_GETTABLE:
/* First try to look for a rotable with this name */
Protect(luaV_gettable(L, RB(i), RKC(i), ra));
break;