Expose lush global as a standard library (issue #26)
Register luaopen_lush() in stdlibs so the lush table is available as a global. Users can now extend the shell by adding functions to lush.builtins. The OP_LUSH VM access via integer keys is preserved.
This commit is contained in:
31
lcmd.c
31
lcmd.c
@@ -1199,3 +1199,34 @@ int lushCmd_setenv (lua_State *L) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* ===== lush standard library ===== */
|
||||
|
||||
static const luaL_Reg lushlib[] = {
|
||||
{"command", lushCmd_command},
|
||||
{"interactive", lushCmd_interactive},
|
||||
{"getenv", lushCmd_getenv},
|
||||
{"setenv", lushCmd_setenv},
|
||||
{"subcmd", lushCmd_subcmd},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
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);
|
||||
/* store in registry for OP_LUSH access */
|
||||
lua_pushvalue(L, -1);
|
||||
lua_rawseti(L, LUA_REGISTRYINDEX, LUA_RIDX_LUSH);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user