From cca6749d4d88e3ce5c0b135e56a5a076e43c28b1 Mon Sep 17 00:00:00 2001 From: Cormac Shannon <> Date: Sun, 22 Mar 2026 18:58:59 +0000 Subject: [PATCH] =?UTF-8?q?Rename=20lush=20Lua=20API:=20command=E2=86=92ca?= =?UTF-8?q?pture,=20subcmd=E2=86=92run,=20getenv=E2=86=92envget,=20setenv?= =?UTF-8?q?=E2=86=92envset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lua-facing names only; C internals unchanged. lush.capture(str) — return {code, stdout, stderr} table lush.run(str) — return stripped stdout string lush.interactive(str) — run with TTY, set _, return result lush.envget(name) — get environment variable lush.envset(name,val) — set environment variable --- lcmd.c | 16 ++++++------- testes/lush/lushlib.lua | 50 +++++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/lcmd.c b/lcmd.c index 83cd0fc4..874bb516 100644 --- a/lcmd.c +++ b/lcmd.c @@ -1270,11 +1270,11 @@ int lushCmd_setenv (lua_State *L) { TString *lushname[LUSH_OP_COUNT]; static const luaL_Reg lushlib[] = { - {"command", lushCmd_command}, + {"capture", lushCmd_command}, {"interactive", lushCmd_interactive}, - {"getenv", lushCmd_getenv}, - {"setenv", lushCmd_setenv}, - {"subcmd", lushCmd_subcmd}, + {"run", lushCmd_subcmd}, + {"envget", lushCmd_getenv}, + {"envset", lushCmd_setenv}, {NULL, NULL} }; @@ -1287,11 +1287,11 @@ LUAMOD_API int luaopen_lush (lua_State *L) { lua_createtable(L, 0, 4); lua_setfield(L, -2, "commands"); /* intern function name strings for OP_LUSH VM access */ - lushname[LUSH_OP_COMMAND] = luaS_new(L, "command"); + lushname[LUSH_OP_COMMAND] = luaS_new(L, "capture"); 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"); + lushname[LUSH_OP_GETENV] = luaS_new(L, "envget"); + lushname[LUSH_OP_SETENV] = luaS_new(L, "envset"); + lushname[LUSH_OP_SUBCMD] = luaS_new(L, "run"); /* store in registry for OP_LUSH access */ lua_pushvalue(L, -1); lua_rawseti(L, LUA_REGISTRYINDEX, LUA_RIDX_LUSH); diff --git a/testes/lush/lushlib.lua b/testes/lush/lushlib.lua index 5550e56c..383624d8 100644 --- a/testes/lush/lushlib.lua +++ b/testes/lush/lushlib.lua @@ -13,30 +13,30 @@ end -- === named functions are accessible === do - assert(type(lush.command) == "function", "lush.command missing") + assert(type(lush.capture) == "function", "lush.capture missing") assert(type(lush.interactive) == "function", "lush.interactive missing") - assert(type(lush.getenv) == "function", "lush.getenv missing") - assert(type(lush.setenv) == "function", "lush.setenv missing") - assert(type(lush.subcmd) == "function", "lush.subcmd missing") + assert(type(lush.run) == "function", "lush.run missing") + assert(type(lush.envget) == "function", "lush.envget missing") + assert(type(lush.envset) == "function", "lush.envset missing") end --- === lush.command works like backtick === +-- === lush.capture works like backtick === do - local r = lush.command("echo hello") - assert(r.code == 0, "lush.command failed") + local r = lush.capture("echo hello") + assert(r.code == 0, "lush.capture failed") assert(r.stdout == "hello\n", "expected 'hello\\n', got: " .. r.stdout) end --- === lush.getenv / lush.setenv === +-- === lush.envget / lush.envset === do - lush.setenv("_LUSH_TEST_VAR", "42") - assert(lush.getenv("_LUSH_TEST_VAR") == "42") - lush.setenv("_LUSH_TEST_VAR", nil) - assert(lush.getenv("_LUSH_TEST_VAR") == nil) + lush.envset("_LUSH_TEST_VAR", "42") + assert(lush.envget("_LUSH_TEST_VAR") == "42") + lush.envset("_LUSH_TEST_VAR", nil) + assert(lush.envget("_LUSH_TEST_VAR") == nil) end @@ -72,7 +72,7 @@ do end --- === user-defined builtin via lush.command === +-- === user-defined builtin via lush.capture === do lush.builtins.myecho = function(cmd, ...) @@ -84,7 +84,7 @@ do return t end - local r = lush.command("myecho foo bar") + local r = lush.capture("myecho foo bar") assert(r.code == 0) assert(r.stdout == "foo bar\n", "expected 'foo bar\\n', got: " .. r.stdout) @@ -162,11 +162,11 @@ do end --- === alias works with lush.command === +-- === alias works with lush.capture === do lush.aliases.myecho = "echo via-command" - local r = lush.command("myecho") + local r = lush.capture("myecho") assert(r.code == 0) assert(r.stdout == "via-command\n", "expected 'via-command\\n', got: " .. r.stdout) @@ -182,10 +182,10 @@ do assert(r.stdout == "works\n") -- $VAR expansion - lush.setenv("_LUSH_LIB_TEST", "yes") + lush.envset("_LUSH_LIB_TEST", "yes") local val = $_LUSH_LIB_TEST assert(val == "yes", "expected 'yes', got: " .. tostring(val)) - lush.setenv("_LUSH_LIB_TEST", nil) + lush.envset("_LUSH_LIB_TEST", nil) end @@ -247,30 +247,32 @@ do assert(r.code == 127, "removed command should not be found") end --- user command via lush.command() +-- user command via lush.capture() do lush.commands.apicmd = function(name, ...) print("api " .. table.concat({...}, " ")) end - local r = lush.command("apicmd x y") + local r = lush.capture("apicmd x y") assert(r.stdout == "api x y\n", "expected 'api x y\\n', got: " .. r.stdout) lush.commands.apicmd = nil end --- === lush.subcmd() direct call === +-- === lush.run() direct call === do - local result = lush.subcmd("echo hello") - assert(result == "hello", "subcmd should return stdout without trailing newline, got: " .. tostring(result)) + local result = lush.run("echo hello") + assert(result == "hello", "run should return stdout without trailing newline, got: " .. tostring(result)) end -- === lush.interactive() direct call === do - lush.interactive("true") + local r = lush.interactive("true") + assert(type(r) == "table") + assert(r.code == 0) assert(type(_) == "table") assert(_.code == 0) end