Remove integer keys from lush table, use string lookups (issue #29)
VM now resolves lush functions via luaH_getshortstr through interned TString pointers, so wrapping lush.command = my_wrapper is transparently picked up. The lush table no longer has integer-keyed duplicates.
This commit is contained in:
20
lcmd.c
20
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);
|
||||
|
||||
Reference in New Issue
Block a user