diff --git a/issues/29-lush-table-cleanup.md b/issues/29-lush-table-cleanup.md index 1bef43e0..9151ff2e 100644 --- a/issues/29-lush-table-cleanup.md +++ b/issues/29-lush-table-cleanup.md @@ -1,6 +1,6 @@ # Issue 29: Clean Up Integer Keys in lush Global Table -**Status:** open +**Status:** done ## Problem diff --git a/lcmd.c b/lcmd.c index f486ab07..733bdbe9 100644 --- a/lcmd.c +++ b/lcmd.c @@ -22,6 +22,7 @@ #include "lauxlib.h" #include "lcmd.h" #include "lbuiltin.h" +#include "lstring.h" /* ===== argv parser ===== */ @@ -1203,6 +1204,8 @@ int lushCmd_setenv (lua_State *L) { /* ===== lush standard library ===== */ +TString *lushname[LUSH_OP_COUNT]; + static const luaL_Reg lushlib[] = { {"command", lushCmd_command}, {"interactive", lushCmd_interactive}, @@ -1214,17 +1217,12 @@ static const luaL_Reg lushlib[] = { LUAMOD_API int luaopen_lush (lua_State *L) { luaL_newlib(L, lushlib); - /* also store integer-keyed entries for OP_LUSH VM access */ - lua_pushcfunction(L, lushCmd_command); - lua_rawseti(L, -2, LUSH_OP_COMMAND + 1); - lua_pushcfunction(L, lushCmd_interactive); - lua_rawseti(L, -2, LUSH_OP_INTERACTIVE + 1); - lua_pushcfunction(L, lushCmd_getenv); - lua_rawseti(L, -2, LUSH_OP_GETENV + 1); - lua_pushcfunction(L, lushCmd_setenv); - lua_rawseti(L, -2, LUSH_OP_SETENV + 1); - lua_pushcfunction(L, lushCmd_subcmd); - lua_rawseti(L, -2, LUSH_OP_SUBCMD + 1); + /* intern function name strings for OP_LUSH VM access */ + lushname[LUSH_OP_COMMAND] = luaS_new(L, "command"); + lushname[LUSH_OP_INTERACTIVE] = luaS_new(L, "interactive"); + lushname[LUSH_OP_GETENV] = luaS_new(L, "getenv"); + lushname[LUSH_OP_SETENV] = luaS_new(L, "setenv"); + lushname[LUSH_OP_SUBCMD] = luaS_new(L, "subcmd"); /* store in registry for OP_LUSH access */ lua_pushvalue(L, -1); lua_rawseti(L, LUA_REGISTRYINDEX, LUA_RIDX_LUSH); diff --git a/lcmd.h b/lcmd.h index 19d82775..951c1a19 100644 --- a/lcmd.h +++ b/lcmd.h @@ -8,6 +8,7 @@ #define lcmd_h #include "lua.h" +#include "lobject.h" /* OP_LUSH sub-operation indices (B operand selects which function) */ #define LUSH_OP_COMMAND 0 @@ -23,6 +24,8 @@ int lushCmd_getenv (lua_State *L); int lushCmd_setenv (lua_State *L); int lushCmd_subcmd (lua_State *L); +extern TString *lushname[]; + LUAMOD_API int luaopen_lush (lua_State *L); #endif diff --git a/lvm.c b/lvm.c index 70747503..ee31a957 100644 --- a/lvm.c +++ b/lvm.c @@ -30,6 +30,7 @@ #include "ltable.h" #include "ltm.h" #include "lvm.h" +#include "lcmd.h" /* @@ -1947,7 +1948,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { lu_byte tag = luaH_getint(regt, LUA_RIDX_LUSH, &lushtv); if (novariant(tag) == LUA_TTABLE) { TValue func; - luaH_getint(hvalue(&lushtv), idx + 1, &func); /* 1-based */ + luaH_getshortstr(hvalue(&lushtv), lushname[idx], &func); setobj2s(L, ra, &func); } vmbreak;